For this project I wanted to design a night light for use in the nursery with the following specifications:
– Diffused lighting source
– Multiple lighting modes – warm glow and bright modes
– Built in timer to turn off or dim after a set period of time
– Externally Powered from 5V supply
– Remote control functionality
A suitable embodiment for the nightlight as found on eBay and Amazon. This was a PIR light with a large diffuser which looked to be simple to disassemble and modify for my purposes:
The light was originally designed to be powered from 3x AAA cells and illuminated for around 30 seconds when movement was detected and initial testing revealed that the light provided adequate illumination of the room with the fitted diffuser. The light was disassembled to determine it’s suitability for fitting a custom PCB.
The schematic design for this nightlight is relatively trivial. Starting with the microcontroller, I selected a Microchip PIC24F32KA301, which had a suitable number of hardware PWM channels and some EEPROM built in for storing brightness settings.
A simple linear regulator provides power to the MCU from the 5V supply.
A white LED source was selected – a pair of Cree XLAMP MX-6 warm white LEDs were chosen to be the main light source for this nightlight and the driver was designed to provide a constant current of around 170mA to the LEDs at full duty cycle. The driver is expected to be connected to a PWM output from a microcontroller for brightness control.
A pair of red and amber LEDs are added to the design to allow a low level warm glow in the room when a main light source is not required. Kingbright KA-3529 LEDs are used for this purpose along with a similar LED driver.
I wanted the light to be simple to control remotely, so some infrared remote controllers were purchased from eBay.
These IR remotes use a 38kHz carrier frequency for modulation of the data stream. Following some initial investigations using the free IR receiver and an oscilloscope, I determined these remotes use the NEC protocol which has the following properies:
Carrier Frequency – 38kHz
Pulse Distance Modulation Protocol
– Logical 0 – 560µs 38kHz burst, 560µs break – 1.125ms total
– Logical 1 – 560µs 38kHz burst, 1.68ms break – 2.25ms total
Message starts with 9ms AGC burst followed by 4.5ms
Total bits transmitted = 32
Address and Command = 8 bits each
Address and Command are transmitted twice, the second transmission has all bits inverted for verification
Total transmission time always constant because every bit is transmitted with its inverted length.
To interface this with the microcontroller, a Vishay TSOP344 series IR receiver is used:
A few other expansion headers are provided on the PCB for future use, but the nightlight is designed to be controlled entirely from the IR remote control.
Version 2 of the PCB has now been completed and features the addition of green and blue LEDs to allow the full range of colours to be produced from the lamp:
The PIC24F32KA301 has only 3 PWM outputs on it, so using a combination of Timer 2, Timer 4 and Timer 5, an additional 2 PWM channels with 16-bit resolution at 244Hz can be created with minimal overhead (Interrupts only occur at 244Hz unlike a full software PWM loop).
Firmware will follow shortly once completed.