Battery monitor and Relay Control with Arduino

Lisa Scholfield
Written by Gearloose

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 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.

// +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

About the author



Welcome to my blog. My name is Akis Mparekas. I am a freelance web developer from Greece and I have been involved in SEO, Website Migration (transferring content from a site, eg blogger to WordPress), website optimization, and web scraping (extracting content from one or more sites) for years.

At the same time I am taking my first steps in game development (unity) and animation (blender). I also create cool stuff, either for work or for fun. When I have time, I write tutorials and I blog.