Οδηγοί/Tutorials

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

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);
  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);
    }
} //loop

3 Responses

  • steven

    5 years ago

    hello,

  • Kraken

    5 years ago

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

  • Kraken

    5 years ago

    --

Add Comment

You might also like

How to play Nintendo Switch games on your Android phone

How to convert your old speakers to bluetooth

How to Install Windows 10 on a Raspberry PI 3

Categories