in this lesson we are going to use infrared remote control to control
this car we're going to learn how to send the core forward backwards turn right turn left
or move to the right or move to the left and also increase and decrease the speed
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 lesson requires that you have watched the introduction to infrared so you have watched
Accord One Core 2 to control the speed of the car and assembly in this lesson now we
are going to control our core using infrared remote control in our introduction to infrared
remote control we learned how to detect the keys that is pressed on the remote control and
take action we saw how to turn on a buzzer when a specific key was pressed the button
is pressed for example power turn off on now this is the time to detect each key to control the car
here is a documentation page for this lesson if you go to Sun founder documentation page
for this project click on core projects and come down number nine it says remote control
and there is full explanation a wiring diagram components that are used the code
and here it has been explained which key does what and how it works it has been explained
and here is the remote control when we press the keys we are using just these two keys when you
are pressing it ignore the rest just this positive and negative so when you press a positive it will
add the speed and when you press the negative it will reduce it every time with a step of 50
and here are these Keys have arranged like a joystick so you can go forward backward and move
to the right turn to the right turn to the left this is not going to the right it's just turn
turning right turning left and if you press these keys in between this key for example it goes uh
forward and right so the wheels will rotate so this goes forward left and
then left backwards and then right backwards if you press these keys
now let me explain the wiring as I explained it in previous lessons these are this is our
positive and this is our negative we have done the wiring please watch that video
first we are getting a wire from pin 13 using this orange wire as shown here just get from pin 13
and connected somewhere on the breadboard that's our pin 13 and then get a 330 Ohm resistor for Led
and connect it somewhere doesn't matter now get your led the longer
pin connected to the pin where the resistor is connected and the other one on this side
now this side negative is not connected we are going to connect it to the negative
to the ground so our LED our LED is ready now pay attention to this infrared receiver
we are going to connect it the way it is shown on the diagram the bump on this side
so the make sure that the flat side is forward so let's insert it somewhere on the board
first let's connect the positive from our breadboard wherever you might connect it
to you might have connected to anywhere so we will connect it to the right side
I think get a black wire connected to the middle and connect it to this ground or negative
the last one will go from the left pin the last pin goes to pin 11 the
same way that we did for the introduction lesson
and here pin 11. this blue
now let's open the project by clicking on file open go to where you have downloaded
the sun founder code click on three in one kit main go to core project
and number nine remote control click and then select the file that has nine in it remember
from the previous lesson this was the detecting Keys file that is attached to this main program
select and open it we already have explained this nothing has changed except this is the code for
the infrared remote we have already explained it pin 11 is defined for infrared receiver pin where
we receive the signal so that's the most important one to remember these four pins are for the motor
which already have explained it multiple times and there is a an LED when you press the key it will
blink the LED that is on the board itself and also we are going to connect external LED so it blinks
a little bigger perhaps and this is the speed of our car inside the setup we have defined a Serial
monitor with 9600 Baht inside and then we have defined four pin for the motor and this line is
it says I receiveEnableIRN so this is in it this enables the input and then infrared pin
input and this is a printing just the text on the serial monitor remote control start
and this is turned this line is setting the LED pin as output so we can control it
now inside the loop this is just receiving and decoding the signal that is received
so if the signal is detected or received then we get the value and the result whatever is resulted
it goes to this function the code key value and the result will be some number or something and
we check if it is not equal to error the code that I mentioned is here so it will return if
it receives this code the key 6 is pressed F key 7 is pressed we receive this code and we if the
power is pressed for example we receive this and if the speed is pressed plus we receive this code
so we receive some kind of code and here and here when we I forgot to mention that when we print
the key after that we go to LED blank this is a function at the bottom of the code which makes
the LED that is connected to pin 13 to blank the code will have the value here if the plus
is pressed if the key is equal plus then get the speed incremented by 50 which means add 50 to the
speed and if it is negative subtract 50 if it is 2 move forward with the speed and for one second
if it is 1 move left for one second and move left just rotate left if it is four turn left if it is
6 and so forth so all the keys and if it is 8 go backward and then for one second now because we
are incrementing the speed it's possible that we may go above 255 so here is the conditional
statement where we say F the speed is equal or greater than 255 if it will set maximum to 255 and
if the speed is less than 0 or equal then we set it to zero we will not allow negative because as
you press that button it will go below zero which is negative and then we have 500 millisecond delay
and then we stop and this is just I have added this text so we can see the speed and then this
line resumes the infrared and this was the F condition and then it this goes back to the loop
and these are the functions move forward move back which we have already seen it turn right
and left and move right move left so we had before we are turned right and turn left this was for one
motor this was for the other motor but this moves this is turning one motor for example
this goes to the left it just turns one motor on the right side and when the right rotates the
a core will go to the left because the left motor is stopped the same
way when you want to go to the right the right is stopped and the left is rotating
and here for back left just right is rotating backward and the chord goes to the left
and if you want to go to the right back is rotating the left is rotating
back right backwards so you're moving to the right
and led blank is here and here this is this function is for bringing the LED we have a
for Loop which starts from I equals 0 to Less Than 3 which is two so I become 0 we turn the
LED pin High using digital right and for 50 millisecond and then we turns it we turn it
off for 50 milliseconds and then it becomes one and then we do the same thing it becomes two we
do the same thing and it becomes three; three is not smaller than 3 from this condition at exits
and here I've opened the serial monitor the code is loaded let's see the functions if
I press positive you will see that the remote control has started and it shows the speed that
we have set this is the code that I have added so we know the speed remember it was default
150 when I added it increase the speed so if I go one more that was 250 but after that if
I press it goes to 255 and that's the maximum even if I press it 10 more times it will not
change because we have set it in the code to be limited now let's go to the negative and as
you can see the speed is being decreased we can slow it down but the color will not move it's
fully powered and here when I press any key as you can see the LED blanks let me turn the light off
every key I have disconnected the motor so it's not running two eight
now if I go to the right go to the left or decrease or increase it's blinking to
send it forward you press two backwards it and then turn right and left I'm pressing now two
and when I release my hand it will stop to
so it stops after about a second so we have to press and then press again
now to go backwards
and now let's see when we turn to the right what happens
you have to just press it once and it rotates now left turn left
so this was turned left now let's go forward right
as you can see only one is rotating now for the left this will rotate
and here when we go backwards we press this back right
you see this is rotating in Reverse so we go back right like this
now here is a demonstration the car doesn't have a power yet let's Power It Up
and I've disconnected this motor wire now it has power
and here is our remote by default when you turn it on it goes to 150 I believe so let's go forward
so it goes and stops
and let's go backwards
if you see the car is rotating a little not straight the reason for that is the
quality of each motor might be a little different or there is a tension when it
is installed so that causes the car to go a little not straight foreign
as you can see every time you press it rotates about 90 degrees 80 or 90 something like that so
now this is different one wheel stops let's go forward and right so I'm going forward and then
presses it doesn't work so you have to press only one key one keyword one function will work now
this is different rotation but this is different if I press this it just rotates around its axis
axis so here to understand it better let's see I'm going right so I just rotate around the axis
but if I press this this button see what happens
it moves and rotate so the axis will be the inner wheel let's go backwards
and let's go a little forward
[Music]