yt_link
insta_link
fb_link
twitter_link

Receiver code

Una publicación compartida de ELECTRONOOBS®️ (@electronoobs) el


Receiver IR remote - CODE


Help me by sharing this post





Download the .zip file below. Open it on your Arduino IDE and upload it to the Arduino and make sure you have the connections as in the schematic. Also, read all the comments in the code to understand more. You could also copy and paste the code from below.

Download receiver code:




This code is for the schematic.




/* Electronoobs IR receiver code. Read the AURT signal from the IR module
 *  Baud rate low: 300 bauds. se schematic below:
 *  http://www.electronoobs.com/eng_arduino_tut35_sch2.php*
 */

//I/O
int left_top = 2;
int left_mid = 3;
int left_bot = 4;
int right_top = 11;
int right_mid = 12;
int right_bot = 13;

//Received codes for each button. Make sure ar the same as in Tx code
byte LEFT_TOP_CODE = 0x04;
byte LEFT_MID_CODE = 0x08;
byte LEFT_BOT_CODE = 0x0C;
byte RIGHT_TOP_CODE = 0x10;
byte RIGHT_MID_CODE = 0x14;
byte RIGHT_BOT_CODE = 0x18;

//Digital write state of each LED; false = LED OFF
bool LEFT_TOP_STATE = false;
bool LEFT_MID_STATE = false;
bool LEFT_BOT_STATE = false;
bool RIGHT_TOP_STATE = false;
bool RIGHT_MID_STATE = false;
bool RIGHT_BOT_STATE = false;

//This is where we store the received byte
byte received = 0;

void setup() {
  Serial.begin(300); //Baud rate has to be low
  pinMode(left_top,OUTPUT);
  pinMode(left_mid,OUTPUT);
  pinMode(left_bot,OUTPUT);
  pinMode(right_top,OUTPUT);
  pinMode(right_mid,OUTPUT);
  pinMode(right_bot,OUTPUT);

  //Turn off all LEDs
  digitalWrite(left_top,LOW);
  digitalWrite(left_mid,LOW);
  digitalWrite(left_bot,LOW);
  digitalWrite(right_top,LOW);
  digitalWrite(right_mid,LOW);
  digitalWrite(right_bot,LOW);
}

void loop() {
  //If the serial is available and with a value > 0 we read the byte in
  if(Serial.available()>0)
  {
    received = Serial.read();    
    //Serial.println(received); //uncomment for debug

    //If the received byte is one of the codes, we change the LED state
    if(received == LEFT_TOP_CODE)
    {
      LEFT_TOP_STATE = !LEFT_TOP_STATE;
    }
    
    if(received == LEFT_MID_CODE)
    {
      LEFT_MID_STATE = !LEFT_MID_STATE;
    }
    
    if(received == LEFT_BOT_CODE)
    {
      LEFT_BOT_STATE = !LEFT_BOT_STATE;
    }
    
    if(received == RIGHT_TOP_CODE)
    {
      RIGHT_TOP_STATE = !RIGHT_TOP_STATE;
    }
    if(received == RIGHT_MID_CODE)
    {
      RIGHT_MID_STATE = !RIGHT_MID_STATE;
    }
    if(received == RIGHT_BOT_CODE)
    {
      RIGHT_BOT_STATE = !RIGHT_BOT_STATE;
    }

    //Turn on or off the LEDs depending on the states
    digitalWrite(left_top,LEFT_TOP_STATE);
    digitalWrite(left_mid,LEFT_MID_STATE);
    digitalWrite(left_bot,LEFT_BOT_STATE);
    digitalWrite(right_top,RIGHT_TOP_STATE);
    digitalWrite(right_mid,RIGHT_MID_STATE);
    digitalWrite(right_bot,RIGHT_BOT_STATE);    
  }
 

}


Arduino infrared receiver tutorial







ADVERTISERS
PCBWAY PCB Manufacturing

PCBWAY Christas PCB Manufacturing

Advanced PCB Manufacturing
Advanced PCB Manufacturing

AFFILATE

Gearbest Tronxy X8 220 x 220 x 200mm Desktop DIY 3D Printer
Tronxy X8 220 x 220 x 200mm Desktop DIY 3D Printer only $139.99

Gearbest Hubsan H117S Zino GPS 5.8G 1KM FPV with 4K UHD Camera 3-Axis Gimbal RC Drone - RTF
Hubsan H117S Zino GPS 5.8G 1KM FPV with 4K UHD Camera 3-Axis Gimbal RC Drone - RTF only $394.99

Gearbest 37-in-1 Sensor Modules Kit
37-in-1 Sensor Modules Kit only $13.99