Loading...

Battery voltage indicator using Arduino - Arduino Geek



Hello everyone! Welcome to Arduino Geek. Today we will discuss about an Arduino based battery voltage indicator. So let's get started.

What is battery voltage indicator?

In this blog we are going to learn, how we can measure the potentiometer voltage and display it as a bar graph on LCD screen. There are times that you need to display level of something that is controlled by a knob. Let’s say the voltage current or maybe speed of a motor level of liquid or something that is controlled with the knob displaying with bar graph. Rather the number has advantage that it can be recognized easily from further distance and immediately.

Battery voltage indicator circuit –

You discover the magnitude so this project is about that I'm using the simple potentiometer here to display this. But if you have a voltage between 0 to 5, that represents some value you can connect it directly to Arduino to be displayed as bar graph. Now let me explain the wiring for this LCD screen either this module or this module because they have the famous I2C module. They’re exactly the same we have SCL and SDA VCC and ground SCL and SDA. We have an Arduino we have SEL we have SCL and SDA also, and FC is a 5 on Arduino Uno. You are using other devices (for example - you  know Ethernet is the a4 a5 is SCL Arduino mega  xx SDA is 21 is SCL and the rest there have  been all mentioned. I will provide you the link for this as well VCC using blue line of being connected to 5 volts and ground or GND have been connected using green to the ground of Arduino for this variable resistor or potentiometer). 

Battery level indicator with Arduino and LCD display –

We have three wires here these two wires will be connected one to ground one to five volts and  the middle one must be connected to one of the pin  that you define in our case you are using an A0. So we will be connected here make sure the middle pin goes here otherwise you when you rotate it. You can make a short circuit between ground and 5 volts and it will be bad because when it goes to the right it will goes to the maximum make sure the right one goes to the 5 volts. If you want to keep the convention. So I have another 5 volts here on my Arduino. You have to install them one by one the downloading this it will be one step file this will be another zip file save  it in your computer somewhere. Click on a sketch include library .zip library then pointed to where you’re safe that this is for example if you're on the desktop or my document wherever this is a file.

If you are using the other one if you are  using this one it will be 16 character by two 16 and this is 20 and then for line so you define  16 characters and then two line or 24th line and this is the sensors pin this is very correct. Your variable is the third potentiometer to the pin to the suspend 0. Take it to pin 0 after that you are creating from this instant instance of this class. We call it LCD and then this is the address 0x3F 0x means hexadecimal 3f is the address and then this column comes from this value and then the city car or character comes from here. Now to find this address you need to open I2C scanner the link will be provided so let me open a square see scanners you open it and then upload. You’ll see the LCD is connected upload this once upload done open the serial monitor and you will see that it will print the address whatever address you have. In my case it's 3f it continuously read and print that for you so this is the address after that we use the instance of LCD bar graph.

How do I monitor battery voltage with Arduino?

You can change it to something else as long as it's not resolved name and then inside this. We are passing this instance of the class this object whatever you type it must be the same and then column 0. This is where we start the bar graph this as we have stored the bar graph from line 0 this is line 1 from line 0 character 0. So this 0 that you see is referring to that and then inside the setup we initialize the LCD by typing a city dot began this initially. I think it's clearing the screen from previous value whatever it is and this text is printed  on the first line and then we go to character 0 line 1 in here character 0 line 1 this was line  0 and then we print voltage bar graph that you saw it just screen voltage bar graph. And then we give the viewer one second to read it and after that inside the loop just was the object that we created clear line and we clear the line this line will stay the same line. We don't need to refresh it because a class is taking care of it. But because this is our voltage we have to refresh as a voltage changes we have to be able to clear the previous value so we type LBG whatever name  you type here this was your object. And then clear line and one if you put line zero it will clear  line zero so line one is the one that we need it. And then we read the input pin using analog reads and serpent it reads pin 0 the pin and the value of whatever it is between C will be stored and  here the value that it reads is a digital value between 0 and 1,024. And will be stored here as integer and we call it input Val and then this is drawing the bar graph for us draw value and BG dot draw valued and then input value whatever value we have and we mentioned that  this has to be with respect to 1024 points. And it will fill up the screen you don't have to worry about it then we go for the next line here we get the input value multiplied by 5 because the maximum voltage that this car measure is 5 volts and number of steps between the 5 is from 0 to 1024 1023. It’s 1024 steps multiplied by this it will give us actual voltage that you read here three-point each one so the value the calculated value of  this is stored in a variable called voltage of type float then we move the cursor by using LCD  cursor line character 0 line 1. It means put the cursor in here and then we print the text called voltage this voltage is printed then we said the cursor at character 8 0 1 2 3 4 5 6 7 at 8 and line 1 which is this line we print the actual voltage that we have calculated. Then we go to character 12 after that that's 8 9 10 11 at 12. We print this V so it looks nice as a voltage and we will hundred millisecond the input as we change it. Let’s demonstrate it the TSA's Arduino Uno you can connect it to Arduino mega or any other. Or do we know that you have as long as you connect it properly. So I've said this up such that when I rotate this to the left which it goes completely disappears initial zero and the maximum which shows five volts it goes up to here only one line left here the rest is completed.

But in between any other value that you have it can show properly the voltage and it's responding very well. Now let's say you want to start the bar graph let’s say from character 8 to the end this was initially the number of columns because it is 16 we said we use the variable. But if you want to make it 8 character just take it and you can start from 8 now this is the length of the bar graph and this is a starting point and this is a line now you will see that. It has moved but 5 is there 2 and 1/2 somewhere at the middle. It will start from that point and the code works with this LCD 2004 exactly the same way.

 
close