Remote dimmer: IR on 12, LED on 5, buzzer on 13, on an Arduino Uno
Buttons 0 to 3 on the remote set the LED on pin 5 to off, dim, medium and full; an active buzzer on pin 13, switched by an NPN transistor, clicks for every code the receiver on pin 12 hears. The whole build, an Arduino Uno and 7 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The parts retail for about $32. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A remote dimmer: buttons 0 to 3 set the LED's brightness.
//
// receiver OUT -> pin 12 VCC -> 5V GND -> GND
// pin 5 -> 220 ohm -> LED -> GND
// pin 13 -> 1k -> an NPN transistor's base; the active buzzer from 5V
// to its collector; emitter -> GND
//
// Each NEC command is one button: 0x16 is 0, 0x0C is 1, 0x18 is 2 and 0x5E
// is 3. The buzzer clicks for every code, so you can hear that it arrived.
//
// Press 0, 1, 2 or 3 on the remote.
// The simulated remote speaks NEC, so only that decoder is compiled in.
#define DECODE_NEC
#include <IRremote.hpp>
const int RECEIVER = 12;
const int LED_PIN = 5;
const int BUZZER = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
IrReceiver.begin(RECEIVER, ENABLE_LED_FEEDBACK);
Serial.println("UNO is ready! Press 0, 1, 2 or 3.");
}
void loop() {
if (!IrReceiver.decode()) return;
bool repeat = IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT;
uint8_t command = IrReceiver.decodedIRData.command;
IrReceiver.resume();
if (repeat) return;
Serial.println(command, HEX);
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
switch (command) {
case 0x16: analogWrite(LED_PIN, 0); break;
case 0x0C: analogWrite(LED_PIN, 7); break;
case 0x18: analogWrite(LED_PIN, 63); break;
case 0x5E: analogWrite(LED_PIN, 255); break;
}
}
Parts list
9 parts, plus the jumper wires. They retail for about $32; on Mokxi they're free.
How it is wired
9 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; LED, red pin C; Transistor (NPN or PNP) pin E; Infrared receiver, VS1838B pin GND
- Arduino Uno R3 pin 13; Resistor, 1k Ω pin 1
- Arduino Uno R3 pin 12; Infrared receiver, VS1838B pin OUT
- Arduino Uno R3 pin 5; Resistor, 220 Ω pin 1
- Arduino Uno R3 pin 5V; Buzzer pin 1; Infrared receiver, VS1838B pin VCC
- Resistor, 220 Ω pin 2; LED, red pin A
- Resistor, 1k Ω pin 2; Transistor (NPN or PNP) pin B
- Transistor (NPN or PNP) pin C; Buzzer pin 2
- Infrared receiver, VS1838B pin IR; Infrared remote, 21 buttons pin IR
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.