Auto-Shutoff Circuit

Schematic of Auto Off circuitI 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.

Auto Shutoff circuit built on a breadboard firstI 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.

Completed circuit built on a chunk of perf boardI 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.

Circuit built dead-bug styleCircuit built dead-bug style

Circuit built dead-bug style

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!

Downloads

Download Binary (HEX)

Download Source (C)

16 Responses to Auto-Shutoff Circuit

  1. Sheldon says:

    Is there anyway you could send the source could for Arduino Uno? Thanks

    • Kyle says:

      Hello Sheldon, unfortunately I have never worked with an Arduino so I don’t have any code available for that. The code is very simple. On power-up, it makes the pin an output and sets it low. It then runs a timer until the counter reaches zero (in my case its about 15 minutes) then it makes the output pin an input (hi-Z). Im not sure if this would work with an Arduino since it may try to pull more power than is initially available on startup. You also have to factor in the bootloader which takes time before it gives control to the main program. Thank you for your interest though.

  2. James Simpson says:

    Not ever thought of making something like this for household electronics? TV, Lights, say when your not in the room, these devices are powered down, and when you get back into the room, they power on.

    • Kyle says:

      James, this circuit could be used for a lot of “white goods,” meaning appliances and household items. The only downfall is that it wont be able to automatically turn back on without physically touching the switch. Good idea thought. I think I would probably use MOSFETs instead of bipolar transistors in a commercial device (less power loss = more efficiency). I just didn’t have any MOSFETs available at the time.

  3. Ivo says:

    Hi Kyle, This is exactly what I’ve been looking for as my wife keeps leaving the dome light in the car on. However i dont have the means to program the IC, could you maybe show me how to replace it with a 555 timer?

    • Kyle says:

      There isn’t really any easy way to substitute the IC for a 555 timer. If you want to only remain on for a few minutes, then this can be done. Unfortunately, the RC value required to obtain the 15 minute timeout wouldn’t be feasible in a 555 (leakage current would overwhelm the charging current). You can find really cheap Atmel programmers online for a few bucks shipped.

  4. John says:

    Hi I am wondering if i can set this up to turn power off in.3 to .5 sec
    I am Working on a project where i need this type of timer but am confused?

    Thanks in advance John

    • Kyle says:

      You should be able to change the shutoff time to what ever you need (.3 to .5 seconds) in the source file. First, you’ll have to change the prescaler of the timer to 1 (no prescaler) then change the MAXCOUNT define statement to 150 for 0.3 second delay or 251 for 0.5 second delay. You can find the MAXCOUNT value by solving: (delay time) / (255 / 128000). I hope that helps some.

  5. Radovan says:

    Hallo.

    The input voltage must be up to 5V ? I have 9V multimeter i have got to use?
    Sorry my english.

  6. Jeremy says:

    I need one of these…where can I buy it?

    • Kyle says:

      I’m not selling them but they are easy to make. Thanks for the interest though. It may be something I’ll consider later on down the road.

  7. gada says:

    Hi,HYLE,thanks,it’s a amazing little board.I bought a attiny programmer meant to program the attiny chips.the programmer i got is designed to piggyback on the arduino board.any common arduino INO files uploaded should go.but i have noticed your HEX and C files which i think might be programmed through avr mkii.Could you detail how you programmed the HEX files?

    • Kyle says:

      I use an AVR dragon for all of my code burning. I like it because it has an on-board ZIF socket as well as headers for ICP, JTAG, and HVSP. The HEX file is a standard format for burning to chips. Im not really an arduino user so I can’t comment on how to do it with the arduino based programmer. sorry.

  8. Thor Elvin Valø says:

    I dont understand the connections on the schematic.

    1. Is the MCU in paralell with the load or in series?
    2. I guess the V+ and V- goes straight to the battery, how does OUT connect?

    Thanks, Thor

  9. Drew says:

    Great little circuit. If I’m using this to control the dome light in a car I just need to make sure the amps stay below about 300mA, right? How could I control the voltage since the dome light would run on 12V and the Attiny uses much less.
    Cheers,
    Drew

  10. Himanshu says:

    sir can i make a monostable multivibrator using 555 timer with a SPST switch rather then push switch i want a same device for my circuit but don’t have the means to program the IC, my requirement is 1 to 2 min output

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>