enter image description here Updated Schematic picture. Some components (power supply, other things connected to the MOSFET) are omitted. The ICSP header was kept since I think it may be interfering somehow.

I have an ATTiny84 whose pins are connected to a photoresistor and resistor (480 ohm) as pictured above. However, really the intention of the photoresistor aspect is to mimic the circuit pictured below, where the green represents the sensor pin which is read using DigitalRead. When I power the circuit in such a configuration that only the sensor pin is tied to the MCU, then it works exactly as intended. If, leaving the circuit powered, I connect the wire that goes to ground on the below circuit to one that is tied (by writing the below code in the setup method) to ground, then it works.

pinMode (5, OUTPUT);
digitalWrite(5, LOW);

The same is true if I just switch the other pin (which is tied to HIGH), or even both at the same time. But, if I turn off then re-power the circuit in the exact same configuration, then it does not work as intended. The different between the pin set to HIGH and the one set to LOW and 5 and 0 v, respectively, is at most ~1v in both cases. Is there a fix that will ensure it works on booting? Why is this happening?

enter image description here

  • \$\begingroup\$ Corrected and simplified schematic. \$\endgroup\$
    – Lorenzo
    Commented Jun 15, 2022 at 20:11
  • \$\begingroup\$ What does "assembled live" mean? Is "GND" in your schematic labeling the net tied to pin 4 (PB3) or is it labeling the GND symbol that's rotated 90° clockwise? The reset pin (pin 4, PB3) should be tied high through a pull-up resistor to keep the MCU from resetting randomly. \$\endgroup\$
    – JYelton
    Commented Jun 15, 2022 at 20:34
  • \$\begingroup\$ Assembled live means that I plug it in with the wires for the photoresistor going straight to ground and to +5v, respectively. If I move those wires to be connected to pins on the mcu that are set LOW and HIGH, respectively, then it works. If I turn power of and then on in that same setup it does not work. GND is just offset, it goes to GND, and PB3 is unconnected to anything but the MOSI interface, and that part of the setup hasn't caused any problems yet. Thank you for your response. \$\endgroup\$
    – Lorenzo
    Commented Jun 15, 2022 at 20:41
  • 1
    \$\begingroup\$ I have read this 3 times and still don't understand what you mean by "it works" or "does not work after booting". Can you provide the source code? \$\endgroup\$
    – Jens
    Commented Jun 15, 2022 at 21:17
  • \$\begingroup\$ By it works I mean that it does the intended function (reads the photoresistor and depending on that gives varying signals to the MOSFET). I mean to say that if I plug it in when those two wires (the ones connected to the photoresistor in the bottom image) are plugged into GND and +5v,it works, and if I leave it plugged in and move those wires to connect to pins tied to GND and +5v respectively, it still works. If I, leaving that setup in place, unplug it and then replug it in, it does not work. docs.google.com/document/d/… \$\endgroup\$
    – Lorenzo
    Commented Jun 15, 2022 at 21:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.