IR Remote LED Controller
ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic
Control an LED with a TV-style infrared remote. A VS1838B IR receiver (OUT on GPIO 14) picks up NEC-protocol button codes via the IRremote library: UP/DOWN arrows step the brightness of the green LED on GPIO 4 (analogWrite PWM), OK toggles power, and keys 1/2/3 jump to dim/medium/full presets. A 128x64 OLED shows the last key, the brightness value, and a bar graph. While the sketch runs, a clickable Virtual IR remote panel appears in the Lab - or leave Auto demo presses on and watch it drive itself.
sketch.ino
// IR Remote LED Controller - control an LED's brightness with a TV-style remote.
// The VS1838B receiver picks up invisible infrared light pulses from a remote
// and the IRremote library turns them back into button codes (NEC protocol).
// While the sketch runs, a Virtual IR remote panel appears - click its buttons!
// UP/DOWN change brightness, OK toggles power, 1/2/3 jump to preset levels.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <IRremote.hpp>
#define RECV_PIN 14
#define LED_PIN 4
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int brightness = 153; // 0..255
bool power = false;
void showState(const char* keyName) {
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("IR REMOTE LED");
display.setCursor(0, 14);
display.print("Key: ");
display.print(keyName);
display.setTextSize(2);
display.setCursor(0, 28);
if (power) {
display.print(brightness);
} else {
display.print("OFF");
}
display.setTextSize(1);
int bar = (brightness * 120) / 255;
display.setCursor(0, 50);
display.print("[");
for (int i = 0; i < 12; i++) {
if (i * 10 < bar) {
display.print("#");
} else {
display.print("-");
}
}
display.print("]");
display.display();
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
Serial.println("IR remote LED controller ready - press a remote button");
showState("none");
}
void loop() {
if (IrReceiver.decode()) {
int cmd = IrReceiver.decodedIRData.command;
const char* keyName = "?";
if (cmd == 0x18) { // UP arrow
keyName = "UP";
brightness = brightness + 51;
if (brightness > 255) brightness = 255;
power = true;
} else if (cmd == 0x52) { // DOWN arrow
keyName = "DOWN";
brightness = brightness - 51;
if (brightness < 0) brightness = 0;
power = true;
} else if (cmd == 0x1C) { // OK button
keyName = "OK";
power = !power;
} else if (cmd == 0x45) { // key 1 - dim preset
keyName = "1";
brightness = 64;
power = true;
} else if (cmd == 0x46) { // key 2 - medium preset
keyName = "2";
brightness = 128;
power = true;
} else if (cmd == 0x47) { // key 3 - full preset
keyName = "3";
brightness = 255;
power = true;
}
int duty = 0;
if (power) duty = brightness;
analogWrite(LED_PIN, duty);
Serial.print("IR cmd=0x");
Serial.print(cmd, HEX);
Serial.print(" ");
Serial.print(keyName);
Serial.print(" bright=");
Serial.print(brightness);
Serial.print(" power=");
if (power) {
Serial.println("ON");
} else {
Serial.println("OFF");
}
showState(keyName);
IrReceiver.resume(); // ready for the next button
}
delay(50);
}Built with FluxBench.AI — the AI workbench for embedded projects.