Saturday, 1 August 2015

A better flasher

Ok, so in my previous blog entry I talked about the fun I had fine tuning my single LED flasher for my little solar / battery relay controller. Well, as it turns out what I produced wasn't the best idea I've had all week.

I went back to my CAD software (Eagle) to update the schematic only to realize the original 555 based implementation had the two blue LEDs in parallel. Yep, darn, I didn't even give the second LED a thought - I could have stuck with a traditional flip-flop after all. Furthermore, my original schematic had the ULN2003 wired incorrectly so as a bonus I've also realized I don't need the original zener diode either. My circuit already has a 5v rail that will be provided by the Arduino.

So, being the perfectionist I am, I went back to the breadboard and put together a basic flip flop (almost identical to the previous circuit) and played around with different resistor / capacitor combinations to see how close I could get to a 1Hz flash rate. Based on the parts I had available I ultimately decided to stick with the standard 10K resistor and 100uF capacitor (provided a rate of 1.07Hz).

While I had all the gear out I thought I'd also optimize the current flowing through each LED. I measured around 5.2v from my power source (my test setup was using a 12v source and a 5.1v zener) and found the LED had 3.3v across its pins (I expected it to be around 3.2v). This leaves 1.9v so for a maximum current of 20mA I would require 95ohms between +VCC and the transistor's collector (with 100ohms being the closest available). I decided to halve the maximum current and use a 200ohm resistor instead. I put it all together and measured the current between the transistor's emitter and the LED's anode - it was spot on 10mA.

Below is the oscilloscope's output, the updated circuit and a small video showing the flashing LED (I used two inputs of a tri-colour LED to emulate two individual LED's.


 

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 :-)