Top Ad Slot (728x90)

Breaking

This is basic example of marquee The direction of text will be from bottom to top.

Monday, 23 March 2015

Arduino - TSOP - IR Receiver Interfacing- How To?

TSOP - IR Receiver

The TSOP SM0038 is an IR receiver.  The TSOP will help you to interface your TV remote with the Arduino and in the Process learn the basics of Wireless Communication. 


The TSOP outputs a constant HIGH signal when idle and as it receives data, it tends to invert the data. i.e when an IR LED is transmitting data onto the TSOP, everytime the IR led goes high, the TSOP will go LOW and vice versa. Remote control signals are often bytes of data that is encoded and transmitted by pulsing(switching ON & OFF the IR LED at a specific frequency) Most TV remote controls work at 32-40 Khz frequency and most receivers can receive this range. 

Heres a link to a nice write up on different remote control protocols. lets first take a look how the Sony Remote Control Protocol Works. We stick to Sony as it is the easiest one to get started with. Read this before proceeding 

Here's a basic outline of how the data is sent. Every time you press a button on a Sony remote control, it sends out a 13Bit data. The first bit is a start bit indicating there are 12 bits of data following it. The next 7 bits are the command bit which will vary depending upon the keys being pressed. The last 5 bits are the address bits which will the same for all buttons but vary for remote controls of different devices.

The black bars in the following image correspond to high signals (called marks) and the white spaces in between correspond to low signals (called spaces). The duration of the 'marks' varies according to the bit being transmitted. It is 2.4ms for the start bit, 1.2ms for HIGH bit and 0.6ms for LOW bit. The duration of the 'spaces' is a constant 0.6ms. Every mark is followed by a space. Any data can be converted to binary format and transmitted in this manner. In fact this is the basic form of all types of serial communication.
 







Technique to decode this signal train, would be to constantly monitor the TSOP pin[Digital 15] for its normal state and the moment it produces a low signal, measure the duration of the low signal. If the measured duration of the low signal is around 2ms then measure and store the duration for the next 12 bits of the incoming data. After storing the data, evaluate the duration and based on the duration convert the data to decimal / hexadecimal and use it in your application








EASY PROGRAM JUST COPY IT DUMP TO YOUR AURDUINO

#include <IRremote.h>

int RECV_PIN = 12;

IRrecv irrecv(RECV_PIN);

decode_results results;
int remote = 0;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    remote = results.value;
    Serial.println(remote);
    irrecv.resume(); // Receive the next value
  }
}

Now get your remote and make note of the values you get for pressing various buttons.

Now lets try to display the remote button value on the LCD. [LCD_TSOP.ino]
/*
The following program uses the IRremote library and displays the value of the 
button being pressed on the LCD
*/

#include <IRremote.h>
#include <LiquidCrystal.h>
/*
List of Values corresponding to numbers of the remote being pressed, 
remember to replace these values with the values you get.
1 16
2 2064
3 1040
4 3088
5 528
6 2576
7 2960
8 3600
9 272
0 2320
*/
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);

int RECV_PIN = 12;

IRrecv irrecv(RECV_PIN);

decode_results results;
int remote = 0, display_value=0;


void setup()
{
  lcd.begin(16,2);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    remote = results.value;
    switch(remote)
    {
      case 16 : display_value=1; break;
      case 2064 : display_value=2; break;
      case 1040 : display_value=3; break;
      case 3088 : display_value=4; break;
      case 528 : display_value=5; break;
      case 2576 : display_value=6; break;
      case 2960 : display_value=7; break;
      case 3600 : display_value=8; break;
      case 272 : display_value=9; break;
      case 2320 : display_value=0; break;
    }
    lcd.clear();
    lcd.print(display_value);
    irrecv.resume(); // Receive the next value
  }
}




1 comment:

  1. To realize the vale of 1 rupee ask the begger,

    To realize the value of 1 minute ask a person who missed the train,

    To realise the value of 1 second ask a person who just avoided an accident,

    To realise the value of 1 mark ask the person who failed,

    To realise the value of your 1 post ask us the "ba students",which could change our life !!

    ReplyDelete