IR Remote

Standard set for Arduino kits consists of simple remote and a small module with IR receiver (basically just TSOP38238 IR sensor + LED and resistor).

IRRemote

The connection and first steps of decoding the signal is based on Ken Shirriff’s blog and his IRemote library. The library is available at Github

See also how decoded key number can be displayed on LED display, and please note, that green LED on the picture is not used in the code below.The code translating received signals into normal numbers:

#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.print("Przycisk ");
    Serial.print(resultIR(results.value),DEC);
    Serial.print("  kod: ");
    Serial.println(results.value, HEX);
//    delay(50); if you keep receiving "button kept" response
    irrecv.resume(); // Receive the next value
  }
}

And (you can add this below or above the main code) my strightforward function to decode even a bit further (works directly also with my dashboard camera remote:

int resultIR(long reading){
 int result;
 switch (reading) {
  case 16738455:
   result = 1 ;
   break;
  case 16750695:
   result = 2 ;
   break;
  case 16756815:
   result = 3 ;
   break;
  case 16724175:
   result = 4 ;
   break;
  case 16718055:
   result = 5 ;
   break;
  case 16743045:
   result = 6 ;
   break;
  case 16716015:
   result = 7 ;
   break;
  case 16726215:
   result = 8 ;
   break;
  case 16734885:
   result = 9 ;
   break;
  case 16730805:
   result = 10 ; //przycisk 0 button 0
   break;
  case 16728765:
   result = 11 ; //gwiazdka asterix
   break;
  case 16732845:
   result = 12 ; //krzyżyk hash
   break;
  case 16736925:
   result = 14 ; //góra up
   break;
  case 16754775:
   result = 15 ; //dół down
   break;
  case 16720605:
   result = 16 ; //lewy left
   break;
  case 16761405:
   result = 17 ; //prawy right
   break;
  case 16712445:
   result = 18 ; //OK
   break;
  case 16753245:
   result = 19 ; //włącznik na pilocie kamery, ON-OFF on dashboard camera
   break;
  case 16769565:
   result = 21 ; //detekcja ruchu - kamera, movement detection on dashboard camera
   break;
  case 4294967295:
   result = 20 ; //przytrzymanie, hold
   break;
  default: 
   result = 13 ; //błąd lub nieznany przycisk, error or not listed above
 }
 return result;  
}

One thought on “IR Remote”

Leave a Reply