hi welcome to our unit tutorial from Robo Jax in this video we are going to learn how
we can measure the potentiometer voltage and display it as a bar graph on LCD screen you
can get the code for this by clicking at the link below the video in the description which
will take you to robojax.com/learn/arduino let's get started with this
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 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 is the if a for 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 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 if you don't have 5
volts we will define extra 5 volts on one of the pin which I have separate video I will provide you
the link so you can define another pin as 5 volts and the other wire will be connected to the ground
I've spent quite some time working on a class working on the code making sure
it works with editing you didn't lose anything to hit the subscribe
button that's the least you can do for me thank you for subscribing
let me now explain the code you need to do is download the liquid crystal high score C library
the link will be provided you will download it as a zip file and also the link will be provided
for LCD bar graph Robo jacks 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 you point to that file and click open and that's
it with this for both of these after that you will have the example file you can open it by clicking
at the file examples and scroll down until you reach to our Robo Jack's here Robo jacks and see
the bar graph and open analog read which is this file and it starts from this point wire that H is
a file that is part of Arduino you don't have to do anything this you have just downloaded these
two these are two classes that are needed for this purpose here you define your LCD number of columns
as 16 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 Robo jacks and then we call it LBG 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 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 and it will start from that point
and the code works with this LCD 2004 exactly the same way right now we have
20 characters and at five volts it goes to have 20 characters thank you for watching I
hope you found this tutorial useful please thumb up the video if you have comment or
question posted a comment section below I try to answer and reply if you subscribe you
will get updates of my upcoming videos make sure to leave the notification on take care
you