โ
Easy to build
โ
Perfect for bedroom or living room
โ
Arduino + IR receiver module
| Feature | Description |
|---|---|
| ๐ฎ Wireless Control | Operate from up to 10 meters away |
| ๐ Toggle Function | One button - ON/OFF control |
| โก Quick Response | Instant switching with debounce protection |
| ๐ Serial Feedback | Real-time status monitoring |
| ๐ Simple Setup | Only 3 wires to connect! |
| ๐ฐ Budget Friendly | Under $10 for the entire setup |
- Overview
- Components Used
- Circuit Wiring
- Pin Connections
- How It Works
- Code Explanation
- Installation
- Usage
- Safety Warnings
- Troubleshooting
- Customization
- License
This project transforms your ordinary Moonlight 230VAC 15W lamp into a smart, remote-controlled lighting system. Using an IR receiver sensor and a 5V relay module, you can toggle your lamp ON/OFF from across the room with any standard IR remote control.
- โ Wireless control up to 10 meters
- โ Debounced input (no accidental toggling)
- โ Serial monitor feedback
- โ Works with any NEC protocol remote
- โ Low power consumption
| Component | Specification | Quantity |
|---|---|---|
| Arduino Board | Uno/Nano/Mega | 1 |
| IR Receiver Sensor | VS1838B / Any 38kHz | 1 |
| Relay Module | 5V Single Channel | 1 |
| Moonlight Lamp | 230VAC 15W | 1 |
| Jumper Wires | Male-Female / Male-Male | 5-6 |
| IR Remote | Any NEC protocol | 1 |
โโโโโโโโโโโโโโโ
โ Arduino โ
โ โ
โ Pin 11 โโโโโผโโโโ IR Receiver
โ Pin 3 โโโบ โผโโโโ Relay Module
โ 5V โโโบ โผโโโโโ
โ GND โโโบ โผโโโโโผโโโโ Common Ground & Power
โโโโโโโโโโโโโโโ โ
โ โ
โผ โผ
โโโโโโโโโโโ โโโโโโโโโโโ
โ Relay โ โ IR โ
โ Module โ โ Sensor โ
โโโโโโฌโโโโโ โโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโ
โ Lamp โ
โ 230VAC 15W โ
โโโโโโโโโโโโโโโ
| Sensor Pin | Connect To |
|---|---|
| VCC (Left) | Arduino 5V |
| GND (Right) | Arduino GND |
| OUT (Center) | Arduino Pin 11 |
| Relay Pin | Connect To |
|---|---|
| VCC | Arduino 5V |
| GND | Arduino GND |
| IN (Signal) | Arduino Pin 3 |
| Terminal | Connection |
|---|---|
| Live Wire (Brown/Red) | Relay COM terminal |
| Relay NO terminal | Lamp Live input |
| Neutral Wire (Blue/Black) | Direct to Lamp Neutral |
| Earth Wire (Green/Yellow) | Lamp Earth terminal |
AC Mains (230V)
โ
โโโ Live โโโโบ Relay COM โโโโบ Relay NO โโโโบ Lamp Live
โ
โโโ Neutral โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโบ Lamp Neutral
| Arduino Pin | Connected To | Purpose |
|---|---|---|
| Pin 3 | Relay IN | Control lamp (HIGH=OFF, LOW=ON) |
| Pin 11 | IR Receiver OUT | Receive IR signals |
| 5V | Relay VCC + IR VCC | Power supply |
| GND | Relay GND + IR GND | Common ground |
Note: All VCC and GND are connected in parallel (common power/ground)
- IR Receiver constantly listens for infrared signals from your remote
- When you press a button, it captures the unique hex code (e.g.,
0xBA45FF00) - Arduino compares the received code with your
targetCode - If matched and debounce time passed (>250ms):
- Toggles relay state (ON โ OFF)
- Updates
lightStatevariable - Prints status to Serial Monitor
- Relay switches the 230VAC lamp circuit ON/OFF
const int relayPin = 3; // Relay control pin
const int irPin = 11; // IR sensor input pin
const unsigned long targetCode = 0xBA45FF00; // Your remote's button code
bool lightState = false; // Current lamp state (OFF initially)
unsigned long lastPressTime = 0; // Debounce timerpinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Relay OFF (Lamp OFF)
IrReceiver.begin(irPin, ENABLE_LED_FEEDBACK); // Start IR receiverif (IrReceiver.decode()) { // Signal received?
if (code matches && debounce) { // Valid button press?
lightState = !lightState; // Toggle state
digitalWrite(relayPin, lightState ? LOW : HIGH); // Control relay
}
IrReceiver.resume(); // Ready for next signal
}# In Arduino IDE:
Sketch โ Include Library โ Manage Libraries โ Search "IRremote" โ InstallUpload this test sketch to find your button code:
#include <IRremote.h>
void setup() {
Serial.begin(9600);
IrReceiver.begin(11);
Serial.println("Press any button on your remote");
}
void loop() {
if (IrReceiver.decode()) {
Serial.print("Code: 0x");
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
IrReceiver.resume();
}
}Replace
0xBA45FF00in the main code with the code you received!
- Open
ir_relay_control.inoin Arduino IDE - Select your board (Tools โ Board โ Arduino Uno/Nano)
- Select correct COM port
- Click Upload (โ)
- Power on your Arduino (USB or 9V adapter)
- Open Serial Monitor (9600 baud) to see status messages
- Point your IR remote at the receiver (within 10 meters)
- Press the programmed button โ Lamp toggles ON
- Press again โ Lamp toggles OFF
- Serial Monitor shows:
IR Ready - Press the programmed button ON OFF ON
๐จ HIGH VOLTAGE WARNING - 230VAC
This project involves mains voltage (230VAC) which can cause electric shock or death!
- โ Disconnect power before wiring the lamp
- โ Use insulated tools only
- โ Place everything in a non-conductive enclosure
- โ Heat shrink tubing on all AC connections
- โ Keep high voltage away from low voltage circuits
- โ Double-check wiring before powering on
- โ Add a fuse (1A slow-blow) on live wire
- โ Never touch wires while powered
- Use a pre-wired relay module with opto-isolation
- Add a status LED to indicate relay state
- Use wire nuts or WAGO connectors for AC wiring
| Problem | Possible Cause | Solution |
|---|---|---|
| Lamp doesn't turn ON | Wrong IR code | Find correct code using test sketch |
| Relay wired wrong | Check COM โ Lamp โ NO connection | |
| Relay failed | Test relay with LED + resistor first | |
| Random toggling | No debounce | Increase delay: change 250 to 300 |
| IR interference | Shield receiver from sunlight/CFL | |
| No serial output | Wrong baud rate | Set Serial Monitor to 9600 |
| Wrong pin | Ensure IR sensor on Pin 11 | |
| Lamp flickers | Loose connection | Check all AC wire connections |
| Relay chattering | Add 10ยตF capacitor across relay VCC/GND | |
| Short range | Low battery | Replace remote battery |
| Obstruction | Clear line-of-sight to sensor |
const int relayPin2 = 4;
const unsigned long targetCode2 = 0xFF10EF00;
// In loop()
if (code == targetCode2) {
digitalWrite(relayPin2, !digitalRead(relayPin2));
}const int ledPin = 13;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, lightState ? HIGH : LOW);#include <EEPROM.h>
lightState = EEPROM.read(0);
digitalWrite(relayPin, lightState ? LOW : HIGH);arduino-ir-relay-control/
โ
โโโ ir_relay_control.ino # Main Arduino sketch
โโโ README.md # Project documentation
โโโ LICENSE # MIT License
โโโ IRremote.h # IR library header
โโโ Arduino-IRremote-master.zip # Library archive (backup)
โ
โโโ .vscode/ # VS Code configuration
โ โโโ c_cpp_properties.json
โ โโโ settings.json
โ
โโโ images/ # Documentation assets
โโโ lamp.gif # Live demo animation
โโโ pir-sensor.jpg # Wiring reference image
This project is released under the MIT License so you're free to use, modify, share, and even build commercial products with it. No strings attached, just open-source love.
Big thanks to the people and projects that made this possible:
- IRremote Library by Ken Shirriff, z3t0, and ArminJo โ the backbone of this project
- The Arduino Community โ for endless inspiration, forums, and support
- Every open-source hardware contributor โ keeping the spirit of DIY alive
Running into trouble? Try these troubleshooting steps first:
- ๐ Double-check your wiring โ a loose connection is the #1 culprit
- ๐งช Test the relay separately โ upload a basic blink sketch to isolate issues
- ๐ก Verify your IR receiver โ test with any TV remote using the IRrecvDemo sketch
- ๐ Still stuck? โ Open an issue on GitHub and I'll take a look
Warning: What you're about to see is a beautiful dream that reality rejected๐๐.
I had this brilliant idea . why not use a PIR motion sensor? The lamp turns on automatically when someone walks by! Genius, right?
So I drew my master plan on a whiteboard:
๐จ "Trust me, I'm an engineer" ๐๐ probably me, right before everything went wrong
- My PIR sensor had โจanxietyโจ ๐ฃ it kept triggering for NO reason
- Filtered it? Still noisy.
- Added capacitors? Still dramatic.
- Talked to it nicely? Ignored me completely.
Sometimes the universe says "not today, buddy".
So I stuck with the IR remote โ it's loyal, quiet, and doesn't have emotional breakdowns.
If you're braver than me and want to try PIR + relay + AC power:
- Keep the sensor FAR from the relay (like, socially distant far)
- Use shielded cables (they're like emotional support wires)
- Add a big capacitor (100ยตF) โ it's basically therapy for electronics
Or just use IR remote like a peaceful person. No shame. ๐
โค๏ธ This whiteboard drawing now lives here forever as a monument to over-ambitious Tuesday afternoons.
If this project lit up your day (literally), consider giving it a star on GitHub . it means more than you know.


