How to use Infrared receiver and remote control with Arduino
Hello there, welcome to this simple tutorial on how to use an infrared receiver and its remote control with an Arduino board.
I’m using an Arduino Uno, LCD i2c screen, VS1838B Infrared receiver and a generic remote control, you can use most of IR remote controls that are used for TVs, Satellite Receivers..
This sensor and its remote will permit you to control remotely your Arduino board, and you can use it to control Relays, LEDs or even small robots… Yes I know it’s very old comparing to Wifi and Bluetooth but here we are :D.
The remote control sends IR codes to the sensor, in some code you’ll see that you can read the raw code and know its type, or IR protocol like NEC/RC5/RC6/Samsung/Panasonic…, in your project you’ll have to associate these buttons codes to some actions or functions like a robot movements, sound, lights….
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:
The module has a digital output that should be wired with a digital pin.
N.B: For both codes used below the LCD i²c is optional

Libraries
The libraries I used are: LCD i²c New_liquid_crystal Download here
and for the IR library you can download it through Arduino IDE -> Library Manager search for IRremote and install it.
Codes:
First it would be better to test with the library examples then the tutorial video will give you idea about the codes I provided below, there are supposed to be easily integrated in your projects.
The first code displays (on both serial monitor and LCD screen) raw values received by the sensor, this will help you to identify each button code to associate later with functions of your choice.
Code 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
//This code is used with Arduino IR sensor and LCD i2c screen //the sensor receives information from the remote and displays //the button's code on the serial monitor and the screen as well //Refer to SurtrTech.com for more information #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:
Here in the second code, I already associated every button with its own name, if we have the same remote, this would be easier to integrate in your project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
//This code works with IR sensor and its remote + LCD i²c screen //I used the code before to identify the buttons and here I associated every button code //with its name, when you press a button its name will show up on both Serial monitor and LCD //Refer to SurtrTech.com for more details #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); } |
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.