Vaibhav Rekhate
Published © MIT

Generating Remote Control Signals Using Induino R3

Can we make our dumb equipments smart by controlling them all with one device?

BeginnerFull instructions provided2 hours834
Generating Remote Control Signals Using Induino R3

Things used in this project

Hardware components

Induino R3
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Termite

Story

Read more

Code

Receiver Code

C/C++
Code print protocol and control code received by TSOP receiver.
/*
 * Code to print protocol and control code received by TSOP receiver.
 * 25/12/2016, Vaibhav Rekhate
 * https://vaibhavblogsite.wordpress.com/
 */

#include <IRremote.h>

#define IR_RECV_PIN 15

IRrecv irRecv(IR_RECV_PIN);

decode_results rxPkt;

void setup()
{
  // Set baudrate to 9600
  Serial.begin(9600);
  // Enable IR Receiver
  irRecv.enableIRIn();
}

void printControlCode(decode_results *rxPkt) {
  int count = rxPkt->rawlen;
  bool valid = true;
  switch(rxPkt->decode_type) {
    case NEC:
      Serial.println("NEC Protocol");
      break;
    case SONY:
      Serial.println("SONY Protocol");
      break;
    case RC5:
      Serial.println("RC5 Protocol");
      break;
    case RC6:
      Serial.println("RC6 Protocol");
      break;
    case UNKNOWN:
    default:
      Serial.println("Unknown protocol");
      valid = false;
      break;
  }
  if (valid) {
    Serial.print("Control Code: ");
    Serial.println(rxPkt->value, HEX);
    Serial.print("Control Code Length: ");
    Serial.print(rxPkt->bits, DEC);
    Serial.println(" bits");
  }
}

void loop() {
  if (irRecv.decode(&rxPkt)) {
    printControlCode(&rxPkt);
    // Resume reception
    irRecv.resume();
  }
}

Transmitter Code

C/C++
Code to transmit using NEC protocol. Control code (32-bit) taken from serial input
/*
 * Code to transmit using the NEC protocol the control code taken
 * as input from serial port.
 * 25/12/2016, Vaibhav Rekhate
 * https://vaibhavblogsite.wordpress.com/
 */

#include <IRremote.h>

IRsend irSend;

void setup()
{
  // Set baudrate to 9600
  Serial.begin(9600);
}

void loop() {
  long upperCode = 0, lowerCode = 0;
  if(Serial.available() > 0) // if Serial data is received
  {
    upperCode = ((long) Serial.read()) << 8;
    delay(50);
    upperCode |= ((long) Serial.read() & 0xff);
    delay(50);

    lowerCode = ((long) Serial.read()) << 8;
    delay(50);
    lowerCode |= ((long) Serial.read() & 0xff);

    // Print code to verify input is correct
    Serial.print("Entered code: "); // print the current value
    Serial.println(((upperCode << 16) | lowerCode), HEX);

    // Send control code in NEC protocol
    irSend.sendNEC(((upperCode << 16) | lowerCode), 32);
    delay(100);

    // Flush buffer before starting over
    Serial.flush();
  }
}

Credits

Vaibhav Rekhate

Vaibhav Rekhate

1 project • 3 followers
Tech Enthusiast, Have built a satellite ;)

Comments