first, we learn how the line tracking Works after that I'm going to explain
the code and wiring and then we will test our core to see if it tracks a line
welcome to Arduino course by Robojax this course is based on SunFounder three in one Arduino kit
sold on Amazon everything that you learn in this course is included in this kit the course
comes with tons of components and projects all with instruction and video for a Smart car and
other projects that you can use for school or home automation you can purchase it from sunfounder.com
the kit also comes with full documentation code download learning projects with full
explanation wiring diagram and the code that you can download a link
to purchase the kit and documentation is below the video in the description
this lesson is about line tracking we are using this line tracking module which has
this infrared transmitter and receiver and we have in an operational amplifier that
the intensity of the received signal will be adjusted using this variable resistor
or potentiometer and the output signal is read where these one of the pin this can
operate with 5 volts and we are connecting it this infrared sensor is called TCR t500
and we have lm393 comparator or operational amplifier inside it
and here is a data sheet for that it can detect the distance between 1-8mm,
and focal length is 2.5 millimeters it can operate from 3.3 to 5 volts
and here is a project if you go to the project is 3.4 learning project
3 and then 3.4 and the module is mid the wiring is like this ground is connected to
ground V plus the middle wire is 5 volts and then the s or signal is connected to pin 2.
and as you can see signal is to pin 2 ground is to ground and a middle which is 5 volts will
be connected to 5 volts I've printed this sheet with these lines to practice the line is around
88 millimeters and it can be up to 1.25 or 12.5 millimeters so this is like eight millimeters and
we are going to run this over the line so how it works is if we are able to see one value on the
white area and other value on the black then we have been able to detect this on the core
on the Smart Core we will have a little space very little if I put a screwdriver this much
space will be between ground and the sensor so we have very little space and when you adjust it if
you see if I bring my hand you see the light is turning on and then turn off so that means that
adjustment is relatively correct then we will rotate this to find unit and we will adjust it
the best value that I got was in here so remember this this is not straight like around 10 degrees
or 15 degrees this line Looks like that so we are going to test it and read the value
and here is the actual wiring the left pin is connected using
orange wire to ground the metal pin is connected using yellow
wire to 5 volts and the right pin is signal which is connected to pin two
now let's open the project 3.4 go to file
open where you save the sun founder file three in one cat Main learning project and
scroll down until you see three four three dot four line detect the line
open that folder and click and open it so they have defined pin 2 as a gray scale pin that is
where the signal comes from the line tracker this is just defining the serial monitor inside the
setup with 9600 bot and we are getting that pin here using pin mode we are defining it as an input
and then inside the loop we are using digital read reading that pin 2 the result which is 0 or 1
is printed on the serial Monitor and we have 10
milliseconds the loop will continuously read either it will print 0 or print one
let me open the serial monitor here we are reading one now this is just
reading one if I if the object is there, we will see some reflection,
so this is not receiving any reflection this is as if it's on black line
as soon as I turn it around you see we are getting 0 and we have now I'm gonna pass the pin from here
so you know how much we are I'm not too far I'm just barely touching the pin now let me see and
then I'm bringing it on black as soon as I bring it on the black you see we are reading the value
I we are reading zero now I'm slowly bringing this on the line as soon as I bring it
you will see that we are reading one now this is on the line
exactly this is the point and then as soon as I go here it will be zero and then one
and zero so we can detect the line now this is a little thicker line it's 100 pixels wide
and let's see here now let me pass the pin so you know you know,
and I pass the pin it's zero it's reading so let me bring it and here
0 so if you are able to move this and then read the value either 0 1 on the line and then
zero outside one on the line and then zero outside then you're ready for the next project
and here to understand it better this black is our line and this is the position of our sensor if the
sensor is on the black area then then we see it with equal one zero and we move left so the core
moves left and it reaches in the white area and then as it reads white is zero and it says move
to the right and it reads black hair so black is equal one so it says one then it says move left
and in here now it reads white equal zero then it moves to the right so this way it
just moves left right left right with zero and one zero and one and it stays on the line
this is the page for the project if you go to the sun founder documentation page core projects then
go to number four Follow The Line this is the page where they have explained everything including the
wiring what is needed and then the adjustment and after that there is a code and after that
it has been explained and here is the line that I've used I'm using a ruler here to show you
it's exactly 25 millimeter or 2.5 centimeter for this test
now let's open the project click on file open go to the folder you where you downloaded three in
one kit Main and inside it car project and then number four Follow The Line select the file and
click open hello the code this portion is exactly the same as before this is for motor and the line
track is connected to pin two we're defining this variable for the line input and then setup this
is initializing the serial Monitor and these fours are four lines are for defining pins as
an output for the motor this is for motor one and this this pure for motor too just to remind you
and this line is to define the line track as input so we can read it now inside the
loop we are defining this speed as 150 remember the value is between 0 to 255
and then we use digital read and then read the line track and when it detects white area it will
be zero when it detects black that's one so that's very important like I explained it before the
value will be stored here and then I've added this line so this can print a so this is like holding
0 or 1 and then we are printing it using serial Monitor and then here we check using conditional
statement conditional statement F line color is this means this means if it is true or it is 1
then move left so it's just by random selection we are going to the left we could go also to
the right but here we just go to the left with the speed that we defined here else it means otherwise
it's white area then go to the right so it moves left right left right and this way the car stays
on the black line and here is the function controls the car to turn left so the right
motor is rotating and the left motor just stops so it turns left and we will and when we want it
to turn to the right the right is stopped the left is rotating forward so the car moves to the right
and here is a demonstration I've put the sensor directly on the this black line
and you see it says black and the car is sending command for the motors to for the
car to go to the left now because I've disconnected the motors it's not moving
let me just move it manually as soon as I go to the left it detects white and it says go
to the right now our vehicle is there it says it goes to the black again it says go to the
left and like that white black white black and as a result the car stays on the line
and here is the wiring I've connected orange red brown is that ground as you can see it is
connected to g red SV it's connected to 5 volts and then if this will be connected to pin 2.
if I turn this here if I turn this here as we saw in the previous lessons the red is
connected to the positive this is my positive which is connected to this 5 volts and this is
my negative which is connected using this blue wire to the ground so the brown wire
from the sensor is connected here so these two wires and so the Orange is connected to pin two
okay I've created this black path and here is our robot let's see if it follows the line so first,
I'm gonna put it on the line as you can see this is the sensor and the sensor must be on
the line first when you're initiating it so let me connect the power and let's see
as you can see the first Circle completed and can do it
[Music]
foreign [Music]