in this lesson we are going to learn how to control this smart car with our hand when
your hand moves to the left it turns to the left your hand moves to the right it turns
to the right and also at certain distance if you put it in front of it follows your hand
if it is around 500 meters you see seven centimeters going forward
and if we have only in one of them it goes to the right and I bring my hand to the left foreign
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 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 is a project page if you come to core projects it's number seven follow your hand
we already know everything about this wiring is already done so we are using infrared sensors and
ultrasonic sensors the wiring everything have been explained in previous lessons we are just going to
jump into code and demonstration now let's open the project click on file open go inside that
three in one cut Main and then click on core project go number seven click on number seven
follow your hand click and open and here is a code let me explain it this is the same exactly as
before defined four pins for the car these two are for one motor these are for the other motor these
two are for left and right infrared sensor these are for the ultrasonic for pin ping and Trigger
and then I've defined this as extra I've defined here of a variable called moving
so initially it's false and then we are defining the serial monitor here this is again we are
defining the pins as an output for motor and these are for obstacle avoidance this was missing I have
taken this from the code for Ultrasonic sensor so Echo and Peng pin one is as input the other is as
an output they have been defined here inside the loop we are reading the distance using read sensor
data this is exact code from the previous lesson and these are also the same code from infrared
where we get the distance using this function and using these two we are getting the left and right
detection of obstacle if it is abstracted if the hand is there we will read zero otherwise it will
be empty and this is the speed we have defined and her I have changed the code here because
the code had some issue it was not working so this portion is exactly the same we check if the
distance is greater than 5 and less than 10 which means between 5 and 10 then we move forward with
the speed passing is passing it to this function which you have seen it in the speed or controlling
the chord lesson and then we say else stop which means if it's not between 5 and 10 centimeter
stop even it's short or to stop if it is long stop now the car is stopped if no hand is there
now here this was part of the code but I've removed something from the bottom if there
is an obstacle or the hand is there because this means there is nothing
and if you put this it means there is something so if there is an obstacle then turn left because
the right is nothing and there is something on the left so we turn left to the speed if on the left
side there is nothing and there is an obstacle or hand on the right side then we turn right
and also this was missing in the code like in the previous ultrasonic code if you don't add this 100
millisecond delay you will not be able to measure the distance because the sensor needs some time at
least 100 milliseconds to measure so this is the exact code as before we don't need to even explain
it because I have already explained this you must watch that video This is for forward backward turn
right and turn left in each function I have added the text for example for desktop it prints on the
serial monitor stop for the left it turns left for the turn right it press right and for backward it
turns reverse and for forward and here I've added these two lines to print the distance
the code demonstration as you can see it shows the distance around 36 centimeters
and because the object is 36 centimeter away it's not doing anything now right now
so let me put my hand here as soon as you see that the distance is 8 centimeter between
5 and 10 at forward so this is supposed to go now forward and if I remove it will stop if I
go if I have my hand is on the left side it goes on the left and stop it goes to
the left and stop and if it is and our fickle is on the right it goes to the right and stops
now
so, I'm holding it up it doesn't move and if I bring my hand in here
let me bring my hand from the bottom if it is around 5 Centimeters you see seven centimeter it's
going forward and if we have only in one of them it goes to the right and also it shows here right
now if I bring my hand to the left, you see it is left and then stop
and at the same time if it is less than this it will stop
listen 5 centimeter and as soon as it's above more than five it will go forward
and now here is the demonstration I will put my hand from the top so you can see it and
as soon as it detects my hand it follows
but if my hand is too far it's not doing anything as soon as it reaches less than between two to
ten centimeter it follows but if I bring my hand here and the left goes right Okay so
fiber left if I go right, it follows the hand
if I go to the right it goes to the right because this sensor is detecting my hand
if I put my hand go forward it follows so as you can see it's working as expected
foreign
[Music]