• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

Automatic night light

Introduction

This project is a continuation of tuturials on voltage comparators, photo resistors and voltage dividers. The idea is to create a light which will automatically light up when the dark falls, and go off in the morning, all depending on the amount of light. An example of use may be street lights, where using this type of set, instead of "manual" manipulation, a considerable amount of electricity would be saved, since the lights would turn on and off when necessary,

LM393 - voltage comparator

LM393-pinout

Voltage comparator is a bistable circuit (flip-flop) which compares two analog signals at the input and depending on the outcome of the comparison it gives HIGH or LOW output. We can imagine it as a small "multimeter"  with a switch. When the measured voltage is higher on the first input pin, the switch is turned on. However, when the voltage is higher on the second input pin, the switch is turned off. In this project, we will use LM393 voltage comparator. More about it in this tutorial.

Photoresistor

Using the photoresistor, we shall read off the amount of light and LM393 will be the switch turning the LED diode on or off. This is actually an optical light sensor.
Before we proceed, we will briefly explain how the photoresistor works. The amount of its resistance depends on the amount of light falling on it. When it is in the dark, the amount of resistance is high. On the other hand, when it is exposed to light, there is little resistance. In some kind of ideal conditions, resistance in the dark would be app. 200kΩ, and when there is bright light 1-2kΩ. For more, check the datasheet.

How to connect?

For this project we will use only ln1(-) and ln1(+) inputs and Output1 output. Firstly, we connect the power source to Vcc and GND pin comparator. As a source we can use a 9V battery.

lm393a

The following step is to make a voltage divider with a fixed resistor and a photoresistor. The fixed resistor should be 10kΩ, which will provide an output of 0.429V when the photoresistor is in the dark (it provides 200kΩ resistance) and 7.5V when the resistor is exposed to light (it provides 2kΩ resistance). Whether we will connect this output voltage to ln(-) or ln(+) does not matter in this case, but we will tell you a bit more about it later on. So, let's connect it to the inverted input, In1(-), yellow wire.

lm393b

After that, we will connect the input voltage for comparison and over 10kΩ potentiometer so that we can adjust the circuit sensitivity. We connect the potentiometer by connecting the reference voltages to the edge pins. On the left pin, we connect the GND, and on the right +9V. The central pin is our output voltage and we connect it to a non-inverted input of the comparator In1(+). The voltage that the input provides depends on the position of the potentiometer. If we turn it completely left, i.e. towards the GND, the output voltage tends to 0V. As we turn it clockwise, the output voltage is proportional to + 9V. For starters, we can put it roughly in the central position.

lm393c

What is going to happen next is:

    • in the dark: the voltage on the inverted pin In1(-) is lower than that of the non-inverted In1(+), therefore we get GND on the output
    • in the light: the voltage on the inverted pin In1(-) is higher than that of the non-inverted pin In1(+), therefore we get Vcc (+9V) on the output

Since we want the LED diode to light in the dark, the Output pin will be connected to the cathode(-) of the LED diode, while we will connect the anode (+) over 330Ω to + 9V.

 

lm393d

 

 

In case we replaced the inverted and non-inverted input on the voltage comparator, they would get +9V on the output, in the dark. Then we would only connect that output to the LED module anode, while connecting the cathode to GND. Of course, through some resistor.

If we want to connect a source other than a regular LED diode, we must calculate the resistor we will use this source with instead of the one of 330Ω via Ohm's law.

What else?

In the end, just note that if you intend to use this circuit with high currents and/or voltages: you should make sure to insert the relay or transistor between the comparator and the light source.

Leave a Reply