Thursday, 20 August 2015

Controlling lights according to sunlight using only few electronic components

At the beginning of this summer, I was asked to provide a simple (and possibly cost-effective) solution to a simple problem: how can I do in order for my garden LED lights to turn themselves on and off according to the sunlight?

There are plenty of ready to use circuits and tools that one can use to answer this question, however I decided to try and design something “new” empowered by what I recently learned about NPN transistors, relays and LT-Spice IV. Let me talk you through my workflow:

The problem and the setting:

Senza titolo-1 copia

The LED lights which provide illumination in the garden are powered by a solar panel which during the day charges the battery. At night, the stored energy is used to power the lamp. The solar charge controller ensures that the charging process is smooth and that everything is going as it should during the charge and discharge processes. Since the solar charge controller is very minimal, it does not have a timer or a switch to turn on and off the lights. A manual switch is therefore used instead (not shown in the picture and to be replaced by this project). The lamp is a 12V 4.5W LED lamp.

The solution

There are plenty of ways to solve this particular problem, some more complex and expensive than others, however, with my solution I wanted to address some important issues:

-The switch circuit should account for changes in sunset and sunrise time shifts during the year.

-The switch circuit should be as minimal as possible, it should function with 12V DC and consume as few energy as possible in order to avoid the use of external power supply, extra batteries or external cables.

-The switch circuit should be designed to maintain the idea of stand-alone self sufficient garden lights.

Having taken into account the points above, my solution is the following:


The relay is then connected to the load and is turned on and off according to how much current flows through the photoresistor into the NPN transistor.

LTSpice IV lets you simulate a variable resistor and understand how the circuit will behave under different parameters. Using the datasheets (check at the bottom of the page) I know that the photoresistor should vary between 2K and 600K  depending on the external light while the relay has a coil resistance of about 400 Ohm. I briefly considered connecting the load (the lamp) directly to the transistor, however the current gain was not enough to fully power the lamp since the lamp has a resistance of 32 Ohm and therefore needs about 375 mA to be fully operational. There certainly are way around this but I decided to not go down this way. Furthermore the transistor cannot deal with currents higher than 100 mA through the collector so it is not safe to pursue this option.

The way the circuit works should be the following:

During the day, sunlight is strong enough to pull down the resistance of the photoresistor and let the current pass through the transistor powering the relay switch. At sunset, resistance starts to add up until it is strong enough to prevent current flowing into the transistor and therefore triggering the relay.

The LTSpice simulation confirms the logic:


Of course my circuit is not perfect and does not take into account the coil inductance and the inductive kick of the inductor during the on to off cycles, however by using a relay module one can neglect this aspect. The full circuit (without inductor) with the relay module and the load should look something like this:


(both circuits are connected in parallel to the 12V battery)

By simulating the circuit behaviour we can see when the relay should be triggered (at about 24K Ohm), now we only need to do the proper connections which should be reversed in order to our lamp to be on at night and off during the day. Our controlling circuit should use 30mA during the day (because of the relay) and 375mA during the night (because of the load).


Below you can find a list of the components I used and the resources I found useful.

List of components:
-Relay SRD-12VDC-SL-C
-NPN 2N3904 transistor

Any suggestion for improvements is welcomed! :)

No comments:

Post a Comment