Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

Ultrasonic Night Light

A high brightness white LED night light, that is activated by tripping the beam of an ultrasonic sensor, with battery backup (only a single A4 battery required) based on a joule thief circuit.

Stumbling around in the dark one night getting out of bed lead to the idea of some sort of automatic night light. Optimally, I wanted some sort of sensor that would be tripped when I woke and or got out of bed, required minimal 'input' from me since still likely sleepy and did not require much modification to my bed.

This resulted in a design for a night light that is automatically triggered by breaking an ultrasonic beam, which turns off after a set time, powered by a single A4 battery, which makes the project compact and in expensive.

List of features:

  • The night light uses a high brightness white LED, that is triggered by tripping the ultrasonic beam.
  • 5V power is provided via a standard phone charger (mini-USB).
  • In event of mains power outage, the white LED is automatically powered-on via the joule-thief circuit using a single A4 battery.
  • A light sensor, a light dependent resistor, only enables LED power-on during night time, that is the preset darkness level.
  • A single toggle button enables user setting of LED on time and ultrasonic sensor sensitivity.

A joule thief circuit, which is a type of voltage booster, is the basis of the design which powers the white LED, as this has minimal, easily available cheap parts, and moreover allows the use of a single A4 1.5V battery, enabling the final design to be compact.

The design calls for the night light to be normally off and to be triggered when waking from bed in some manner for a set time. So the joule thief circuit needed to augmented with a timer and some sort of sensor.

While there are many potential options such as the ubiquitous 555 timer chip, a Digispark Attiny85 module only costs about $2 from ebay and provides onboard timers, analog to digital converter, PWM output etc with 6K of program memory in a 2cm square PCB ready for mounting. So the Digispark module would provide the timer functionality, and conveniently could then also digitally control the joule thief circuit for powering the LED via simple NPN transistor switch.

While the Digispark module could directly power the white LED, with a suitable transistor to switch the needed higher current, the joule thief circuit was still utilised, as this enabled the white LED to be battery powered, and in case of mains power outage, the joule thief battery powered part of the circuit would automatically take over. So, gives a nice back-up night light even in the event of power outage.

With the Digispark module using the HC-SR04 ultrasonic module is relatively trivial (see Attiny85/HC-SR04 project for more detail) and this gives a nice solution to automatically turning on the LED when getting out of bed, by just having to put your feet down when standing up. One downside of using the digispark module is that it requires 5V input. However, Digispark modules with mini-usb connectors, that accept standard phone chargers, are readily available, so 5V DC bedside power is not a problem and doesn't require extra components.


The circuit is based around the Digispark Attiny85 module firmware controlling the high power white LED via enabling/disabling the joule thief circuit.

During normal operation the Digispark Attiny85 module outputs a digital high via PB1 causing transistor Q2 to conduct. Thus providing a path to ground for the primary winding of the joule thief coil via resistor R7 rather than to the base of transistor Q1. Hence, the oscillation normally that would occur in transistor Q1 and the joule thief coil is inhibited. Therefore, the white LED is not illuminated. Details for how the joule thief circuit operates are available at wikipedia (1)

This also means if the Digispark Attiny85 module is powered down (or outage of the 'mains' 5V DC supply) the joule thief circuit will operating independantly and illuminate the white LED using the 1.5V battery (i.e., act as "backup" night light in event of power outage). Switch SW2 disconnects the battery to the joule thief circuit.

The Digispark Attiny85 module firmware continuously checks the HC-SR04 ultrasonic module for a return signal that is within the preset distance. See Attiny85/HC-SR04 project for more detail. If a return signal is found, pin PB1 is output digital low and hence the joule thief circuit oscillation is enabled and the white LED is illuminated. The firmware initiates a timer which will cut off the white LED after the preset time has expired.

Toggle button SW1 inconjunction with the state of the light dependant resistor (LDR) Z2 is used to accept user input to set the on-time duration of the white LED and the "sensitivity" of the ultrasonic sensor.

When the toggle button is depressed and the LDR is in the "light" (i.e., above the preset limit), a firmware timer is initiated and for each second the toggle button is held-on the on-time duration of the white LED is increased in steps of one minute, to a maximum of five minutes after which cycles back to one minute. The white LED is flashed rapidly the corresponding number of flashes to indicate to the user the currently selected on-time duration, which is selected by simply releasing the toggle button.

Simiarily, when the toggle button is depressed but the LDR is in the "dark" (i.e., blocked by a finger or similar) the distance within which the ultrasonic sensor will report a return signal is increased in steps of 25cm.

This function of the LDR inconjunction with the toggle button in providing user input is ancillary to the main purpose of the LDR (although was necessary due to the limited number of I/O pins available on the Digispark Attiny85 module). The main purpose of the LDR is to enable the Digispark Attiny85 module to assess light conditions and only enable the white LED if the ultrasonic sensor is tripped, and ambient conditions are 'dark' i.e., night-time. The 'darkness' is preset via resistor R6. R6 could be replaced by a potentiometer if it is desired to allow this to be altered by the user.

The choice of using the Digispark Attiny85 module to enable digital control of the joule thief and operation of the HC-SR04 ultrasonic sensor also means 5V DC power for the circuit is conveniently available from standard phone chargers via the micro-USB port.

Firmware

An advantage of using the Digispark Module is that the firmware can be written and uploaded using the Arduino IDE. The code is available  here,  and the following is a high-level overview:

Central to the firmware is the NewPing Arduino Library, this enables easy initialisation and reading the ultrasonic sensor.

The main loop consists of first checking the various inputs, that is, the state of the LDR and toggle switch and then reacting appropriately, depending if the LED is currently on or off.

If the LED is currently on, that is, the sensor was previously tripped a timer is checked to determine if the LED should remain illuminated or not.

If the LED is not illuminated, the ultrasonic sensor is checked, and if a signal within the set range is detected, the LED on status is changed, as long as the LDR is below the set limit, i.e., it is dark.

Finally, if the toggle button has been pressed, after some software debouncing, either the LED on time, if the LDR is in the dark, or the ultrasonic sensor range if the LDR is in the light, is set according to how long the user holds down the toggle switch.

And then the main loop repeats.


Note: Image loading can be slow depending on server load.

  • Ultrasonic Night Light SchematicUltrasonic Night Light Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    Ultrasonic Night Light Schematic

Note: Image loading can be slow depending on server load.

  • Veroboard LayoutVeroboard Layout

    Silver Membership registration gives access to full resolution diagrams.

    Veroboard Layout

See Schematic Section for component codes and parts list.



Qty Schematic Part-Reference Value Notes
Resistors
1R62K21/4W, 10% 
2R7,R81K1/4W, 10% 
Capacitors
1C30.1 uF25V electrolytic 
Integrated Circuits
1U2CD4060Digispark/Attiny85 datasheet
Transistors
1Q1D2012small signal NPN 
1Q2BC547small signal NPN 
Diodes
1D6LED1W white  
Miscellaeous
1Z1Joule Thief Coil 
1Z2Light Dependent Resistor 
1Z3HC-SR04Ultrasonic Sensor 
2SW1,SW2switchToggle, SPST
Description Downloads
Ultrasonic Night Light Bill of Materials Text File Download

The following YouTube video shows the construction and testing of the circuit and completed project.

This was the first project I have constructed using the joule thief circuit. Despite the myriad videos and pages on the web, and the relative simplicity of the joule thief, can still be a little tricky to get the circuit to operate initially. I was more interested in getting this night light finished rather than an 'exhaustive' examination of the joule thief circuit. So, once I had the circuit working with the component values given in the schematic, did not explore further at this stage.

I plan on a further seperate project to examine the joule thief circuit in more detail (to ascertain limitations, which components/values are crucial etc as I would like to understand/optimise this circuit for battery operation), so stand-by.

However, I found that the inductance of the coil to be relatively un-important (disregading efficiency etc), and if the oscillation didn't start, a small value capacitor (C3 in the schematic) in parallel to the resistor supplying base current to the joule thief transistor (Q1 in the schematic) could generally get the circuit to operate.

The ultrasonic sensor is relatively straight-forward and I previously explored this component, see the Attiny85/HC-SR04 project.


The ultrasonic night light project is a relatively simple project and no particular difficulties, other than the usual care and attention required when constructing any electronic circuit, should be expected.

The following YouTube video shows the construction and testing of the circuit and completed project.

Probably the biggest "gotcha" would be not hooking up the coil corrretly. Note, that the two windings in the joule thief coil are connected in opposing directions, this induces a voltage in the secondary winding which is positive due to the winding polarity (see the dot convention that is used on the schematic).

The type of NPN transistor used for the joule thief did not seem important (I used the 'ubiquitious' BC547 - but any small signal transistor seems OK).

The joule thief coil will generate 'whatever' voltage is required in order to make the load conduct (i.e., whatever is conected at the collector of Q1), so best not to operate the joule thief without an attached load - otherwise, likely to damage the transistor.


The following YouTube video shows the construction and testing of the circuit and completed project.

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with Silver Membership and above can download.


Silver Membership is only $2, so join now!