Guide to TSOP IR receiver

Guide to TSOP IR receiver

TSOP IR Receiver 

http://dmohankumar.files.wordpress.com/2011/12/tsop-1738.jpgTsop is an IR receiver which will help you to interface your TV remote with arduino.

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, every time 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. 

The SIRC protocol uses a pulse width encoding of the bits. The pulse representing a logical "1" is a 1.2ms long burst of the 40kHz carrier, while the burst width for a logical "0" is 0.6ms long. All bursts are separated by a 0.6ms long space interval.






Modulation


If you look at the image, you can see the the 1.2ms high of the Logical '1' has further black lines with spaces in between. These correspond to the ON/OFF cycles. The space between these is what is called the frequency. The frequency of occurrence of a ON/OFF cycle is what it means.

The black bars in the below 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.


 

SIRC Modulation










 

Protocol

SIRC Pulse Train

 LSB=least significant bit

MSB= Most significant bit

 

The picture above shows a typical pulse train of the SIRC protocol. With this protocol the LSB is transmitted first. The start burst is always 2.4ms wide, followed by a standard space of 0.6ms. Apart from signalling the start of a SIRC message this start burst is also used to adjust the gain of the IR receiver. Then the 7-bit Command is transmitted, followed by the 5-bit Device address. In this case Address 1 and Command 19 is transmitted.Commands are repeated every 45ms(measured from start to start) for as long as the key on the remote control is held down. 

 Please click here for more info --->http://www.sbprojects.com/knowledge/ir/sirc.php

 

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. 

Calculating the pulse.

The pulse of the transmiton can be calculated using the pulse in function --->  http://arduino.cc/en/Reference/pulseIn 


Here's the code, You can plug in the remote function into any of your programs, just remember to declare pin 15 as INPUT.

  void setup()  
 {  
  pinMode(15,INPUT); // TSOP is connected on the 15ht pin  
  Serial.begin(9600);  
 }  
 void loop()  
 {  
  int remote_val = remote();  
  if(remote_val>0)  
  {  
   Serial.println(remote_val);  
   delay(150); // A remote press will normally generate 3 signal trains. This is to avoid reading duplicates  
  }  
 }  
 int remote()  
 {  
  int value = 0;  
  int time = pulseIn(15,LOW);  
  if(time>2000) // Checking if the Start Bit has been received. Start Bit Duration is 2.4ms  
  {  
   for(int counter1=0;counter1<12;counter1++) // A loop to receive the next 12 bits  
   {  
    if(pulseIn(15,LOW)>1000) // checking the duration of each pulse, if it is a '1' then we use it in our binary to decimal conversion, '0's can be ignored.  
    {  
     value = value + (1<< counter1);// binary to decimail conversion. 1<< i is nothing but 2 raised to the power of i  
    }  
   }  
  }  
  return value;  
 }  



To remove all these complications, we can also use Ir remote library which can be downloaded at http://arcfn.com/files/IRremote.zip
IR wiring
Hardware connection Tsop (left)







 

The examples/IRrecvDemo sketch provides a simple example of how to receive codes: 

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

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

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

 

 

24 comments:

  1. Nice guide,
    Thank you!

    ReplyDelete
  2. The pinout in the picture at the top is wrong. If anyone connects the pins like that they fry the sensor.

    ReplyDelete
    Replies
    1. One of the problems with the IR-recievers is that they come with all possible pinout combinations. It's therefore important for the user to double check before connecting. Here's a couple of examples:
      http://arduino-info.wikispaces.com/file/view/IR-Receivers-900.jpg/473330184/800x225/IR-Receivers-900.jpg

      Delete
  3. there is a problem with the library . i just ran a example code , has the bug been fixed?? help.



    ReplyDelete
    Replies
    1. hy i have done a complete video tatorial on the arduino ir remote with all the hexadecimal coding and converting a tv remote to any remote in my youtube channel the link is given by ...."""" https://www.youtube.com/watch?v=tO2U0FoVHHM """

      Arduino IR Remote - Convert Any Old Remote Into A Useful Remote For Your Own Buttons
      https://www.youtube.com/watch?v=tO2U0FoVHHM

      Delete
  4. pulseIn logic should be HIGH not LOW, because we need to read HIGH Pulse not LOW

    ReplyDelete

  5. C:\Users\modaduguakhilkumar\Documents\Arduino\libraries\RobotIRremote\IRremoteTools.cpp:5: error: 'TKD2' was not declared in this scope
    I am getting this error please help me slove this

    ReplyDelete
  6. nice post,
    I was looking for Arduino's tutorial recently

    ReplyDelete
  7. 'TKD2' was not declared in this scope this type of error occur due existing Robot library in Arduino main library so for solve this type of issue first you remove it from your ardiuno library than install IRremote library the problem will be solved try it

    ReplyDelete
  8. Can anyone help me to write arduino code for 2 or 3 ir sensors. I have modified this above program but facing problem.
    Waiting for reply.
    Thanxs.

    ReplyDelete
    Replies
    1. hy guys i have done a complete video tatorial on the arduino ir remote with all the hexadecimal coding and converting a tv remote to any remote in my youtube channel the link is given by ...."""" https://www.youtube.com/watch?v=tO2U0FoVHHM """

      Arduino IR Remote - Convert Any Old Remote Into A Useful Remote For Your Own Buttons
      https://www.youtube.com/watch?v=tO2U0FoVHHM

      Delete
  9. HOW CAN ONE KNOW THAT A TSOP DEVICE IS BAD

    ReplyDelete
  10. i want to control 10 devices using PIC ic , through TV remote. Can you please send me the code for the same at abhishek1405949@gmail.com .thnx

    ReplyDelete
  11. hy guys i have done a complete video tatorial on the arduino ir remote with all the hexadecimal coding and converting a tv remote to any remote in my youtube channel the link is given by ...."""" https://www.youtube.com/watch?v=tO2U0FoVHHM """

    Arduino IR Remote - Convert Any Old Remote Into A Useful Remote For Your Own Buttons
    https://www.youtube.com/watch?v=tO2U0FoVHHM

    ReplyDelete
  12. Let me just commend you on your work here, as i think that you're doing a swell job. Its been particularly useful to me and i'd like you to continue with this. Thanks!

    ReplyDelete
  13. My tosp always sends me 1 when i read out of him. Although the irball lies behind the sensor. I just get 0 if the ball is shut down. Can you tell me why he always finds the ball although the sensor has just a range of 25° or how I can fix the problem.

    ReplyDelete
  14. I discovered your this post while looking for information about blog-related research ... It's a good post .. keep posting and updating information.spanish interpreter madison

    ReplyDelete
  15. https://mobilebaazar24.blogspot.com/2020/06/oppo-a9-mobile-price-in-bangladesh.html#more

    https://mobilebaazar24.blogspot.com/2020/06/xiaomi-redmi-9-mobile-price-in.html#more

    https://mobilebaazar24.blogspot.com/2020/06/samsung-galaxy-m31-mobile-price.html

    https://mobilebaazar24.blogspot.com/2020/05/vivo-v19-pro-mobile-price-in-bangladesh.html

    https://mobilebaazar24.blogspot.com/2020/06/oppo-a9-mobile-price-in-bangladesh.html

    ReplyDelete
  16. Can u help me to interface 2 sensor in arduino

    ReplyDelete
  17. 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. pakistani lawn suits with chiffon dupatta , 2 piece suit online shopping in pakistan 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.

    ReplyDelete