Arduino Projects

12v Battery Efficiency Monitoring using Arduino and Cell App with Database

Description:

 

Battery Efficiency Monitoring- In this tutorial, you will learn how to monitor the efficiency of a 12v Battery using Arduino, 0 to 25v voltage sensor, HC-05 Bluetooth Module, RTC DS3231 Real Time Clock and an Android cell Phone. The Battery voltage information is stored in the Arduino at regular intervals which can be defined in the Programming. Then using the Android Cell Phone the stored information can be requested wirelessly by sending a command to the Arduino. The received information is stored in the Cell Phone database along with the Date and Time information. The information stored in the database can be used for post-analysis. More sensors can be connected with the Arduino. Currently, I am using only the Voltage sensor for demonstration purposes.


This project is entirely based on my previous Tutorial based on the wireless battery voltage monitoring system. In this project, I used the same 0 to 25-volt voltage sensor and the same HC-05 Bluetooth module. In this project, I didn’t use any database and as you can there is no date and time information. For the best understanding watch, this tutorial and then you can resume from here.

In Today’s tutorial, we will cover.

  1. RTC DS3231 Real Time Clock Pinout
  2. 0-25 Voltage Sensor Pinout
  3. HC-05 Bluetooth Module Pinout
  4. Complete Circuit Diagram of the battery efficiency monitoring system
  5. Programming explanation and finally
  6. Testing

Without any further delay, let’s get started.



Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

RTC DS3231 Real Time Clock:

Voltage sensor 0-25v:

Bluetooth Module: Hc-05:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


RTC DS3231 Real Time Clock:

Battery Efficiency

This is the RTC DS3231 module. The RTC stands for Real-Time Clock. You might be thinking why we need the RTC DS3231 module when the Arduino itself has the built-in timekeeper. Arduino is really powerful and we can make a real-time clock, but the problem comes in when the Arduino is turned off, or the power is disconnected, the time and date information is completely lost.

Battery Efficiency

But if you look at the RTC DS3231 module it has a battery and can keep track of the Time and Date information even if the main power supply is disconnected or we reprogram the microcontroller. For the best understanding read article on the RTC DS3231 given in the related projects section.

RTC DS3231 Features:

The RTC DS3231is a low-cost, highly accurate Real Time Clock, which can maintain hours, minutes, and seconds. This module can also maintain the day, month and year information. The RTC DS3231 module also has automatic compensation for leap years and for months with fewer than 31 days.

This Module can be powered up using 3.3 volts or 5 volts.


As you can see clearly in the picture above, the DS3231 module has a total of 6 male headers and are clearly labeled. Out of these 6 Pins, we will be using only 4 Pins which are the SCL, SDA, VCC, and GND.

0-25v Voltage Sensor used in Battery Efficiency Monitoring System:

This is 0 to 25v voltage sensor, which I will use for measuring the Battery voltage. This module is capable of measuring the voltages ranging from 0.02445v to 25volts dc. As you can see on one side we have a block terminal, this is where we connect the voltage and ground wires coming from a battery. The Voltage wire is connected with the VCC terminal and the ground is connected with the GND terminal.

On the other side, we have three male headers labeled as +, s and -.

The S pin of the sensor module is connected with the analog pin of the Arduino or mega and the – the pin is connected with the ground of the Arduino. While the + pin is not connected.



If you want to learn how to modify this sensor to measure higher voltages greater than 200 volts then watch my tutorial.

HC-05 or HC-05 Bluetooth Module:

This is the HC-05 Bluetooth module, as you can see I have already connected some jumper wires so that it can be easily interfaced with the Arduino. It has a total of six male headers clearly labeled with

State

RXD

TXD

GND

VCC and

EN

Out of these six pins we will be using only RXD, TXD, GND, and VCC.

For the extreme basics like for example, changing the name of the Bluetooth module, Pairing Code, and how to use the AT commands watch my video tutorial.


Now let’s have a look at the complete circuit diagram.

Battery Efficiency Monitoring Circuit Diagram:

Battery Efficiency

This is the complete circuit diagram of the 12v Battery Efficiency monitoring system. As you can see on the left side, the voltage sensor Vcc is connected with the Battery 12v input and the ground of the voltage sensor is connected with ground of battery. The S pin of the voltage sensor is connected with the analog pin A1 of the Arduino and the “ – “ pin is connected with the Arduino’s ground. While the + pin is not connected.

The HC-05 or HC-06 Bluetooth module VCC pin is connected with the Arduino’s  5 volts, the Ground pin of the Bluetooth module is connected with ground of the Arduino. The TXD pin of the module is connected with pin2 of the Arduino and RXD pin of the Bluetooth module is connected with pin3 of the Arduino.  The Bluetooth module communicates with the Arduino through serial communication, as you know in Arduino we have only one serial port available on pin0 and pin1. We will use the Arduino’s default serial port for the debugging purpose and make another serial port using pin2 and pin3. I will explain this in programming how to make a serial port.


The RTC DS3231 Module GND pin is connected with the Arduino’s Ground. The VCC pin is connected with the Arduino’s 5 volts. The SDA pin is connected with the Arduino’s Analog pin A4 while the SCL pin is connected with the Arduino’s Analog pin A5.

Interfacing:

Battery Efficiency

All the components are interfaced as per the circuit diagram as explained above.

Download the apk file: battery Effciency App

The android application source code is available at the lowest price: 50 Dollars. If you need the Source code, send me an email on

stu_engineering@yahoo.com

Or contact via my Whatsapp number:

+923339218213

12v Battery Efficiency Monitoring Arduino Programming:

This Program is the combination of all the three programs used in my previous three tutorials, given above. For more information, you can read the articles given in the related projects section.

#include <stdlib.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include “RTClib.h”

SoftwareSerial blue(2,3); // bluetooth module connected here

String cmessage; // complete message
int flag = 0;
float correctionfactor = 0;
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;

// two resistors 30K and 7.5k ohm
float R1 = 30000; //
float R2 = 7500; //
int value = 0;

String Bvoltage; // Battery Voltage
char buff2[10];

// for RTC

RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”};
char db[50][40];
int Day;
int Month;
int Year;
int Secs;
int Minutes;
int Hours;

String dofweek; // day of week

String myDate;
String myTime;

// keep track of time
int cmins = 0; // current minutes
int pmins = 0; // previous minutes

int delay_in_minutes = 1; // original value 59

// messages to Android application, that will be stored in the database.
String message1;
String message2;
String message3;
String message4;
String message5;
String message6;
String message7;
String message8;
String message9;
String message10;
String message11;
String message12;
String message13;
String message14;
String message15;
String message16;
String message17;
String message18;
String message19;
String message20;
String message21;
String message22;
String message23;
String message24;

int counter = 1;

int cflag1 = 0;
int cflag2 = 0;
int cflag3 = 0;
int cflag4 = 0;
int cflag5 = 0;
int cflag6 = 0;
int cflag7 = 0;
int cflag8 = 0;
int cflag9 = 0;
int cflag10 = 0;
int cflag11 = 0;
int cflag12 = 0;
int cflag13 = 0;
int cflag14 = 0;
int cflag15 = 0;
int cflag16 = 0;
int cflag17 = 0;
int cflag18 = 0;
int cflag19 = 0;
int cflag20 = 0;
int cflag21 = 0;
int cflag22 = 0;
int cflag23 = 0;
int cflag24 = 0;

int data;
void setup(){

pinMode(analogInput, INPUT);
Serial.begin(9600);
blue.begin(9600);

if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}

if (rtc.lostPower()) {
Serial.println(“RTC lost power, lets set the time!”);

// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));

// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// rtc.adjust(DateTime(2019, 7, 19, 14, 46, 0));
}

}
void loop(){

while(blue.available()==0)
{
battery_voltage();
delay(500);
date_time();
delay(500);
cmessage = cmessage + “B_Voltage:” + Bvoltage + ” “+ myDate + ” ” + myTime;
//Serial.println(cmessage);
track_t();
delay(1000);
Bvoltage = “”;
myTime = “”;
myDate = “”;
cmessage = “”;
}
// command from Bluetooth

if(blue.available()>0)
{
data = blue.parseInt();
delay(200);
}

if (data == 1)
{

blue.println(message1);
delay(500);
blue.println(message2);
delay(500);
blue.println(message3);
delay(500);
blue.println(message4);
delay(500);
blue.println(message5);
delay(500);
blue.println(message6);
delay(500);
blue.println(message7);
delay(500);
blue.println(message8);
delay(500);
blue.println(message9);
delay(500);
blue.println(message10);
delay(500);
blue.println(message11);
delay(500);
blue.println(message12);
delay(500);
blue.println(message13);
delay(500);
blue.println(message14);
delay(500);
blue.println(message15);
delay(500);
blue.println(message16);
delay(500);
blue.println(message17);
delay(500);
blue.println(message18);
delay(500);
blue.println(message19);
delay(500);
blue.println(message20);
delay(500);
blue.println(message21);
delay(500);
blue.println(message22);
delay(500);
blue.println(message23);
delay(500);
blue.println(message24);
delay(500);

data = 2;
Bvoltage = “”;
myTime = “”;
myDate = “”;
cmessage = “”;
}

}

void battery_voltage()
{
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1023.0; // see text
vin = vout / (R2/(R1+R2));

vin = vin – correctionfactor;
Bvoltage = dtostrf(vin, 4, 2, buff2); //4 is mininum width, 6 is precision

//blue.print(“Battery Voltage: “);
//blue.println(vin);

}

void date_time()
{

DateTime now = rtc.now();

Day = now.day();
Month = now.month();
Year = now.year();
Secs = now.second();
Hours = now.hour();
Minutes = now.minute();
dofweek = daysOfTheWeek[now.dayOfTheWeek()];

myDate = myDate + dofweek + “:” + Day + “/” + Month + “/” + Year ;
myTime = myTime + Hours +”:”+ Minutes +”:” + Secs ;

//Serial.println(myTime);
}

void track_t() // track time
{

if ( flag == 0)
{
pmins = Minutes + delay_in_minutes;
flag = 1;
}

if ( Minutes == 0)
{
pmins = Minutes + delay_in_minutes;
}
cmins = Minutes;

if ( cmins == pmins )
{

pmins = Minutes + delay_in_minutes;
counter = counter + 1;
}

if ( (counter == 1)&& (cflag1 == 0) )
{
cflag1 = 1;
message1 = message1 + cmessage;
cmessage = “”;
}

if ( (counter == 2)&& (cflag2 == 0) )
{
cflag2 = 1;
message2 = message2 + cmessage;
cmessage = “”;
}

if ( (counter == 3)&& (cflag3 == 0) )
{
cflag3 = 1;
message3 = message3 + cmessage;
cmessage = “”;
}

if ( (counter == 4)&& (cflag4 == 0) )
{
cflag4 = 1;
message4 = message4 + cmessage;
cmessage = “”;
}

if ( (counter == 5)&& (cflag5 == 0) )
{
cflag5 = 1;
message5 = message5 + cmessage;
cmessage = “”;
}

if ( (counter == 6)&& (cflag6 == 0) )
{
cflag6 = 1;
message6 = message6 + cmessage;
cmessage = “”;
}

if ( (counter == 7)&& (cflag7 == 0) )
{
cflag7 = 1;
message7 = message7 + cmessage;
cmessage = “”;
}

if ( (counter == 8)&& (cflag8 == 0) )
{
cflag8 = 1;
message8 = message8 + cmessage;
cmessage = “”;
}

if ( (counter == 9)&& (cflag9 == 0) )
{
cflag9 = 1;
message9 = message9 + cmessage;
cmessage = “”;
}

if ( (counter == 10)&& (cflag10 == 0) )
{
cflag10 = 1;
message10 = message10 + cmessage;
cmessage = “”;
}

if ( (counter == 11)&& (cflag11 == 0) )
{
cflag11 = 1;
message11 = message11 + cmessage;
cmessage = “”;
}

if ( (counter == 12)&& (cflag12 == 0) )
{
cflag12 = 1;
message12 = message12 + cmessage;
cmessage = “”;
}

if ( (counter == 13)&& (cflag13 == 0) )
{
cflag13 = 1;
message13 = message13 + cmessage;
cmessage = “”;
}

if ( (counter == 14)&& (cflag14 == 0) )
{
cflag14 = 1;
message14 = message14 + cmessage;
cmessage = “”;
}

if ( (counter == 15)&& (cflag15 == 0) )
{
cflag15 = 1;
message15 = message15 + cmessage;
cmessage = “”;
}

if ( (counter == 16)&& (cflag16 == 0) )
{
cflag16 = 1;
message16 = message16 + cmessage;
cmessage = “”;
}

if ( (counter == 17)&& (cflag17 == 0) )
{
cflag17 = 1;
message17 = message17 + cmessage;
cmessage = “”;
}

if ( (counter == 18)&& (cflag18 == 0) )
{
cflag18 = 1;
message18 = message18 + cmessage;
cmessage = “”;
}

if ( (counter == 19)&& (cflag19 == 0) )
{
cflag19 = 1;
message19 = message19 + cmessage;
cmessage = “”;
}

if ( (counter == 20)&& (cflag20 == 0) )
{
cflag20 = 1;
message20 = message20 + cmessage;
cmessage = “”;
}

if ( (counter == 21)&& (cflag21 == 0) )
{
cflag21 = 1;
message21 = message21 + cmessage;
cmessage = “”;
}

if ( (counter == 22)&& (cflag22 == 0) )
{
cflag22 = 1;
message22 = message22 + cmessage;
cmessage = “”;
}

if ( (counter == 23)&& (cflag23 == 0) )
{
cflag23 = 1;
message23 = message23 + cmessage;
cmessage = “”;
}

if ( (counter == 24)&& (cflag24 == 0) )
{
cflag24 = 1;
message24 = message24 + cmessage;
cmessage = “”;
counter = 0;
cflag1 = 0;
cflag2 = 0;
cflag3 = 0;
cflag4 = 0;
cflag5 = 0;
cflag6 = 0;
cflag7 = 0;
cflag8 = 0;
cflag9 = 0;
cflag10 = 0;
cflag11 = 0;
cflag12 = 0;
cflag13 = 0;
cflag14 = 0;
cflag15 = 0;
cflag16 = 0;
cflag17 = 0;
cflag18 = 0;
cflag19 = 0;
cflag20 = 0;
cflag21 = 0;
cflag22 = 0;
cflag23 = 0;
cflag24 = 0;

}

Serial.println(cmins);
Serial.println(pmins);
Serial.println(counter);
}

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

2 Comments

  1. Hello,
    I was doing the same project and I watched your details in YouTube. These multiple codes did not work for me. Can you please fix the code or send the right code. 12v Battery Efficiency Monitoring using Arduino and Cell App with Database.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button