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

WellPCB PCB Manufacturing
urPCB PCB Manufacturing
PCBGOGO PCB service

Gearbest Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black
Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black only $$162.89

AFFILATE

Gearbest Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black
Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black only $$352.94

Gearbest Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black
Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black only $$153.84

Gearbest Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black
Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black only $$253.39