Sunday 17 May 2015

Arduino Lesson 14 : Interfacing IR sensor with Arduino UNO

Intro to topic :

When we talk about communicating with arduino boards there are many many possibilities either by using buttons,keypads. sensors.shields or wireless mediums. The simplest wireless medium is to use IR sensors with arduino. So here is the tutorial how to use them with arduino.

Hardware required :

  1. Arduino UNO board.
  2. IR sensor TSOP 1738
  3. Connecting wires/Jumper wires.
  4. PC to configure arduino board (with arduino software installed).
  5. Bread board.



Explanation to Circuit :

As i have shown you the fritzing image the IR sensor TSOP1738 has three pins out of which two pins are used to power it up from 5v and ground and the third pin whenever recieves any IR signal on it produces on TTL signal or produces on hex value related to signal incident on it. So this trick can be used to detect the hex codes related to any button of IR sender or  IR based remote like TV remote.




Steps to follow :


  1. Connect the Circuit according to schematic image on bread board.
  2. Power up the IC by applying it the 5v and ground.
  3. Connect the 5v and groung connections correctly and make sure they are connected to right numbered pins.
  4. Once connected correctly connect arduino to PC.
  5. open up the Arduino IDE in PC and upload the following code.



Code to be uploaded :

#include <IRremote.h>
#define irPin 2
IRrecv irrecv(irPin);
decode_results results;

void setup()
{
   Serial.begin(9600);
   irrecv.enableIRIn();
}

void loop()
{
   if (irrecv.decode(&results))
      {
      Serial.print("0x");
      Serial.println(results.value, HEX);
      delay(250);
      irrecv.resume();
      }
}




Once you uploaded the Code open up your serial monitor in Arduino IDE and take any IR remote in your home and come in front of your circuit and press any button in front of it and see the  magic. As you press any key your key code will be decoded and HEX equivalent will be shown up in serial monitor. So this shows that you have used this IC correctly and these codes can be further used in different projects like automation of devices with TV remotes.




If you have any more things to ask let it be in comments i will try to more explain it.

No comments:

Post a Comment