Introduction: A Better Light Sensor Switch (PCB Included)

About: I'm an electronic engineering student. I don't usually have much spare time but I like to work on random projects to keep myself entertained. I hope you like them!

Some time ago I was asked by my father to design a light sensor circuit for him, he has some LED's installed and a solar panel and a battery array, which he then uses to power his garden lights. The function of this light sensor was to turn on the LEDs at night when the light falls under certain threshold, that was quite straight forward, and I built a simple comparator to do the job.

After some testing I noticed the output tends to switch states when the voltage at the sensor is around the threshold voltage, this can cause some flickering during the last moments of the day, specially if there are clouds around which make the sensor voltage go up and down.

I decided to solve this by adding some hysteresis to my comparator, this means, once the sensor reaches the threshold voltage, the lights will turn on, but will also increase the threshold voltage. In order for the lights to turn off again, the sensor must now rise a considerable amount of voltage to reach the threshold again, and this gives it a larger margin to cope with interferences caused by the environment.

Step 1: Materials

If you want to build this sensor you'll need:

  • 741 OP amplifier
  • 8 pin socket (optional)
  • 10 Ohm resistor
  • 30k to 100k resistor (to set histeresis)
  • 10k to 100k resistor (to be used with LDR in a voltage divider)
  • Light dependent resistor
  • 100k potentiometer
  • 4148 diode
  • IRF540 MOSFET
  • Prototype board or copper clad board
  • Some wires
  • Heatshrink tube

Tools:

  • Soldering Iron
  • Lighter

Step 2: How It Works

Operational amplifiers can work as comparators by removing the feedback loop, this makes the gain to be incredibly large, so large that the slightest difference of voltage between the inputs is enough to make the output signal change states. As the name suggests, a comparator will take a voltage at the input and compare it with another, depending if it's higher or lower the output will become high or low, depending on the configuration.

When acting as a comparator, an operational amplifier usually has a reference voltage and a variable voltage, the reference voltage will remain constant, and in this case is fixed thanks to the potentiometer, this voltage can vary from VCC to 0 volts. The variable voltage is the voltage coming from the sensor, more light means more voltage, and less light means less voltage in this case, this voltage variation be achieved thanks to a voltage divider consisting of the LDR and a resistor.

Once the voltage coming from the voltage divider is lower than the reference voltage the lights will turn on, but since the output is connected to the reference voltage by a resistor, the reference voltage will rise a bit as the output voltage goes high, once this happens, the variable voltage will have to climb that gap that has been just created to turn the output low again.

This can be seen in the video, the blue line is the voltage reference, the yellow line is the sensor voltage and the pink line is the output voltage, as you can see, when the variable voltage passes the reference voltage, the output goes up along with the reference, and now the variable voltage has to climb that gap back to turn the output off again.

Step 3: Set Voltage Divider Resistor

To set up the LDR-resistor voltage divider we need to measure the LDR resistance in light and completely darkness conditions, in my case direct sunlight gives a value of 300 Ω, while the resistance when in total darkness is around 200 kΩ, the appropriate thing to do is to choose a resistor between those values, around 100kΩ, I ended up using a 40kΩ resistor due a wrong measurement, it works fine enough, but I'll probably end up changing it.

Choosing a value too low, like the one I chose, will cause the light to turn on with very low light conditions, even if the reference potentiometer is already set to do this. Choosing a value too high will cause the lights to never turn on. The ideal resistor is probably around 80-120kΩ in this case.

This arrangement of resistors will produce a voltage at the output which will depend on the resistors used, this voltage is determined by the equations above. OP amps have a very high impedance, this means almost no current makes it though the input pins, this allows us to design the voltage divider without taking into account any loads.

Step 4: Set Hysteresis Resistor

The hysteresis resistor's function is to raise the reference voltage by a certain amount when the lights turn on, this is made to prevent the variable voltage to oscillate around that reference causing flickering.

The amount by which this voltage rises is represented in this graph I made (see picture).

As you can see, there's no hysteresis when the potentiometer is set near the extremes, this is why it's important to set a correct voltage divider resistor which will allow the circuit to operate in the middle to middle-low range.

Step 5: The Circuit

The circuit is quite simple and can be assembled easily, here are the schematics and board files for Eagle:

Specifications:

  • Recommended voltage range: 9 to 20 volts
  • Absolute voltage maximum: 22 volts
  • Recommended load current:>10 amps, heatsink is recommended past 5 amps (1.1 watts of power dissipated at that point)
  • Maximum load current:33 amps at 25ºC, 23 amps at 100ºC

IRF540 datasheet

To increase the load handling capability you can use a higher end MOSFET or parallel several MOSFETs with the same characteristics.

Step 6: Making the Circuit

I used a copper clad board to create the circuit using the toner transfer method. I also used some connectors to connect the hysteresis resistor, in case I want to change it afterwards.

TIP: If you remove the hysteresis resistor the circuit will return to it's normal operation, working without adding voltage to the reference voltage after it is trespassed.

Step 7: The End

I've tested this circuit and it works flawlessly, so feel free to print or make your own.

TIP: Don't place the sensor near the lights you're trying to control, when they are turned on the sensor will turn them off because it detects the light they produce, entering in an annoying strobe-like loop.

Thanks for watching.

Sensors Contest 2016

Participated in the
Sensors Contest 2016