Lukas Thorwald Hey
Created July 3, 2020 © GPL3+

Universal IR remote Receiver

Sketch to use a KY-022 + Arduino Mega for receiving data sent from an universal IR remote

IntermediateWork in progress12 hours1
Universal IR remote Receiver

Things used in this project

Hardware components

Universal IR Remote
×1
Arduino Mega 2560 & Genuino Mega 2560
Arduino Mega 2560 & Genuino Mega 2560
×1
KY-022 IR Sensor
×1
In-Line Adapter, RJ45
In-Line Adapter, RJ45
×1
Cat 5 Cable
Amount is length in meters for the prototype
×1
Modular Connector, RJ45 Plug
Modular Connector, RJ45 Plug
×2
Through Hole Resistor, 1 kohm
Through Hole Resistor, 1 kohm
×3
General Purpose Transistor NPN
General Purpose Transistor NPN
×3
Perf+ 2
Crowd Supply Perf+ 2
×1
6-pin Header & Gender Changer (5-pack)
Digilent 6-pin Header & Gender Changer (5-pack)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Code

Arduino Mega Sketch

Arduino
This utilizes pin 11 to receive from the KY-022 sensor, 10 to 8 is PTT/UP/DOWN
#include <IRremote.h>
#include <IRremoteInt.h>
 
// Here we have....
int RECV_PIN = 11;  // Data input pin for the ky-022
int DOWN_PIN = 8;   // Data output pin for the NPN transistor shorting DOWN to GND
int PTT_PIN  = 10;  // Data output pin for the NPN transistor shorting PTT to GND
int UP_PIN   = 9;   // Data output pin for the NPN transistor shorting UP to GND
// Arduino-IRremote Library Initialisation
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // IR-receiver start
  Serial.println("IR-Receiver started\n");
  // I set all pins to LOW for safety reasons
  digitalWrite(PTT_PIN, LOW);
  digitalWrite(UP_PIN, LOW);
  digitalWrite(DOWN_PIN, LOW);
  Serial.println("All output pins set to LOW\n");
}
 
// Main program
void loop() {
   
  // Check for received signals
  // Note: The 'delay' is just a placeholder for what your rig wants to recognize
  // shorting the transistors as keypress ;-)
  if (irrecv.decode(&results)) {
    switch (results.value) {
    case 0xFFE21D:
        Serial.println("PTT ON\n");
        digitalWrite(PTT_PIN, HIGH);
    break;
    case 0xFFA25D:
        Serial.println("PTT OFF\n");
        digitalWrite(PTT_PIN, LOW);
    break;
    case 0xFF22DD:
       Serial.println("DOWN\n");
       digitalWrite(DOWN_PIN, HIGH);
       delay(250);
       digitalWrite(DOWN_PIN, LOW);
    break;
    case 0xFF02FD:
       Serial.println("UP\n");
       digitalWrite(UP_PIN, HIGH);
       delay(250);
       digitalWrite(UP_PIN, LOW);
    break;
    default:
       Serial.println("Ignoring this one:\t");
       Serial.println(results.value, HEX);
    break;
    }
    irrecv.resume(); 
  }
}

Credits

Lukas Thorwald Hey

Lukas Thorwald Hey

0 projects • 1 follower

Comments