8th
JUN

Set up an IR Receiver on a Arduino

Posted by M. 4Gani under Electronici:

The IR signal is a series of IR light pulses which are modulate with a high frequency known as the carrier frequency.
The carrier frequency used by most transmitters is 38 kHz.
The IR receiver has a bandpass and filtered 38 kHz than demodulates the IR light signal, pre-amplifier and converts it to a binary signal.
Each button on the remote control generate a unique hexadecimal code.
This is the information that is modulated and sent over IR to the receiver.

Hardware requirements:

– Arduino board
– IR receiver. Such as the TSOP38238
– An IR remote such as you use for controlling your TV,

Connecting the IR receiver is very simple.
The IR Remote Receiver Electronic Brick has 3 pins. GND, VCC and Signal.

There are many different IR remote controls.
All of these may have different encoding methods and number of physical buttons, and different codes received when a button is pressed.

The best way to find the key codes for your remote control you can upload this code to your Arduino and open the serial monitor.

Below an example Software Sketches for a few common IR Remotes.
You press a key on your remote and the program print the hexadecimal code.

Decoding IR Data

#include "IRremote.h"
int receiver = 11;                   // pin 1 of IR receiver to Arduino digital pin 11

IRrecv irrecv(receiver);
decode_results results;

void setup() {
  Serial.begin(9600);
  Serial.println("IR Receiver Raw Data + Button Decode Test");
  irrecv.enableIRIn();               // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {    // have we received an IR signal?
    Serial.println(results.value, HEX);
    translateIR();
    irrecv.resume();                // receive the next value
  }
}

void translateIR() {                // takes action based on IR code received
  switch(results.value) {
    case 0xFF20DF: case 0x202C23D: Serial.println(" 0ff"); break;
    case 0xFFB04F: case 0x20238C7: Serial.println(" v+"); break;
    case 0xFF906F: case 0x202A857: Serial.println(" v-"); break;
    case 0xFF48B7: case 0x202B04F: Serial.println(" ok"); break;
    case 0xFFA857: case 0x202F807: Serial.println(" FORWARD"); break;
    case 0xFF08F7: case 0x20208F7: Serial.println(" LEFT"); break;
    case 0xFFC837: case 0x2028877: Serial.println(" RIGHT"); break;
    case 0xFF10EF: case 0x20220DF: Serial.println(" 4"); break;
    case 0xFF38C7: case 0x202A05F: Serial.println(" 5"); break;
    case 0xFF5AA5: case 0x202609F: Serial.println(" 6"); break;
    case 0xFF30CF: case 0x202807F: Serial.println(" 1"); break;
    case 0xFF18E7: case 0x20240BF: Serial.println(" 2"); break;
    case 0xFF7A85: case 0x202C03F: Serial.println(" 3"); break;
    case 0xFF42BD: case 0x202E01F: Serial.println(" 7"); break;
    case 0xFF4AB5: case 0x20210EF: Serial.println(" 8"); break;
    case 0xFF52AD: case 0x202906F: Serial.println(" 9"); break;
    case 0xFFC23D: case 0x20200FF: Serial.println(" 0"); break;
    default:  Serial.println("-> other button  <-");
  }
  delay(500);
} 

Post your comment

*

code