Battery monitor and Relay Control with Arduino

Sometimes, especially if you have a DIY solar power system, you need to monitor the battery voltage. You can do this easily with an Arduino and some other stuff.

For this project, i used:
An Arduino Pro Mini clone (~$4 from DX. You need the USB to TTL Serial Adapter to program it.)
1 x 12VDC Relay
1 x BC547 transistor
2 x 1.5K resistor
1 x 1n4148 or 1n4144 diode
1 x 5VDC USB Car Charger

Arduino checks the battery, according to the settings you made to “volts” datatype. You can use any other resistor you have, but you must check the battery with a multimeter and then make the needed changes to calculate the correct ratio. Use the serial port to check the value, so you can know what voltage it reads.

When the voltage drops below a level you want, in this example under 10.5V, then the Arduino triggers the Relay and you can do anything (i use the relay to connect to the power wallet, until the battery is fully loaded and then the relay closes).

Use the below code, to program your Arduino. To connect a relay on Arduino, view the below image.


/*
Arduino Battery Monitor.
Controls the Relay.
Prints the voltage to the serial port.
*/

int batteryPin = 0; // +V from battery is connected to analog pin 0
int outputPin = 2; //The pin to control the Relay

void setup()
{
pinMode(outputPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
// read the value from the battery
int val = analogRead(batteryPin);

// calculate the ratio, use a multimeter.
float volts = (val * 3.05) ;
//Use it to watch the Volts and make the changes.

Serial.println(volts);

if (volts < 1050) { //Turns on the Relay analogWrite(outputPin, HIGH); digitalWrite(Relay, HIGH); } else { //Relay is Off analogWrite(outputPin, LOW); digitalWrite(Relay, LOW); } }

Leave a Reply