Hi, welcome to another video tutorial from Robojax. in this video we are
going to see how we can use the sharp infrared distance measurement module you
see the ruler is here and it shows the distance around as you can see here 16
centimeter I am a 16 centimeter and you can see on the screen it shows 16
centimeter between the distance that I have where if I put my hand it will show
a different value you can get the code for this module by clicking at the link
of the description which will take you to www.robojax.com/learn/arduino
let's get started with this so I'm now on sharp website if you
scroll down there's two type digital output which we are not using we are
using the analog one the digital has Letter D in between with some numbers which
reflects the distance this is for five centimeter for example this is for 10
centimeter so that's 05 after the 8 refers to the distance so that is
10 centimeter as you can see here this is 15 here is the one that we need the
analog one so this is 1.5 to 15 centimeter this is to 2-15 to 2:30
and the one that I'm using is this one a A41SK which measures from 4 to 30
centimeter and also we have higher versions which goes from 180 to 182 from
20-250cm this is the model that if you are looking for. and the other one and they
are offered at different physical shapes they are all the same except the shape
and the model reflect different type for different application some of the maps
cable some of them will be installed on the PCB so the length for this page will
be provided at the link that you follow from the description and also the
data sheets will be provided separately so you can download all of those.
This is the datasheet of the module that I'm using it says 4 to 30 centimeters
as you can see here so you have to understand that this is not precise in
terms of millimeters so this has some issues with it so the application is for
cleaning robots for personnel and sanitary so not for precision devices.
here is the voltage the operating voltage is between 4.5V to 5.5V
which were using 5 volts that would be fine. and the amount of the
current that it dissipates typical is 12 milli ampair and the maximum is 22 milli
ampere. of course this has been measured at the condition that the distance was
around 30 centimeter so this chart is very important so the module actually
outputs the voltage with relation to the distance as the distance increases the
voltage that outputs will be decreased so this is the voltage on the y axis on
the x axis we have the distance in centimeter as you can see at 2 centimeter
it outputs 2.2V and here is the maximum is at around 3.5 centimeter which
will produce around 3.3V 01 or something like that
we volt and as the distance increases we go to 5, 6 and up to this distance
for 30 centimeter we get around 0.4 volts this shape is not a regular
one to do it so that's why the library will be used but if you want to enter
this into Excel and then find the equation of this plot then you don't
need a library and you can calculate it to eliminate the errors
the author of the code has offered the mean value which means they measured
multiple values and then get the mean or average of it
Hardware Explained
so the module is very compact here the module has transmitter and receiver
infrared transmitter and receiver here and we have three wires so the red is
connected to 5V the black is connected to the ground GND
this yellow is the output and this is a servo type connection so you can plug in
any maile wire here two connect it. so the total
length of this is 44.5mm millimeter depth of it is 13.3mm
three millimeter and this here we have so many parameters at this level with a
screw set at 33.9mm millimeter here we have twenty nine
point four millimeters
Downloading the library
with the ring key that you download directly from our website or go to get
GitHub and then when once you are in this page just click here and download
zip , save it wherever you want I'm saving it in download here
I really have it so once you download it this is a file so right click you select
the 7-zip or any other tool that you have and extract here so it will create
a folder with the same name without the dot zip so here is a it will create a
folder like this if I open it you will see all the files out here shortIR.h
sharpIR.cpp so these are a must with these two other files in order
to make it work but once you are done here. right click copy it and then go and
find your dinner installation folder which would be C:\\program files somewhere
in my case it here so once you go with you on your Arduino you will see a
directory structure like this go to the library and right click and paste it
Code explained
after that we go to the loop which starts on and here inside the loop this
is a delay the author of the code suggests that we should have a value of
2,000 millisecond or two seconds but you can experiment with this depending on
your application depending on the type of the module depending on the distance
that you use you can change this to see which value is suitable for you so we
can reduce the time if you need to measure faster but two seconds is very
slow and I'm going to show you that we if we remove this style we can get a
pretty precise measurement. then here we just get the current time in millisecond
and store it in a start time this is for calculating the measurement time so you
can remove it if you don't need it and then SHARPIR that IR this object that we
created object then this is a method that gets the value so that this whole
thing is the distance that we measure but here we don't want to print it we
just want to store it and the DIS variable as an integer it doesn't have
any decimal point so you'll get effects for five three or something and then
serial parentis printing a text here this serial print will print this DIS
this is printing the distance for us which we need now then we go again get
the current time from the time that we started the measurement and from here
some time has passed so we subtract the start time which was here so we subtract
it and we call that INtime and then we'll put this text and then print the
INTime here on the screen so this way we know how many millisecond it took to
do this calculation because the start is here and in this here and between that
distance have been measures and then the loop continues like that
Project Demonstration
let's measure seven centimeter so the seven centimeter is exactly seven 6 is
exactly 6 as you can read so now the code is running as you can see here this
is a 22 centimeters I am a 22 centimeter and also on the screen that you see that
we are getting 22 centimeter let's go at 33 this is around 7 centimeters error so
let's go back to 20 so our 20 we are getting 21 so 20 and below is good let's
go 15 so at 15 we are getting 15 as you can see here this is precise at the
lower values and a higher value and has some errors but if the error is
consistent add some extra factor of addition or subtraction from the value
so you can get a precise measurement thank you for watching this was
introduction to the Sharp Infrared distance measurement module I have
another video using this 1602 display where I to see which has only four
cables please tumble the video please share the
roster subscribe I appreciate it
Suttiel typed and correct on April 26, 2020 by Ahmad Shamshiri in Ajax, Ontario, Canada
I did my part to help you learn. Now it is your turn. Thumb up the video please.
This will not cost you anything. Subscribe to my channel and keep the ads watching and do not skip.