Hi there! I'm trying to do something possibly a bit unusual.
I have a program running on an attiny85 and there's a sensor that I want to trigger that*.
my reasoning is that the attiny85 is always connected to 5V and when 2n2222 base is set to high, then it gets "grounded"
the problem is that attiny85 is ON all the time (even if the 2n2222 base is disconnected or grounded)!
attiny85 is connected also to a couple of leds and a beeper (all output pins), so perhaps this is creating a path to ground?
I've read it's safer to have a 10k resistor in series with 2n2222 base and I tried doing that, but this didn't help (keep in mind that the circuit is being kept on even if 2n2222 base is disconnected, so that's not the issue).
here's a simulation that seems to do what I want (assume attiny85 is the resistor+LED on the right) - if I disconnect (or ground) the base the LED powers off:
* I'm not connecting the sensor directly to attiny85 because this sensor is extremely low-power and runs on batteries, so I'd prefer to keep it as-is and just use it to turn the attiny85 on for a few seconds when it's triggered
That's due to phantom power through I/O pins' protection diodes. Insert a resistor into each line that can power the controller.
A low side switch is not recommended, use a high side switch in the 5V line to turn a controller off.
Even better: put the controller asleep instead of cutting the power. A well connected ATtiny draws a few µA in deep sleep, less than your batteries are draining themselves.
Insert a resistor into each line that can power the controller.
The 2 LEDs have standard 330 resistors on the lines; the beeper doesn't (I believe it's equivalent to 8 ohms or so). I'll try adding a 220 ohms and report back
A low side switch is not recommended, use a high side switch in the 5V line to turn a controller off.
I initially tried that, but it didn't work. I suspect it's because the voltage of the sensor output is low and it doesn't trigger the transistor when "switching" 5V (but does for GND). Does that make sense? IIRC how transistors work, I believe the needs to be a certain voltage difference between base and the collector.
A well connected ATtiny draws a few µA in deep sleep
Yeah, I also considered this, but since I'm using a digispark board that would mean destroying the power led (it's always on), the voltage regulator and connecting the power to VIN. I tried to be lazy
ha, this almost worked!
Indeed the attiny85 now powers off, but with a caveat; when it shuts down, the LED connected to pin 1 turns on!
This LED is connected as: GND - 330 resistor - LED - attiny85 PIN1
when the attiny85 is powered on, this LED blinks as expected.
when attiny85 is powered off, the LED magically gets on (doesn't seem to be at full power)
so there seems to be some current flowing through attiny85 pin1 when it's powered off (but not through attiny85 pin0 where another LED is connected)
any clues what I can do about that? My only idea is using a 2-transistors circuit (instead of powering attiny85 from this transistor, I'd trigger a second transistor that would then power attiny85)