Picaxe LED night light
This is a little night-light that comes on when it gets dark, to illuminate dark rooms or hallways. I’m sure you can buy these cheaply ready made but it’s more fun to make your own, and this way it can be customised exactly how you want it.
The unit is very efficient – I use 4x AA NiMH batteries which last over a month in typical use. The circuit uses a high-brightness LED, but driven at a lower current. The firmware makes use of the Picaxe’s “SLEEP” command, so that the CPU is only running for a fraction of the total uptime.
I don’t want to put a dollar figure on the parts, because each user will have different sources for their parts (I’ll provide some links later). By fabricating my own circuit board I built the whole thing for under ten US dollars.
Step 1: Design
It’s a pretty simple circuit, based on an 8 pin Picaxe 08M. This was what I had on hand, you could also use the newer 08M2.
It uses an LDR and a 1M2 resistor to form a voltage divider on pin 1 of the Picaxe. There’s an orange LED connected to pin 4 of the Picaxe via a 1k2 resistor. This limits the current through the LED to about 5mA. This reduces the LED brightness, but it’s still sufficient to provide a dim light if your eyes are adjusted to the darkness (I use it in my hallway so I can avoid tripping over at night, but not wake the household by turning on the main light)
Pulldown resistors are used on the unused Picaxe pins – it’s good practice not to allow I/O pins on a microcontroller to “float” and I think it also reduces current consumption very slightly. I used 110k resistors for the pulldowns, because I had a lot on hand. You could use anything around 100k.
The LED is driven straight from the Picaxe so it’s important to limit the total current from this pin to under 20mA.
The cicruit draws less than 1mA when the LED is off, and about 5.5mA when the LED is on. I run mine from 4 AA NiMH rechargeable batteries (which supply about 5V) which last about a month on average, before I need to recharge them.
The software spends most of its time in “sleep” mode, and only wakes up every 2.3s to check the state of the LDR. Before reading the LDR, it turns off the LED so that its light output doesn’t affect the reading. The reading happens so quickly the LED can hardly be seen to flicker when it is very briefly turned off. In order to avoid the LED turning on and off repeatedly around dusk, some hysteresis is built into the code. This is done very roughly by calculating an average value for the ambient light, so that changes in the ambient light take a while to propagate in the code. The raw ADC reading is also divided by 10 to minimise noise.
The code I have attached works on the Picaxe 08M. You should be able to convert it to run on the 08M2 by using the wizard built-in to the Picaxe software
LDR: Simliar to Philips ORP12. I used the RD3480 from www.jaycar.com.au
LED: high-brightness 5mm amber LED. I used the ZD0295 from www.jaycar.com.au
PCB: A custom board I designed in Eagle and etched myself. All the design files are attached to this Instructable
Case: I designed the above PCB to mount in a HB6005 clear plastic case from www.jaycar.com.au
Capacitors: 1x 100uF 16v; 1x 100nF, 50v.
Resistors: 1x 1M2; 2x 110k; 1x 22k; 1x 10k; 1x 1k2. all are 1/4w meetal film types (but it probably doesn’t matter)
Miscellaneous: Power socket, battery holder (the circuit requires 5V – I used 4x 1.2V AA rechargeable batteries), programming header, about 15cm of insulated hookup wire
If there’s a lot of interest for this circuit, I’ll get a batch of PCBs and make a kit available.
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days
Current Project / Post can also be found using:
- 16f84a led projects