In the previous post, we have talk about how to measure distance using Ultrasonic sensor. Now you are at the moderate class robotics knowledge. It’s time to make some advanced project. In this post we are going to talk about how to receive signals from IR remote using IR receiver using Arduino. Let’s get started.
Basic explanation.
What is IR?
IR stands for Infrared Rays. Infrared’s wave length is
between 780nm to 1µm in the spectrum. IR is used to communicate shortly, like
changing channels in TV. You can see IR rays using your phone camera. Just turn
on the phone camera and press the button of IR remote. You can see a purple
color light transmitting from the IR remote.
What is spectrum?
Here is Electromagnetic Spectrum Image.
Spectrum is electromagnetic wave list. Visible light is
about 0.4µm to 0.7 µm. So, according to this electromagnetic spectrum, you
can’t see IR rays in your eyes.
Pin out and Circuit diagram.
This IR Receiver has 3 pins. Two of them are VCC and GND as
before projects. You have to connect VCC to 5V and GND to Arduino’s GND. Then
last pin is signal pin. I have connected it to 11th pin of Arduino.
Below is the pinout of IR receiver.
Below is the circuit diagram.
Getting signals from IR remote.
In this code’s beginning we have to include IRremote
library. You already know how to include libraries to Arduino. If you don’t
know, go to this page and learn it. After including the library, I have created
integer variable named decval. It’s for saving decoded IR signal. Then I created
object for our pin. It means 11th pin is named as “SoftEXS” you can
use any name here. Then I created another object named “results” for making
decoded results.
Inside the void setup, I have set the serial monitor’s baud
rate to 9600. Second line of the void setup says “ready to get inputs” to IR
receiver.
Inside the void loop, I have put if condition to get reading
only if there is a signal. So, it only gets readings if you press any button.
Without if condition, it’s printing zeros every time. Inside the if condition, I
have assigned decoded signal to “decval” variable. Then in the next line, I created
the output from serial monitor and in the last line of if condition, I put a
command that says “ready for getting your next value”. Then I added 100
milliseconds delay to make the code smoother and that it.
Assign values to IR decoded signals.
You saw the outputs of this IR remote. They are not actual
values. They are long numbers. So, you have to convert them to numbers. To do
that, you have to create if function. Here is the code. You can understand this
now.
If you have any question regarding to this, please comment
below. We are here to help you. Share this website among your friends. Stay safe,
good bye.