Battery monitor and Relay Control with Arduino

Published on  by Gearloose ‐ In  ‐ Reading time: less than a minute
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've 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
Battery monitor and Relay Control with Arduino 1

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.

Battery monitor and Relay Control with Arduino 2
Arduino Battery Monitor.
Controls the Relay.
Prints the voltage to the serial port.

// +V from battery is connected to analog pin 0
int batteryPin = 0;

//The pin to control the Relay
int Relay = 2;

// This is to controll the onboard led. For testing purposes only.
int outputPin = 13;

void setup()
  pinMode(outputPin, OUTPUT);
    pinMode(Relay, OUTPUT);

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.


if (volts < 1050) {
//Turns on the Relay
analogWrite(outputPin, HIGH);
digitalWrite(Relay, HIGH);
} else 
    //Relay is Off
    analogWrite(outputPin, LOW);
    digitalWrite(Relay, LOW);
} //loop
Battery monitor and Relay Control with Arduino 3





Yeah, you are right. The relay is wrong here. I changed the code.



Related Posts

How to convert your old speakers to bluetooth
How to Install Windows 10 on a Raspberry PI 3
Gold Detector with Arduino