Go Down

### Topic: 12 Volt Lead Acid Battery Low Voltage Cutoff (Read 5290 times)previous topic - next topic

#### coolyyz321

##### Mar 12, 2017, 02:58 amLast Edit: Mar 12, 2017, 03:12 am by coolyyz321
I'm trying to make a Low Voltage Cutoff for my boombox with the Arduino. My needs for this is the Arduino to disconnect the battery at 11.6 volts. How would I do this, what would I need? I am new to the analog to digital business and need help for the value to put in the code for the digital value.

#### MorganS

#1
##### Mar 12, 2017, 03:03 am
You would need a voltage divider to convert the 0-14V (maximum) down to the 0-5V range that the Arduino can actually read.

You also need more details, like is the Arduino powered from the same battery?
"The problem is in the code you didn't post."

#### coolyyz321

#2
##### Mar 12, 2017, 03:24 am
The arduino will be powered by the same battery and I put the code with the first post that I made. I just need to know how to get the right digital value for the voltage out the divider going into arduino. How would I get the value? I'm new to the analog to digital.

#### jremington

#3
##### Mar 12, 2017, 04:36 amLast Edit: Mar 12, 2017, 04:40 am by jremington
Make an accurate voltage divider with precision resistors, and there is no need to calibrate it.

Otherwise, make a 3:1 divider with three 10K resistors (two in series to make 20K on top and one 10K in the bottom) and calibrate it with your multimeter.

It is not a good idea to power the Arduino with a "12 V" lead acid battery via the barrel jack, because the voltage can go well over 14 V during charging, and that is too high for the on board voltage regulator.

You can add a 7 to 9V regulator between the two.

#### coolyyz321

#4
##### Mar 12, 2017, 05:11 am
I got the divider working, what would the code be for this cutoff?

#### Robin2

#5
##### Mar 12, 2017, 10:24 am
What value is (or would be) returned by analogRead() when the battery voltage falls to 11.6v?

You can calculate that value by measuring the voltage with a multimeter when it is higher and noting the corresponding value from analogRead(). Do that measurement and tell us the values. Better still get two separate sets of values for two different battery voltages.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### jremington

#6
##### Mar 12, 2017, 04:39 pmLast Edit: Mar 12, 2017, 04:40 pm by jremington
Quote
what would the code be for this cutoff?
Post the code you have, with a wiring diagram (not Fritzing) and tell us how it misbehaves.

#### coolyyz321

#7
##### Mar 12, 2017, 05:15 pm
For 11.6 volts the value is 785,

#### coolyyz321

#8
##### Mar 12, 2017, 06:02 pm
// low voltage cut-off

#define RELAY 7
#define DIVIDER A0

void setup(){
pinMode(RELAY, OUTPUT);
pinMode(DIVIDER, INPUT);
}

void loop()
{

{
digitalWrite(RELAY, HIGH);
}
else
{
digitalWrite(RELAY, LOW);
}
}

Would this be the correct code for this?

#### Robin2

#9
##### Mar 12, 2017, 06:25 pm
That looks reasonable - assuming HIGH causes the relay to open.

Will opening the relay also cause power to the Arduino to be disconnected? If that happens what will the relay do?

On the other hand if the Arduino continues working do you really want it to reconnect the power a few seconds later?

Maybe you don't need the ELSE. Or maybe you should have a separate IF something like
Code: [Select]
`if (VoltageReading > 812) {   digitalWrite(RELAY, LOW)}`
which should turn it on if the voltage is above 12v

I am not suggesting you follow these comments slavishly - they are just here to prompt your thoughts.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### coolyyz321

#10
##### Mar 12, 2017, 07:14 pm
Could the relay be used on the power input if the arduino so when the threshold value gets hit, then the arduino and the boombox just shut off? Like the relay is a closed circuit when arduino is powered, then when the value is hit, then the relay would shut off everything. Mabye.

#### Robin2

#11
##### Mar 12, 2017, 08:22 pm
Could the relay be used on the power input if the arduino so when the threshold value gets hit, then the arduino and the boombox just shut off? Like the relay is a closed circuit when arduino is powered, then when the value is hit, then the relay would shut off everything. Mabye.
That is certainly possible. But you need a relay that requires power to hold it closed. The way your code is written
Code: [Select]
`if (VoltageReading <785)  {  digitalWrite(RELAY, HIGH);  }`
it looks like it is normally closed and that would not switch everything off.

If the relay does switch everything off you will need to hold the ON switch long enough for the Arduino to boot and take charge of the relay with a digitalWrite(make-relay-go-on) in setup()

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### coolyyz321

#12
##### Mar 12, 2017, 08:27 pm
I'm relatively new to coding, so how would i write this in the code?

#### Robin2

#13
##### Mar 12, 2017, 10:43 pm
I'm relatively new to coding, so how would i write this in the code?
I'm not sure what you are asking. You have all the parts in the code in Reply #8.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### coolyyz321

#14
##### Mar 13, 2017, 12:32 am
Wait, never mind, it was a stupid question, sorry.

Go Up