Building a small relay controller
The last thing I want to be doing while camping is keeping an eye on my battery status so I switch from one to the other before the battery in use is depleted by more than 50%. Sure, I can put both batteries in parallel but I prefer to give my Ctek 250 one battery at a time as this is how it will perform at its best.
For this reason I've decided to design and build my own smart controller that can monitor battery status and automatically switch the charging and source batteries. At the heart of the design will be an Arduino that will be used to monitor voltage and current information. This information will be interpreted and used to drive relays that will switch the loads automatically. I'll also be building in some visual indicators and an LCD to provide real-time data. I have plans to eventually add data logging so I can read the information at a later time in the hope of being able to detect reduced battery performance. So many plans. Who knows how far I'll get with this project, but in this blog I'm giving some insight into one small part of the circuit design.
The final product will contain two tri-colour LEDs to indicate the state of the system for each of the two batteries connected.
RED - Will indicate the associated battery is currently being charged.
GREEN - Will indicate the associated battery is currently being used to source any connected load(s).
BLUE - Will indicate the associated battery is currently isolated (not charging or providing a source of power).
For a bit of fun I decided it would be good to make the BLUE indicators flash. I didn't want to waste two outputs of the Arduino for this purpose and since the microcontroller has a limited memory I didn't want to waste valuable space writing code for something I could do via electronics.
Flashing an LED can be achieved by a number if different methods. One would be to use a 555 timer and the other would be to use a handful of resistors, transistors and capacitors to create a bi-stable multi-vibrator (also known as a flip-flop).
I originally planned on using the 555 timer but for no reason other than wanting to play with my oscilloscope I decided to do it using the basic components.
All flip-flop circuits I've created contained two LEDs that alternated. I only want one LED so a small circuit refactor was going to be required.
Most flip-flop circuits you'll find use NPN transistors with the LEDs connected between its collector and a resistor that limits the current from the power source.
My tri-colour LEDS are common-cathode so I thought I'd start with a circuit I was familiar with but move the LED to the transistor emitter. Since I only needed one LED, I removed the second from the circuit and switched it on.
It was crap. I could see the LED ramp up in brightness before it abruptly turned off again.
It was time to connect up the oscilloscope and check what was happening on the capacitor being used to change the state of the transistor.
As can be seen in the first image the voltage would ramp up, hold and then drop. Unfortunately, the ON time period was much longer than the OFF period.
I tried adjusting the resistor values to alter the capacitor charge rate but this wasn't very effective. I then realized the LED that I had removed was altering the symmetry of the circuit because of a difference in voltage drop (the blue LED can cause up to a 3.2v drop).
The solution was quite simple in the end...reduce the size of the capacitor on the affected side.
At first, the frequency was too fast (about 0.8Hz) but at least the ON and OFF periods were roughly the same. So, with a little more fine tuning (change resistor values to increase the time it takes to charge the capacitors) I managed to obtain a comfortable rate of 1.08Hz.
Happy days. Wow...2am, it was time to head off to bed.
In the morning, however, I was back at it. I wanted to perform one more test - I wanted to hook all of this up to a ULN2003 IC (contains 7 Darlington pairs) to make sure I could drive a 12v relay on one output and have my flasher be driven from another (the flasher incorporates a 5.1v zener to reduce the 12v input source).
It all works. Plenty more to do, but at least the prototyping has finally begun.
LOL...A schematic error - the top power rail for the circuit is meant to be connected to the cathode of the zener...not the 12v rail. Oops. At least I tested it correctly :-)