Picaxe LED night light

Summary of Picaxe LED night light


This project describes a low-power DIY LED night-light using a Picaxe 08M microcontroller, an LDR for ambient light sensing, and a dim high-brightness amber LED. The design emphasizes long battery life (4×AA NiMH), use of sleep mode and hysteresis in firmware to avoid flicker at dusk, and a simple PCB housed in a clear plastic case. All design files and parts lists are provided for fabrication and programming.

Parts used in the Night-Light:

  • Picaxe 08M microcontroller (CPU)
  • LDR (similar to Philips ORP12; RD3480 referenced)
  • High-brightness 5mm amber LED (ZD0295 referenced)
  • PCB (custom board designed in Eagle)
  • HB6005 clear plastic case
  • 100uF 16V electrolytic capacitor
  • 100nF 50V ceramic capacitor
  • 1.2M resistor (1M2) for voltage divider
  • 110k resistors (two) for pulldowns
  • 22k resistor
  • 10k resistor
  • 1.2k resistor (1k2) current-limiting resistor for LED
  • Power socket
  • Battery holder for 4×AA cells (4×1.2V NiMH)
  • Programming header for Picaxe
  • Approximately 15 cm insulated hookup wire

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.

Power efficiency

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.

Picaxe LED night light
Cost

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

Circuit
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.

Software
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

Picaxe LED night light
Hardware
CPU: Picaxe 08M.
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 wireIf there’s a lot of interest for this circuit, I’ll get a batch of PCBs and make a kit available.

Downloads

Below are the Eagle files for the schematic and PCB. There’s also a full-size PDF of the PCB tracks if you’re etching your own PCB.
For more detail: Picaxe LED night light

Quick Solutions to Questions related to Night-Light:

  • What microcontroller is used in the night-light?
    The project uses a Picaxe 08M microcontroller.
  • How is ambient light detected?
    An LDR in a voltage divider (with a 1M2 resistor) is connected to pin 1 of the Picaxe to measure ambient light.
  • How is the LED current limited?
    The amber LED is driven from Picaxe pin 4 through a 1k2 resistor to limit current to about 5mA.
  • How does the firmware conserve power?
    The firmware uses the Picaxe SLEEP command and wakes every 2.3 seconds to check the LDR, keeping the CPU off most of the time.
  • What batteries are used and how long do they last?
    The circuit runs from 4×AA NiMH rechargeable batteries (~5V) which last over a month in typical use.
  • How does the design avoid flicker around dusk?
    Hysteresis is implemented by averaging ambient light readings and dividing the ADC reading by 10 to reduce noise, so changes propagate slowly and avoid rapid on/off switching.
  • What are the typical current draws of the circuit?
    The circuit draws less than 1mA with the LED off and about 5.5mA with the LED on.
  • Are unused microcontroller pins handled specially?
    Yes, unused Picaxe pins have pulldown resistors (110k) to prevent floating and slightly reduce current consumption.
  • Can the code run on newer Picaxe variants?
    The provided code is for Picaxe 08M but can be converted to 08M2 using the Picaxe software wizard.
  • Are PCB design files available?
    Yes, Eagle schematic and PCB files plus a full-size PDF of PCB tracks are provided for etching your own PCB.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter