Accéder au contenu principal
Publicités

How to use Infrared receiver and remote control with Arduino

Hello Hello… Welcome to this simple tutorial on how to use an infrared receiver and its remote control with Arduino board.

I’m using Arduino Uno, LCD i2c screen, VS1838B Infrared receiver and a generic remote control, you can use most of remote controls around your house

If you want to see how to use a LCD i2c screen see my other post or video:

Arduino LCD I2C simple use and direct write from serial monitor

Wiring:

Codes: Watch the video to know the use of which code

Code 1:

//Surtrtech

#include <IRremote.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>


#define I2C_ADDR 0x27 

#define BACKLIGHT_PIN 3

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7


int RECV_PIN = 6;


IRrecv irrecv(RECV_PIN);

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

decode_results results;


void setup()

{

  Serial.begin(9600);

  irrecv.enableIRIn(); // Start the receiver

  lcd.begin (16,2);

  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

  lcd.setBacklight(HIGH);

  lcd.home ();

  lcd.print("Press a key");

}


void loop() {

  if (irrecv.decode(&results)) {

    lcd.clear();

    lcd.print(results.value, HEX);

    Serial.println(results.value, HEX);

    irrecv.resume(); // Receive the next value

  }

  delay(200);

}

 

Code 2:

 

//Surtrtech

#include "IRremote.h"

#include <LCD.h>

#include <LiquidCrystal_I2C.h>


#define I2C_ADDR 0x27 

#define BACKLIGHT_PIN 3

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7


int receiver = 6; 


LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

IRrecv irrecv(receiver);           

decode_results results;            




void setup()  

{

  Serial.begin(9600);

  Serial.println("IR Receiver Raw Data + Button Decode Test");

  irrecv.enableIRIn();

  lcd.begin (16,2);

  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

  lcd.setBacklight(HIGH);

  lcd.home ();

  lcd.print("Press a key");

  delay(2000);


}



void loop()  

{

  if (irrecv.decode(&results)) // have we received an IR signal?


  {

    //Serial.println(results.value, HEX);

    translateIR(); 

    irrecv.resume(); // receive the next value

  }  

}

void translateIR() 


{


  switch(results.value)


  {


  case 0xEF3B295B:  

    Serial.println(" CH- "); 

    lcd.clear();

    lcd.print("CH-");

    break;


  case 0xD7C4FB7F:  

    Serial.println(" CH  "); 

    lcd.clear();

    lcd.print("CH");

    break;


  case 0xF1FFE9FB:  

    Serial.println(" CH+ "); 

    lcd.clear();

    lcd.print("CH+");

    break;


  case 0x69C6FA7D:  

    Serial.println(" PREV "); 

    lcd.clear();

    lcd.print("PREV");

    break;


  case 0xDE4001F:  

    Serial.println(" NEXT "); 

    lcd.clear();

    lcd.print("NEXT");

    break;


  case 0x592FA519:  

    Serial.println(" PLAY/PAUSE "); 

    lcd.clear();

    lcd.print("PLAY/PAUSE");

    break;


  case 0x4DA7A0BF:  

    Serial.println(" VOL- ");

    lcd.clear();

    lcd.print("VOL-"); 

    break;


  case 0x3E3D6F9:  

    Serial.println(" VOL+ ");

    lcd.clear();

    lcd.print("VOL+"); 

    break;


  case 0xFB54EA5B:  

    Serial.println(" EQ "); 

    lcd.clear();

    lcd.print("EQ");

    break;


  case 0x26B9C4DD:  

    Serial.println(" 0 "); 

    lcd.clear();

    lcd.print("0");

    break;


  case 0x87E5C91F:  

    Serial.println(" 100+ "); 

    lcd.clear();

    lcd.print("100+");

    break;


  case 0xEF881E99:  

    Serial.println(" 200+ "); 

    lcd.clear();

    lcd.print("200+");

    break;


  case 0x264C7D03:  

    Serial.println(" 1 "); 

    lcd.clear();

    lcd.print("1");

    break;


  case 0x2D607981:  

    Serial.println(" 2 "); 

    lcd.clear();

    lcd.print("2");

    break;


  case 0x87EAA93D:  

    Serial.println(" 3 "); 

    lcd.clear();

    lcd.print("3");

    break;


  case 0x92DA21E3:  

    Serial.println(" 4  "); 

    lcd.clear();

    lcd.print("4");

    break;


  case 0x9F8ECFD5:  

    Serial.println(" 5 "); 

    lcd.clear();

    lcd.print("5");

    break;


  case 0x40876B7F:  

    Serial.println(" 6 "); 

    lcd.clear();

    lcd.print("6");

    break;


  case 0xF6027943:  

    Serial.println(" 7 "); 

    lcd.clear();

    lcd.print("7");

    break;


  case 0xC264BDB9:  

    Serial.println(" 8 "); 

    lcd.clear();

    lcd.print("8");

    break;


  case 0xB50E0A1D:  

    Serial.println(" 9 "); 

    lcd.clear();

    lcd.print("9");

    break;


  default: 

    Serial.println(" other button ");

    lcd.clear();

    lcd.print("other button");


  }


  delay(500);



}
Publicités

Yassine Tout afficher

Electronics, Automation engineering student... I try to share my little experience with other electronics amateur.

Répondre

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l'aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

%d blogueurs aiment cette page :