I came up with this circuit after searching for something similar and coming up empty. Basically, I have a lot of battery operated devices with power switches, but no auto-shutoff. Yes, there are many circuits out there that provide a means of automatically turning off a device, but they have one downfall – they require a momentary switch. Almost everything I have that I needed an auto-off for has a SPST switch and I didn’t want to rip open the case to modify it for a momentary switch. Normally, this would be a simple task for a microcontroller to monitor the switch and turn the circuit on or off accordingly. This would work, but i wanted a circuit that would completely cut the power, meaning not even the microcontroller is powered when off.
I tested many ideas before finally settling on this one. At the heart of the circuit is a timer, in this case I’m using an AVR Tiny to trigger a port pin when powered on and turning it off after the time has elapsed. The port pin is fed into the base of a PNP transistor. The collector of the PNP is then fed into the base of a NPN. The emitter of the NPN is tied to the switch and thus the negative terminal of the battery. The collector goes to the ground of the timer circuit (AVR Tiny). This collector also feeds the new switched power to the original circuit – say a light. Finally, the emitter of the PNP is tied to the positive terminal of the battery (along with the timer and original circuit) through a small 1K resistor. The resistor limits the current on the two transistors, yet allows the NPN to function in the non-linear (switching) region. To start the circuit when the switch is turned on, a small 1nF capacitor is connected between the base of the PNP transistor and the emitter of the NPN. A very small 15pF capacitor is connected between the base and emitter of the PNP to allow the circuit to restart quickly when power-cycled.
I built this using parts on hand over the course of a weekend and as such, it may not be the best approach but it works well. The voltage drop introduced by the emitter-collector junction of the NPN is roughly 200mV, which shouldn’t affect the original circuit, unless it is an extremely low impedance load. Future improvements may include using MOSFETs instead of bi-polar transistors.
I started with a breadboard and after verifying the circuit works, I built it on a piece of perf-board I had. This is when I ran into troubles with it not restarting after cycling the power (switching it off and on). Many hours later (the next day actually) I realized I needed the small capacitor between the emitter and base of the PNP, which was missing on the breadboard. The breadboard itself has a pretty high capacitance between rows (several picofarads) which was introduced unknowingly. I built several other circuits ‘deadbug’ style and they all work just as well (with this added capacitor).
The microcontroller I used was the AVR tiny85 because I have some many of them on hand. In reality, any microcontroller can be used so long as it has a few bytes of code space (maybe the tiny5). The code is very simple: enable port pinX as output low, when timer is up, make port pin input (HiZ). I’m using interrupts, sleep modes, and the watchdog clock source to keep power usage minimal. Even with it written in C, the code size is only 200 bytes, which can be substantially reduced further with assembly.
Feel free to use this as you please, just be sure to give reference to me. The source files are below for the AVR. If you like it or find it useful, then let me know!