Hi, welcome tonight doing a tutorial for Robojax.
my name is a Ahmad Shamshiri. in this tutorial we are going to learn learn how
to use this sharp infrared distance meter to measure the distance and
display it on an LCD 2004 as inch or centimeter or under 1602 LCD with I
Square C which has only four wires .you can get the code for this by clicking at
the link below the video in the description which will take you to the
www.Robojax.com/learn/arduino let's get started with tis.
I've separate video explaining this sharp infrared sensor and a full detail
and explanation the video the link for the video is below this video I'm not
going to explain it so in this video we are going to just measure the distance
and displayed either on this LCD 2004 which has which has twenty characters
and four lines or on this LCD 1602 which has sixteen characters and two
lines both of these are based on I squared C. this is I2C module which
needs only four wires remember the old version used to have all these wires but
we use this module and we use only four wires and the same way for this as well.
Wiring Explained
let me now explain the wiring for this LCD for these two they are exactly the
same on this on the left side this is ground ground is connected to the ground
of Arduino the second pin is VCC which is connected to five volts and then we
have SDA in the orange from here it is connected to A4 and SCL pin the
yellow is connected to A5. the same connections are valid for this and
you can also connect to SDA and SCL at this point. and for this Sharp sensor the
it needs five volts so the 5 volts pin the red is connected to pin 2 where we
defined it as extra 5 volts in the code and the middle pin is ground ground is
connected using black wires to second ground here and then the white pin is a
data out which is here and it has been connected to A0. if you want to
learn Arduino I have a best seller course on udemy where you can learn or
do know from ground up with hundreds of projects all course material library
codes wiring diagram everything available in one place the link for my
Arduino course is below this video in the description.
Code explained
let me now explain the code you need to install the library for the LCD I will
provide you the link you will save it as a zip file after that click on Sketch->
include library and then->Add dot zip library and then browse to where you
have saved it in this case I'll give you an example if it was saved inside
download and tutorial and if this was the downloaded library select the zip that you
have download it and click open it will be installed. we are defining a VCC for
the distance sensors this is a extra VCC VCCPin have defined here pin 2. and
because I've defined the code such that you can use multiple devices and this is
an array and this is the pin that is the sensor is connected to if you have a
second one as I've explained in the introduction code you can put A1, A2
and so forth. but if you have two elements here make sure to type here 2
and if you have had one this must be one otherwise you will get errors. this
average is 50 and we get the average distance of 50 measurements and this is
your microcontroller voltage if if it is 3.3 volt this type here 3.3 this line is
the address for I2C module for this module this has I2C
address so you have to get the address I will give you the code for I2C
scanners copy and paste it and run the code so this is the code
do not worry what is inside this code so run this code and upload it and once
it's uploaded and your annual screen is connected then open the serial monitor
and here when it runs make sure on this side it must be on the right lower side
9600 9600 and this will print the address 0 x mean
hexadecimal and 3f is the address and as you can see I've written it here so I
don't forget and I don't need to run the I2C scanner. closes it . this 16 is number
of characters 2 is number of lines and that is referring to the 16
character and here to means to line and if you have this 2004 then it has 20
characters here and four lines so you will enter that and here inside a single
quote type capital C for centimeter and capital "I" for inch and this is the text
you see here on the screen so if you want to customize of the other language
just put that here and here. there is a how you use it.
readDistance 0 if you have sensor one sensor just put 0 if you have a second
sensor put 1 and uncomment this and the same way if you have more just put this
with changing the number one two three or so and so forth so this will read it for you.
must have a this with the distance and this is printing it so if you want to
print this one and wait for some seconds and then print the second one if you
have multiple senses you can do that as well
and if you want to take some action based on the distance for example if the
distance for sensor 0 is greater than 8.5 you want to do something put your
action inside this code.and this is also printing it on the serial monitor here
as well.
Demonstration
and here is the demonstration. let me tape this hair so it doesn't move and here is a
distance sensor and as you can see we are reading eleven point one three and
if I go further changes and if I bring it closer
it shows the distance and for different sizes this sensor can measure up to 14
centimeter from two centimeter to 14 and this is now showing an centimeter now I
have dating it two inch so and now it shows the same distance an inch.
and have now I've uploaded to this larger LCD and as you can see it shows
inch if I turn the light off you can see it better.
I would like to thank my Patrons from Patreon.com
Subtitle typed and corrected by Ahmad Shamshiri in Canada on July 17, 2020
I did my part to help you learn. Now it's your turn.
You can subscribe to my channel, thumb up 👍 the video and say "thank you" in the comment section.
The link to my PayPal account is below this video if you want to send me chase donation. Thank you.
thank you for watching a tutorial from Robo Jax if you learned something and
found it useful please thumb up 👍 as this will help my video in the search
algorithm of YouTube. if you have comment our question please post a comment
section below I try to answer a reply. and to get updates of my upcoming videos
make sure to subscribe.
Related Videos
in this tutorial we're going to learn how we can use this VL 53 l1x 4 meter
laser distance sensor to display the distance on an LCD monitor besides a LCD
with I2C module so now that the value of set is in millimeter