Translate

Showing posts with label Battery. Show all posts
Showing posts with label Battery. Show all posts

Sunday 29 July 2018

Paddock battery charging.


Paddock battery charging. That is charging up our racing car battery whilst it's stood in the paddock awaiting it's next run. Both Julian (with the Mini) and Matt (with the Chevette) have expressed an interest.... right...

So we've started the car, ticked over in the cue lane for a few minutes, done our timed run, and driven back to the paddock. We can now charge up the battery waiting for our next run.

The car is fitted with an acid mat battery, and we have a spare, normal lead-acid battery to charge from in the paddock... great, just connect the two together right? Well, no. The fully charged voltage of a lead-acid battery is 12.6 V (at 20 degrees C) ... the best we can hope for is the two batteries, once connected, is to equalise, and it won't happen quickly. So we need to raise the voltage of the paddock battery to 14.4 V, which will charge the car battery without causing it to gas. We'll also limit the current to 5 amps or so.

Now, we could build ourselves a small boost circuit to do this for us, but thankfully, we can purchase a module from eBay for very little money.

It has adjustable voltage output and adjustable current limiting, and rated at 90W.












I'd also like to be able to measure the output current and voltage, and the input voltage...

Voltages are easy to monitor. I don't want the paddock battery to become discharged below 11.6V to avoid it becoming damaged.

Output could be measured by looking at the voltage drop across a small resistor in the negative lead to the battery under charge (in fact, that's exactly how  the constant current mode on the boost module is done), however, I'll use another module....

....enter the ACS712 current motoring IC.
It measures the current by looking at the magnetic field created around a heavy piece of wire which is moulded into the IC. There are 3 versions of the IC, a 5A version, a 20A version and a 30A version. I have chosen the 20A version, so I've got a bit of headroom.












There are two relay modules, which are used to switch the charger on, and the other to enter "bypass mode", whereby if the battery to be charged requires more than 5A at the minimum voltage, the booster will be bypassed, until the charge current falls below 5A, at which point the booster can safely take over.









This is the monitoring circuit. Power is supplied to the ATMEGA328P and accessories via a 7805 regulator.  The uC reads the voltages of input and output using ADC 2 & 3 respectively, via dividers formed by R2 & R3, and R4 & R5. Current is read (as a voltage of  100mV / A) by the ACS712 connected to ADC0. A relay output is provided, which will connect the output from the boost converter once the micro is up and running, and the battery to be charged is connected. If the current exceeds 5A, the boost converter is bypassed, so as to protect it until current is stable. Data is displayed on a 20x4 LCD, connected via an I2C interface. In the event of the input voltage falling below 11.6V, the beeper will sound to alert the user the input battery is becoming seriously discharged. I could stop charging at this point, using the relay, but it's more important that the car battery is charged than the input battery being flat (although at 11.6V, the input battery is entering deep discharge, and permanent damage/loss of capacity may be being caused)

A small PCB is etched ... 

Here's a great website for creating a 3D view. It only works with small boards (unless you want to pay for it) ... but's its a fun thing... just drag and drop your .brd file from eagle into it! You can zoom around and look at any angle, even from below ... Website can be found at 3dbrdviewer.com. (Sadly, since writing this, the site has closed.)


It's a pity it doesn't look quite so good in real life ;)









And the unit is assembled and tested...

Shown here charging a small SLA.












Code (and eagle files) can be found on my github page https://github.com/andydoswell/paddock-charger

Saturday 25 March 2017

Arduino LiPo charger / monitor.

I've been using 18650 LiPo cells for a while in a few gadgets.

I'd purchased a small charger module from eBay, and assembled a single cell charger.




It worked well, but it just wasn't geeky enough ... I'd like a bargraph, voltage and percentage on a nice colour screen, and the ability to charge 4 cells...




so, I bought some more charger modules from eBay....













... a high current (5A) adjustable buck converter ...











...  a super cheap 2.2" ILI9340C display ...










... and a 4 cell battery holder ...












... some tea was drunk, and a plan hatched.

Each charger module will be connected to the high-current 5V supply, and operate independently of the arduino. The battery voltage will be measured by the arduino, and will be used to produce the data for the display. When the charge complete LED on the charge module illuminates, the arduino will indicate this on the display.

Some code was created and a prototype lashed up...

First problem was the display. The ILI9340C is designed to operate on 3.3V. Mine was fitted with a 3.3V regulator. "Great" ... except the data lines need to be converted to 3.3V ...

I fabricated a small resistive divider board, and fitted it. Each line from the micro feeds a 4.7K resistor in series with a 9.1K resistor to ground. The display connects to the junction between the resistors. The 5v supply I left supplying the display, and the LED backlight was connected to 5V via 180 ohms... bingo!

Next was to modify the charger module, so we can see when then charging LED is lit. Now I looked at (what I thought was) the datasheet for the IC, and carefully soldered a wire to pin 8 of the IC, being CHRG (active low) ... great ... nope. It didn't work. It stayed happily at 5V, regardless of the state of the battery. Thankfully, after some googling, I found the correct datasheet, and reverse engineered the charger module...


I set up the buck converter to output 5.0V , and mounted it, the arduino and the charger modules on a piece of perfboard. Before connecting the charger modules, I calibrated each analogue input on the arduino to give an accurate voltage reading at 4.2 and 2.8 volts.

Connecting in the chargers, and putting a battery in gave me good results .... nice bar graph reading, pretty looking display, BUT putting another battery on charge revealed an issue.... the voltage reading was getting less accurate the more cells were on charge .... the meter actually over-reading the voltage. I messed about for a while with the code, seeing if there was a reading error (there always is a "settling time" with the arduino's analogRead function) .. but the fault wasn't there..

Measuring the output of the buck converter exposed the problem. Under load, the regulation was letting me down, the voltage falling to 4.76V. Now that doesn't effect the charger circuit, as it's designed to operate down to 4.5V... BUT it does effect the arduino's ability to make accurate measurements.. It's down to how the arduino's reference voltage is derived. The arduino's A to D uses a reference voltage, connected to the AREF pin (pin 21 on a ATMEGA328P). In arduino, this is coupled straight to the 5V supply... if the supply is moving about, so will the values from the A to D converter. Not good. Now we could put a voltage reference IC here, but I'm using a pro-mini, and modifying that tiny PCB is not an option.

A note on voltage calibration. When you first run the software, you may (probably will) need to alter the voltageCal value in the software to give accurate readings. Easiest way to do this is read the voltage at the battery compartment terminals of one unit with a meter, and compare it with the reading on the display. If the two don't marry up (it should be around 4.06V), then take the actual reading on your meter and divide it by the reading on the display. Now multiply that value by the current voltageCal and use this figure to be the new value for voltageCal. If the display is reading low, your multiplier will be greater than 1. If it's high, it will be less than 1.

Improve the power supply's regulation? OK, an option, but we're dealing with quite a high current output here , so perhaps that's not a good idea either...

Option 3, provide the Arduino with a separate regulated 5V supply. The load isn't much, and doesn't vary much either... Ideal. So, a simple 7805 and a handful of decoupling ? ... Almost ...


This is a picture of the reverse side of the power supply... the ground pin is at the bottom. See that resistor? It's 0.05 ohms. It's in series with our ground output. It's so the unit can calculate how much current is being drawn, and limit the current if required (there's a current limit pot on the top of the unit).

Whilst the module is not isolating (the output is still referenced to the input), the ground at the output of the module is not quite the same voltage as the ground at the input, and the situation gets worse as the current being drawn increases. So we need to feed our 7805 with the "raw" supply coming in, but ensure our ground (or more technically, reference pin) of our 7805 is connected to the ground on the output side of the module. Sorted.

It doesn't look nice.. it's a bit of a rat's nest..


.. except the display, which I'm rather pleased with ....










So here's the schematic...



... and the code...


... and a picture of the completed unit in use :)



One word of warning... put the batteries in the right way round. Reverse polarity will destroy the charger modules, and possibly the A to D on the ATMEGA328 too :( .. don't ask me how I know...
I've now added 4 x 1A fast acting fuses in line with each battery.



Saturday 10 October 2015

Arduino Mains Monitor with SIM900A GSM messaging.

Picture the scene... You're away on holiday, sunning yourself in Spain (or if you're Spanish, enjoying the damp weather in the UK !) ... and thousands of miles away, some spurious minor electrical niggle in your house causes the RCD circuit breaker to open. You return 10 days later to find the contents of your freezer oozing their way across the kitchen floor. Not nice... You reset the breaker, and the power comes back on, showing no faults.

It happens from time to time in my house. I've tested each circuit, and every appliance to try and find the cause of the random tripping. The fault is not visible on any of my insulation readings, but, nevertheless it does happen. Sometimes not for years.... frustrating!

So what can we do about it? Fix the fault would be the easiest thing to do, but it's eluding me. How about monitoring the mains, and sending me a message, so if it does trip, I can reset the power without issue? Good plan...

Now the disclaimer:

WARNING. Do NOT try this at home. This project deals with mains voltages. A shock from the mains will hurt and can easily be fatal. Work safely. Use an RCD. Disconnect from the mains before making any adjustments. 
RESPECT IT'S AUTHORITY

I will not, under any circumstances, accept any liability if you decide to re-create this project for yourself.


Now that's got that out of the way...

So, we have a plan. Measure the mains voltage (and why not frequency at the same time?), and act conditionally on it's failure. We also need to get it to send us a message. We're going to need some form of uninterruptable power supply, so when the mains does go off, our micro will still be running, and we've got power enough to send the message. Here's the circuit:


I'll go through it step by step...

Power comes in via a fuse to two transformers. TR1, is a mains to 15V transformer, and is used as our power supply. It feeds a bridge rectifier, B1 and C1 and C2 are used to smooth and decouple the resultant DC. The DC is fed via D2 to a 7805 regulator, which provides the 5V for the Arduino and the SIM900  module. So that's fairly straightforward. The 7805 in this instance is a 2A part, as the SIM900A does require a fair amount of current to function.

(You could, and it would be safer to do so, build this unit using two wall warts, one, with, say at 15VDC, 3A output to replace TR1 & B1, and a second, with AC output in place of TR2. That way, all the tricky and potentially dangerous stuff with the mains is eliminated)

The rectified DC from B1 is also fed to two LM317 voltage regulators in series. The first, IC1, is configured as a 100mA constant current source, this is then used to feed the second regulator, IC2, which is configured as a conventional voltage regulator, in this case, R3 is adjusted to provide around 14V. This forms a 100mA constant current charger, with maximum voltage of 14V, which we can use to charge G1, which is an old 12V NiMH battery I happened to have kicking about. It's got plenty of capacity left, so will do nicely as our back up battery. S3 is a battery diconnect switch. Useful for resetting. (Why didn't I use an LM200, as it is capable of both current and voltage regulation in one package, instead of two LM317's? Because I didn't have one!)

So, when the mains is present, our battery is being charged. In the event of mains failure, D2 will stop conducting, and the supply will be seamlessly taken over by the battery, supplying current to the 7805 via D1. D3 prevents current flowing back into the charging circuit. The battery voltage is also sampled at the mid-point of the potential divider, R11 and R12, and fed to the Arduino A1 pin. T2, between the reference pin of IC2 and ground, is used to switch off the charging circuit momentarily, so we can measure the battery voltage, and not just the output of the charger. It's controlled by the Arduino A2 pin, configured as a digital output.

OK, so that's power and back up power sorted, so what about measuring the mains? TR2 is a small (3VA) 18V mains transformer. This feeds another bridge rectifier, B2, and a small smoothing network, formed by C7. The voltage developed across C7 is fed to a potential divider formed by R5 and R4, and the resultant voltage fed to Arduino A0. This voltage will be directly proportional to the mains input voltage on the primary of T2.... or will it? Whilst I was experimenting, I noticed the measurement wasn't linear. Adding a bit of loading, in the form of R15 to the secondary helped matters no end, although it was accurate enough over the range required for this to be left out, if required.

Also coupled to the secondary is our frequency measuring network. The AC is fed via coupling capacitor C8 to the base of a BC547, T1. This provides a 5 volt 50 Hz signal to the input of IC4A (a Schmitt trigger hex interter), this will square our pulses up. The output of IC4a is fed via a low pass filter, formed by R8 and C9 to the input of IC4B, the output of which is connected to the Arduino pin D8. We'll use this to measure the frequency of the mains. Tie all of the unused inputs of IC4 to ground.

On to the micro side of things...

The LCD is wired to the Arduino in the time-honoured fashion, except for the cathode of the backlight, which isn't connected straight to ground, but to the collector of T3. This allows us to control the backlight, using A4 of the Arduino configured as a digital output. There's a momentary switch coupled to A3, which is used as a "push to transmit" function, and a toggle switch, S2, connected to pin A5, which is used to stop the SIM900 sending messages. R9 is the LCD's contrast control.

The SIMR pin on the SIM900 module is connected to the Arduino's hardware serial Tx pin, and the SIMT pin is connected to the Rx pin.

The software.....

We're going to need something to measure our frequency. I did initially use PulseIn , but it's not that accurate, so I switched to using the most excellent FreqMeasure library, available from https://www.pjrc.com/teensy/td_libs_FreqMeasure.html . Now this has a drawback. It uses Int 1, and this is in conflict with the software serial library, which is why the SIM900 is connected to the hardware serial port of the Arduino. The issue here is the hardware port is also where the inbuilt USB interface sends/receives data, so you'll need to disconnect the SIM900 from the arduino whilst uploading the sketch, or doing any serial debugging. You can use SoftwareSerial during development, but be prepared for some unusual responses from FreqMeasure!

Ok, so the sketch.

There's a rake of variables set at the start. The variables to watch are the mains tolerances, these will need to be set for your local mains (They're currently set for UK mains spec.)

  float MainsMinV = 216.2; // This sets the lower limit for the mains voltage. Change this to suit your local voltage limit
  float MainsMaxV= 253; // Maximum voltage limit
  float BatteryMin=11.2; // Battery low limit
  float MainsMinF=49.5; // Minimum allowable mains frequency limit, change to suit local power
  float MainsMaxF=50.5; // Maximum allowable mains frequency limit.

You will also need to change line 260 :
      Serial.println("AT + CMGS = \"+44xxxxxxxxxx\"");// recipient's mobile number, in international format
If your mains is not ~240v, you will also need to change the scaling factor in the software , line 286, so the voltage reads correctly. Currently the mains voltage is scaled so 250V is equal to 5V at our micro. If, say, you're on 120V mains, and want the voltage to top out at , say 130V, then the scaling will be 130/5 = 26. It's currently set to 51, so 5V on our analogue port reads as 255V :
  ACVoltage = (sensorValue * (5.0 / 1023.0))*51;

Adjust R4 to get the mains calibration correct.

So, here's the complete sketch:


If you're using a SIM900A module outside of Asia, you may run into difficulties, as I did. There's some brief notes I made here : http://andydoz.blogspot.co.uk/2015/10/sim900-and-sim900a-module-signal.html and a link to a website which contains detailed instructions on sorting out the firmware to make the unit work.
Here's some pictures of my unit:



BTW. Sainsbury's is my service provider!









Electrical Safety is paramount. Here is the incoming mains earth (ground) securely tied to the chassis of my metal case. 

Friday 6 March 2015

"Stupid" - The simple smart charger for lead acid batteries.

Now my good friend "Curly" has a caravan. It's a great little thing, but has the most bizarre electrics I've ever seen in a caravan. It's got AC mains, and AC 12V.... AC???!!! When mains isn't available , I think the idea was a relay clicked over to supply the internal lights from a battery someplace, thus switching from AC to DC. This battery was long gone, and most of the wiring with it.

Matt wanted to add a leisure battery back in to the electrics so he could run his LED lights and telly etc, without having to have a mains hook-up, and when mains wasn't present to charge the battery.

I took a look at the bizarre circuitry, and rapidly worked out we were going to need some for of charge controller, or "smart" charger to do the job.

Then I thought again. We've already got a nice 10A 12V AC transformer, and an automotive relay in this bizarre set-up, so can we re-arrange this to provide us some sensible charging?

Measuring the off-load voltage of our transformer showed that, after rectification we were nearing 18V. Not good for trying to charge our leisure battery for any length of time, it will simply out gas and dry out. Nah.

Some form of charge controller? Yeah. A pulse-width modulated thing, with possible arduino control and a sensible FET was considered. Then I got to simplifying. What we needed was a window comparator.

Now a window comparator circuit usually uses two op-amps as comparators, one to turn the relay on to start charging our battery when the battery volts are low, and one to turn the relay off to stop charging our battery, once the battery voltage has risen to a charged state. Now there will be much debate about sensing battery temperature, and constant current, baulk and float charge amongst you at this point, but let's keep this simple.

So, I start thinking about our window comparator, on at around 11.5V and off by 14.3V ... seems reasonable, a voltage reference, some potential dividers, a dual op-amp, a driver transistor and we're away .... but is there a simpler way?

How about just using a potential divider on the base of our transistor to switch the relay, and not using any comparators... well, that would work, but the hysterisis between the two required voltages might not be good enough and cause the thing to oscillate. I try it out. It oscillates. OK, so how about simply two transistors and a couple of steering diodes? Yep, that works... but can it be simpler still?

Looking at the circuit for a while, how about using the spare contact on my relay to switch in the second pot, altering the value of my comparator? Yep!

It's ended up like this:-


Now, it's not the easiest of things to set up. I connected Pin 30 of the relay to pin 87A of the relay and powered that point with a variable power supply to first set the minimum voltage (11.5V) using R2, then the maximum voltage using R1. Vary the power supply to the unit to see at what voltage the relay clicks over. There is some interaction between the pots, so it will take a few goes at adjustment to get the unit to achieve repeatable results.

Issues.

Yes, it's simple. There are issues. If something fails, there's precious little to stop it boiling our battery dry. The voltage control does seem stable in use, however. If the battery does fail open circuit, or F1 blows, the unit will oscillate... but at least the buzzing will draw your attention to the fact the battery has failed! The charging voltage does not compensate for changes in temperature.

Don't try and use this on a sealed lead acid battery. Chances are if something does go wrong, the battery will not be able to vent quick enough. It could burst. I've seen SLA's that look like footballs because they have been abused. Don't do it. 

When charging lead acid batteries, hydrogen gas is given off. Do not charge any lead acid battery in a confined space, or worse, a sealed box. No naked lights. I've seen tops blown off batteries as something has ignited escaping hydrogen. It's not good.