Thursday, 16 August 2018

Automate your garden lights DIY style: getting practical!

This post is a follow up of this project.

After a lot of fiddling around, I finally built up the circuit for automating the turn on and off of my garden lights. It was about time wasn’it? Yeah, I know, it took me some time, but it was worth it since I think the end result is particularly nice and I enjoyed the process of building the circuit.

Goals of this project

The objectives of this DIY project are the following:

  1. Automate the turn on and off of garden lights: 4 LED lights powered from a battery which is recharged every day through an appropriately sized solar panel. The lights should turn on in the evening and turn off in the morning. Ideally turn on and turn off should be adjustable with ambient light.
  2. Improve my basic knowledge on how to design a proper circuit, a PCB, source components and debug analog circuitry.
  3. Keep the project relatively cheap.

The circuit in LTSpice

Below you can find a picture of the circuit simulated in LTSpice with all my notes following testing and a close up of the circuit.

Image 2

Image 3


As you can see, the circuit is pretty simple

  • The source is a 12V battery with a voltage that generally can range from 11.50 to 12.5 V.
  • At node B a voltage reference is generated and through a buffer (U2) this reference is fed to a comparator with hysteresis (U1) which compares the reference with the voltage at bus A. Note that the reference voltage at bus B is adjustable through the potentiometer POT1.
  • At bus A a voltage divider made by a potentiometer (POT2) and a photoresistor feeds a voltage to the comparator U1. From my measurements, the resistance of the photoresistor varies from 2k Ohm when it is full daylight, to about 600k Ohm in full dark. When it is dark outside, voltage at bus A goes up and it turns on the comparator U1 which in turn turns on Q1 and the relay and the load. When it is bright outside, voltage at bus A goes down and U1 turns off thereby turning off Q1, the relay and the load.
  • The load is an LED light which draws 375 mA at 12 V (it consumes nominally 4.5 W) so it can be modelled as a 32 Ohm resistor (at steady state).

A couple of notes on the LTSpice model:

  • Don’t mind the exact mode of the operational amplifiers: the ideal op-amp model tends to behave rather oddly so I decided to use these two which seem to behave like actual op-amps.
  • If you want to simulate a change in brightness from full dark to full brightness to full dark again, simply connect V3 to bus A.
  • The relay inductance is not the correct one (since it is not provided in the datasheet) but I did not bother to measure it since it does not matter in this case as long as a freewheeling diode is used.
  • POT1 changes the reference voltage at bus A (and therefore the “reference sun light brightness”): by lowering POT1 we increase the brightness required to turn (and keep) op amp U1 on. By increasing POT1 we decrease the brigthness required to turn (and keep) op amp U1 on.
  • POT2 changes the dependency of voltage at bus A with respect to the photoresistor: $V_A(P) = 12 P/(P + POT2)$. The derivative of $V(A)$ with respect to POT2 is: $dV_A(P)/dPOT2 = POT2/(P + POT2)$. $P$ is the resistance of the photoresistor - For low P (less than 10k Ohm): increasing POT2 decreases the speed of the change in voltage at bus A due to a change of resistance of P (and therefore a change of brightness). Decreasing POT2 increases the speed of the change in voltage at bus A due to a change of resistance of P (and therefore a change of brightness) - For high P (higher than 10k Ohm):
    P does not influence the behaviour of $V_A$ that much. There is included in the schematic a chunk of R code that simulates this behaviour.
     

I connected V3 to bus A to simulate the behaviour of the circuit. V3 simulates a change from full dark (night) to full brightness (day) to full dark (night) again. In the following plot you can see the voltage changing at bus A V(n004) and the voltage on the load V(n010). The hysteresis is needed since once the light turns on, the brightness captured by the photoresistor increases and you want to avoid the circuit becoming unstable and turning on and off again (it happened during one of the first tests without hysteresis).

Image 4

The circuit in Eagle

After having simulated the circuit, I designed the PCB in Eagle. The components I used are the following

  • 1 photoresistor.
  • 2 potentiometers ACP SPAIN 20k Ohm.
  • 1 IC LM358N which has 2 operational amplifiers.
  • 1 NPN transistor BC337-40.
  • 1 diode 1N4148.
  • 1 connector for the wires.
  • 4 10k Ohm 1/4 W, 5% resistors.
  • 1 1k Ohm 1/4 W, 5% resistor.
  • 1 blue LED.
  • 1 relay SRSZ-12VDC with 5 pins.
  • A 1uF capacitor.

A couple of notes on my design and components choices

  • I decided to use a single IC which had 2 operational amplifiers. The LM358N was available at my local store and fitted my requirements. I know a comparator would have been a better choice for U1 but I did not want to use 2 ICs and this one works good enough.
  • The diode does not need to be this specific one, it can be a generic diode. It is operated pretty rarely (2 times a day).
  • It is particularly important to set the base resistor (R9) of the transistor to 1k Ohm. Since the negative pin of the LM358N is pinned to GND, when the output of the IC is off, the actual output is around 0.6 V. R9 should be high enough to ensure that the transistor does not turn on when the output of the IC is low.
  • The actual capacitance can be different from the one stated above. 1uF is more than enough for stabilizing the output of the battery which is already pretty stable.

The schematic is drawn below. I went through a few revisions of the schematic mainly for the following reasons:

  • The footprints of the connector, the potentiometer and of the relay were not available in Eagle so I had to draw them on my own. You can find them here.
  • The schematic of the relay given by the manufacturer in the datasheet is WRONG! I had to correct it when drawing the footprint!!! Always double check with the actual part before putting your component in your PCB design.
  • I used the default and the SparkFun rule check routines.
  • I added a blue LED to signal if power is applied to the board.

Image 5

Image 6

The final result: PCB

For the manufacturing of the PCB I decided to go with JLCPCB. They’re prices are amazingly low for prototypes. The PCB I received is perfectly polished and exactly as I expected it. There were no problems in processing my order. Excellent service, I would recommend it to every hobbyst.

IMG_20180813_133749


A couple of notes on the PCB:

  • This PCB was obtained from an earlier version of the Eagle drawing. This is why you see a few different details. Namely I corrected the footprint of the silkscreen drawing of transistor T1 (which is reversed) and its position. I also added a few notes on the silkscreen.
  • The PCB worked perfectly from the beginning, I was pleasantly surprised.
  • 12 V from the battery is applied to the pads: pad 1 is positive and pad 2 is negative (GND).
  • The load is connected to the connector.

The final product mounted and operational looks like this

IMG_20180816_083401

Please don’t mind the unordered arrangement of the resistors, this was one of the earliest prototypes.

After a few tests I found out that the circuit has the following power consumption:

  • 40 mW during the night, i.e. when operational.
  • 0.5 W during the day, i.e. when non operational.

The consumption during the day is a bit high and is mainly due to the relay. This is partially ok since the panel is charging the battery during the day but still this is not the best in terms of efficiency of the whole package. During the night it is crucial that the power consumption of the control circuit be low since you want the battery to last as long as possible and spend its energy to power the load.

Operational notes

I would suggest not to fiddle around too much with the potentiometers before testing the working of the circuit. The circuit is designed to work with both the potentiometers in their middle position. When first assemblying the circuit, please make sure that the potentiometers are as in figure. Then you can try tweaking the potentiometers around.

You can use the device to control 12 V loads other than lights.

Future improvements

There are a couple of improvements I’d like to make in the future, namely

  1. Replace the relay with a transistor to save power during the day.
  2. Add a “battery save” feature that disconnects the load when the battery is discharged and disconnects the solar panel when the battery is fully charged.

How can I build this?

You can find the LTSpice simulation, the Eagle schematic and PCB here. If you want to build this project you simply need to:

  1. Make the gerber files from Eagle.
  2. Send them to your PCB manufacturer.
  3. Buy and then solder the components.

Conclusions

The conclusions I drew from the making of this project can be summarised as below

  1. Hardware projects require time and patience. But they are worth it in the end. If you break a part you need to wait at least 3-4 days to get the replacement.
  2. Spare parts available on the shelf which are not the exact match may work too for a quick test.
  3. Circuit behaviour can be simulated to a very fine degree but the practice is always the final test.
  4. Do not overkill using parts that are not needed. In my example, the relay is overkill, an NPN transistor would have suffice and even improved the power consumption of the board. Lesson learned.
  5. Always double check the footprint of components with the actual thing if you can. Trust datasheets but double check crucial things.

5 comments: