# Circuit to choose/correct battery polarity

#### CuatroMan

Joined Nov 25, 2018
13
Hi friends,

I'm hoping for a bit of help with a challenge I'm faced with solving.

I have a project that aims to "automatically" sort AA batteries by remaining voltage/capacity.
I believe I have a handle on the voltage sorting portion, yet the physical orientation of the batteries is tripping me up.

With a voltage reading of a positive number or negative number, I can determine if the battery is oriented incorrectly.
Yet, I'd like to find a circuit solution to possibly switch the negative and positive leads so the batteries polarity is correct and functions like a properly oriented battery.

I'm hoping this explanation makes sense -- I'm a lifelong newbie.

Thanks for any help!

#### AlbertHall

Joined Jun 4, 2014
11,240
You could connect the battery via a bridge rectifier so the polarity would always be correct but you will lose some of the voltage in the diode drops.

Alternatively, having detected the polarity, you could operate a DPDT relay to switch the battery terminals around. You will need some cunning with this method. When the relay switches and the polarity is correct the relay will switch back again! One way would be to put the polarity sensing before the relay contacts and the voltage using/measuring circuit after the relay.

Or measure the voltage with a microcontroller and use the abs() function.

#### dl324

Joined Mar 30, 2015
12,826
What does automatically mean? Is there some mechanism that loads the batteries? What is measuring the voltage?

#### CuatroMan

Joined Nov 25, 2018
13
Alternatively, having detected the polarity, you could operate a DPDT relay to switch the battery terminals around. You will need some cunning with this method. When the relay switches and the polarity is correct the relay will switch back again! One way would be to put the polarity sensing before the relay contacts and the voltage using/measuring circuit after the relay.
Thank you AlbertHall! A relay seems like an elegant solution.
Am I on the right track with this schematic?

Or measure the voltage with a microcontroller and use the abs() function.
I'm not familiar with the "abs" function but looking into it now.

Thank you!

#### CuatroMan

Joined Nov 25, 2018
13
What does automatically mean? Is there some mechanism that loads the batteries? What is measuring the voltage?
Thank you DL324. Currently just using a gravity method (ramp) and an arduino to measure the individual voltages.

#### AlbertHall

Joined Jun 4, 2014
11,240
Thank you AlbertHall! A relay seems like an elegant solution.
Am I on the right track with this schematic?

I'm not familiar with the "abs" function but looking into it now.

Thank you!
Yes, that will do the job.

abs() is a function in 'C' on the Arduino. It returns the absolute magnitude of a value.
abs(2)=2
abs(-3)=3
and so on.

#### dl324

Joined Mar 30, 2015
12,826
Thank you DL324. Currently just using a gravity method (ramp) and an arduino to measure the individual voltages.
If the ADC range doesn't allow reading negative voltages, you could use an absolute value circuit. Or use some method to insure proper orientation.

#### AlbertHall

Joined Jun 4, 2014
11,240
If you connect the batteries to the Arduino with a circuit as below then you can directly read the cell voltage without worrying about the polarity.
The two resistors give a point at half the supply voltage and the cell voltage will add or subtract from that, giving you 1V or 4V. For accuracy the Arduino can also measure the mid point voltage then find the difference between the two voltages and use the abs(function to get the cell voltage regardless of orientation.

#### crutschow

Joined Mar 14, 2008
27,029
If you need to actually reverse the battery polarity for you testing, below is the LTspice simulation of a circuit using a relay, as Albert suggested.
It uses a comparator to switch a DPDT relay so that the output test voltage (yellow trace) always has the A voltage positive with respect to the B voltage, as the input test battery (Vtest) (blue trace) changes polarity.
The relay turns on (green trace) when the voltage is more positive that about 148mV.
With no input connected, the relay is off.

#### ian field

Joined Oct 27, 2012
6,539
You could connect the battery via a bridge rectifier so the polarity would always be correct but you will lose some of the voltage in the diode drops.

Alternatively, having detected the polarity, you could operate a DPDT relay to switch the battery terminals around. You will need some cunning with this method. When the relay switches and the polarity is correct the relay will switch back again! One way would be to put the polarity sensing before the relay contacts and the voltage using/measuring circuit after the relay.

Or measure the voltage with a microcontroller and use the abs() function.
If you can spare 1.4V out of 1.5...……………..

#### ian field

Joined Oct 27, 2012
6,539
Hi friends,

I'm hoping for a bit of help with a challenge I'm faced with solving.

I have a project that aims to "automatically" sort AA batteries by remaining voltage/capacity.
I believe I have a handle on the voltage sorting portion, yet the physical orientation of the batteries is tripping me up.

With a voltage reading of a positive number or negative number, I can determine if the battery is oriented incorrectly.
Yet, I'd like to find a circuit solution to possibly switch the negative and positive leads so the batteries polarity is correct and functions like a properly oriented battery.

I'm hoping this explanation makes sense -- I'm a lifelong newbie.

Thanks for any help!
There's a way to rig a MOSFET so the body diode would conduct if there was enough voltage, but it also enhances the channel so you pretty much get RDSon - but I doubt you have the voltage to do that.

Many "smart" chargers have a comparator to check the polarity of any battery applied. Its high impedance stuff that isn't damaged by reverse polarity, but a correct polarity of sufficient voltage flips the comparator - that activates a relay to complete the main current path.

The downside is, it requires a power source to work.

#### CuatroMan

Joined Nov 25, 2018
13
If you can spare 1.4V out of 1.5...……………..
Thanks Ian. Am I loosing that much voltage by using a relay and HIGH/LOW from micro?

#### CuatroMan

Joined Nov 25, 2018
13
If you need to actually reverse the battery polarity for you testing, below is the LTspice simulation of a circuit using a relay, as Albert suggested.
It uses a comparator to switch a DPDT relay so that the output test voltage (yellow trace) always has the A voltage positive with respect to the B voltage, as the input test battery (Vtest) (blue trace) changes polarity.
The relay turns on (green trace) when the voltage is more positive that about 148mV.
With no input connected, the relay is off.

View attachment 170117
Thank you for this! Very helpful!

#### CuatroMan

Joined Nov 25, 2018
13
abs() is a function in 'C' on the Arduino. It returns the absolute magnitude of a value.
abs(2)=2
abs(-3)=3
and so on.
Excellent explanation! Thank you!

#### djsfantasi

Joined Apr 11, 2010
7,641
Since you’re already reading the voltages with an Arduino, IMHO, AlbertHall’s suggestion in Post #8 is the simplest and best solution. Look at it again.

#### CuatroMan

Joined Nov 25, 2018
13
I'm so impressed and grateful for everyones quick responses and suggestions to help.
I truly appreciate everyone taking time out to help.

Off to the bench!

#### BobaMosfet

Joined Jul 1, 2009
1,664
If voltages are not large, I'd use transistors instead of relays. Faster, no spark issue (so safe anywhere), no snubber needed, and no time delays due to EM field charge/discharge time.

#### CuatroMan

Joined Nov 25, 2018
13
If voltages are not large, I'd use transistors instead of relays. Faster, no spark issue (so safe anywhere), no snubber needed, and no time delays due to EM field charge/discharge time.
Thank you. I'm measuring individual AA batteries. Would the diode drop be an issue with transistor?

#### BobaMosfet

Joined Jul 1, 2009
1,664
Thank you. I'm measuring individual AA batteries. Would the diode drop be an issue with transistor?
Unlike a BJT, a MOSFet does not have a diode drop. Instead the Source->Drain voltage drops much less, as if a low-value resistor is between them. You can look at the datasheet to determine it's value (RDS(on)) and calculate the voltage value across it by the current going through it, and readd that to your end value.

#### crutschow

Joined Mar 14, 2008
27,029
Would the diode drop be an issue with transistor?
You could use a MOSFET which has no diode drop, but it does have an ON resistance.