Introduction: Auto-Off Nightlight

Do your kids like sleepling with a flashlight for protection against monsters? Do they forget to turn to off before falling asleep? if you answered yes to both questions, you might need your very own battery saving "Auto-Off Nightlight"

Step 1: How It Works

This Instructable is based around the ATTINY2313 microcontroller and a circuit that I designed. A single button turns the light on and starts a timing loop inside the micro. After 6 minutes, the light turns off and the micro enters a super low-power sleep mode. Pressing the button on the front wakes the micro up and starts the program all over again.

My requirements for the nightlight were the ability to go into a low-power standby mode, single button power on, a bright light with a constant brightness, and operated from AA batteries.

Want to build this but don't want to use a microcontroller? Then you might want to check out my Auto-Off Flashlight Instructable:

So lets see how it all goes together.

Step 2: Parts Needed

4.5v LED torch

ATTINY2313 micro

1k resistor

.1uF capacitor

BUZ101A mosfet

4.5v AA battery holder

normally open button

small piece of perf board

project box - I used the Hammond 1591ctcu crystal clear case

Step 3: Prepare the Torch

The LED torches are getting cheaper and cheaper. I paid $1 for the above torch and needed to take a hack saw to the tube so I could solder wires to to the LED array. I noticed that the LEDs are soldered on with a very poor quality solder, so you might need to touch them with a soldering iron to make sure that they are connected to the circuit board. The center of the circuit board is the anode, or positive lead and the edge contains the cathodes or negative leads.

Step 4: Start Building the Night Light

Once you have everything ready, start putting your circuit together. Please look at the schematic for the exact details. We will only be using 4 pins of the micro, a smaller chip could be used but I have a development station for the 20 pin ATTINY2313.

You want to install a .1uF cap between power and ground. I like to mount the cap on the rear of the circuit board to keep the leads as short as possible. I placed a 1K pull-up resistor on the reset line just to make sure things go well.

Pressing the button pulls the reset line low and wakes the micro up from sleep.

Power is always applied to pin 20 of the micro, VCC, and to the top of the LED array.

When the micro is running, pin 13 is set high which causes the mosfet to conduct and pull in a ground for the LED array. After the time set by your program, the micro places the mosfet gate low to turn out the light then it goes to sleep.

Step 5: Program the Micro

I used AVRdude as my compiler. The micro first sets up PORTB as outpUTS, then sets pin 13 high then counts for 6 minutes. The mosfet is turned on which then turns the LED array on. After 6 minutes it sets pin 13 low, the light goes out, and the micro is placed in low-power sleep mode. Pulling pin 1, the reset line, low wakes the micro out of sleep mode and starts the program all over again.

Its that easy! Be the first to post a picture of the auto-off nightlight that you made and I'll send you a pro membership!

My simple program for the ATTINY2313 Auto-off Nightlight is as follows:

//attiny2313pu processor using avrdude

#include (avr/io.h)
#include (avr/delay.h) #include (avr/sleep.h)

int main(void){


DDRB=0xff; // PORTB = all output

PORTB=0x1e; //set bits high

int i = 3500; //number of loop runs

while (i!=0)

{ _delay_ms(100); //delay

i--; // count down



TCCR0B &= 0b11111000; //stop timer 0

TCCR0A &= 0b00111111; //00c0ca set

MCuCR != 0b00100000; // sei=0

MCUCR != 0b00010000; //power down sleep

_delay_ms(10);//small delay

PORTB=0x00; //PORTB all low

sleep_cpu(); //go to sleep



Chitlange Sahas (author)2014-06-04



Awesome job! This is a great idea!