and this lesson we are going to use infrared transmitter or
remote and infrared receiver to detect when the key is pressed,
we can take action or turn on a buzzer, so we detect the signal from remote
and we are going to learn how to take action when a button is pressed for example power turn off on
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 a code that you can download a link
to purchase the kit and documentation is below the video in the description
in this lesson we're going to use this infrared receiver where we will transmit some code using
this transmitter and the transmitter is located in here so this will release the infrared which
we cannot see but this sensor can see it and we will detect which key is pressed
the first thing we do is there is a battery installed here and
when I remove it the battery is now activated
to check the battery, we just need to push this piece just push this the other side and then this
can be removed here this is the battery and the battery is cr2025 this is a three-volt battery
this plastic was just blocking it from usage so the battery would last longer,
and this is the code under more syntax 511
.2 and here 511 and then 511.2 is infrared receiver we have an infrared receiver that has
power supply 5 volts ground, and the left pin is the receiver or the signal that we receive
and here this is the wiring it's very simple from the right it goes
to 5 volts the metal to ground and the left pin we are connecting it to pin 11.
and here the receiver has a bump here make sure it's facing you
from the right this goes to 5 volts the middle pin goes to ground
and the left pin which is signal it goes to pin 11 in this code
now first lessons let's install the library by for remote click
on sketch include Library manage libraries
on this screen type IR or emote I IR remote just wait few seconds and here you will see IR remote
click install wait for the installation to complete and close
now to open the code click on file open three in one kit and then learning project
and 511 IR and select 511 IR and open it
and here is the code if you pay attention this is the first time that you see another tab
so in this tab we have a series of decode values certain value for each for example uh we have
this value each value is corresponding to something plus minus 9
U cycle play part so these are the codes that we are receiving from remote but here
we have included the library in this line and we have defined pin 11 as receive pin
and then from this re IR receive IR remote we create the receive pin and pass the receive
pin and that the code result will be available in here inside the setup we are initializing
the serial Monitor and this and then you using the object that we created in here
we enable we use enable irn so we can start receiving inside the loop this function is getting
the uh the code and this result is passed as an object this result is from the uh the code result
so this decode result is also part of this Library we create a an object called result and we pass it
to this function which decodes F the result is okay then we use the decode value we get the
result the value from there and result dot value we pass it and if we don't get error then that's
our value will be printed if we don't get the code equal to error otherwise it has something useful
and then it says resume so this decode value is a function which is in the same folder if
and here if we go to learning projects and 5.11 you will see that we have this file
decoderkeyvalue.uno so we have two files
this is automatically included because it's in the same folder so this will read it for us
let me upload the code now I've opened the serial monitor so here is the remote as you can see,
we read some function some text let me show you it says the function
decode and result is deprecated you may not it may not work as expected
just use decode without parameter and inferior decoder
will receive it with a field name so deprecated if it doesn't work use it like that but don't
worry it's working so here, I'm pressing let's say power and as you can see, we have decoded power
let me correct this mute
play pause this is what backward forward minus plus 0 and then equalizer
cycle or repeat
and here is the code that I've written to take action when a key is pressed first,
we have defined a buzzer pin pen two
and inside the setup we are defining using pin mode the buzzer pin as output so this must be
inside setup and inside the loop head is what we take action this is a portion that I have added
this will have the value and I use that in here and I said if this value is == power
if the power key is pressed then digital using digital right the buzzer pin should
be high so the buzzer which is connected to that buzzer pin 2 will be turned on else
if it is not if the value is something else then turn it off or set it low as simple as that
and here I've added this buzzer the right pin is long I've connected it using red wire from
positive to pin 2 and the left pin depends the other side has been connected to ground
now let's open the serial monitor serial monitor is open here and here is my buzzer let me
press one or other Keys as you can see it says mute now let's press power
so, buzzer is running if I press again,
it will not change because it's the same value you have to do something else
power or other button
perfectly working
this is Ultimate infrared project for Arduino we're going to learn how to detect any remote
using Arduino so we can take action when you press a key to do something then we
are going to use Arduino as a transmitter or as a remote so we can turn on and off a
TV or other devices that needs infrared next project we are going to control an
AC bulb or a relay so you can control AC bulb or DC bulb or load whatever you have
next project we are going to cut like this when I press it rotates now right
stop it and then rotate it left and final project would be to control a Servo motor using infrared