Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ก IR Remote Controlled Lamp

VID_20260728_135958_054-ezgif com-optimize

โœจ Wireless control for your moonlight lamp โœจ

Platform: Arduino Language: C++ Library: IRremote License: MIT


๐Ÿ•น๏ธ Turn your 230VAC lamp on/off using any standard IR remote

โœ… Easy to build
โœ… Perfect for bedroom or living room
โœ… Arduino + IR receiver module


๐ŸŽฅ Demo (Plz wait for loading...)

Lamp toggling ON/OFF with IR remote

๐ŸŽฌ Demo: Lamp toggles with every button press (for me is ON/OFF)


๐ŸŒŸ Features at a Glance

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

๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

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.

Features:

  • โœ… Wireless control up to 10 meters
  • โœ… Debounced input (no accidental toggling)
  • โœ… Serial monitor feedback
  • โœ… Works with any NEC protocol remote
  • โœ… Low power consumption

๐Ÿงฉ Components Used

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

๐Ÿ”Œ Circuit Wiring

System Overview

          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   Arduino   โ”‚
          โ”‚             โ”‚
          โ”‚  Pin 11 โ—„โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€ IR Receiver
          โ”‚  Pin 3  โ”€โ”€โ–บ โ”ผโ”€โ”€โ”€โ”€ Relay Module
          โ”‚  5V     โ”€โ”€โ–บ โ”ผโ”€โ”€โ”€โ”€โ”
          โ”‚  GND    โ”€โ”€โ–บ โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€ Common Ground & Power
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
                    โ”‚         โ”‚
                    โ–ผ         โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  Relay  โ”‚  โ”‚   IR    โ”‚
              โ”‚ Module  โ”‚  โ”‚ Sensor  โ”‚
              โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚    Lamp     โ”‚
            โ”‚  230VAC 15W โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Detailed Wiring Instructions

๐Ÿ”ด IR Receiver Sensor (Pin 11)

Sensor Pin Connect To
VCC (Left) Arduino 5V
GND (Right) Arduino GND
OUT (Center) Arduino Pin 11

๐ŸŸข Relay Module (Pin 3)

Relay Pin Connect To
VCC Arduino 5V
GND Arduino GND
IN (Signal) Arduino Pin 3

๐Ÿ’ก Lamp Wiring (230VAC โš ๏ธ)

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

๐Ÿ“Š Pin Connections

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)


โš™๏ธ How It Works

  1. IR Receiver constantly listens for infrared signals from your remote
  2. When you press a button, it captures the unique hex code (e.g., 0xBA45FF00)
  3. Arduino compares the received code with your targetCode
  4. If matched and debounce time passed (>250ms):
    • Toggles relay state (ON โ†” OFF)
    • Updates lightState variable
    • Prints status to Serial Monitor
  5. Relay switches the 230VAC lamp circuit ON/OFF

๐Ÿ’ป Code Explanation

Key Variables

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 timer

Setup Function

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);     // Relay OFF (Lamp OFF)
IrReceiver.begin(irPin, ENABLE_LED_FEEDBACK);  // Start IR receiver

Main Loop Logic

if (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
}

๐Ÿ“ฅ Installation

1. Install Required Library

# In Arduino IDE:
Sketch โ†’ Include Library โ†’ Manage Libraries โ†’ Search "IRremote" โ†’ Install

2. Get Your Remote's IR Code

Upload 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 0xBA45FF00 in the main code with the code you received!

3. Upload Main Sketch

  1. Open ir_relay_control.ino in Arduino IDE
  2. Select your board (Tools โ†’ Board โ†’ Arduino Uno/Nano)
  3. Select correct COM port
  4. Click Upload (โ†’)

๐ŸŽฎ Usage

  1. Power on your Arduino (USB or 9V adapter)
  2. Open Serial Monitor (9600 baud) to see status messages
  3. Point your IR remote at the receiver (within 10 meters)
  4. Press the programmed button โ†’ Lamp toggles ON
  5. Press again โ†’ Lamp toggles OFF
  6. Serial Monitor shows:
    IR Ready - Press the programmed button
    ON
    OFF
    ON
    

โš ๏ธ Safety Warnings

๐Ÿšจ HIGH VOLTAGE WARNING - 230VAC

This project involves mains voltage (230VAC) which can cause electric shock or death!

Mandatory Safety Precautions:

  • โœ… 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

Recommended:

  • 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

๐Ÿ”ง Troubleshooting

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

๐ŸŽจ Customization

Add Multiple Lamps

const int relayPin2 = 4;
const unsigned long targetCode2 = 0xFF10EF00;

// In loop()
if (code == targetCode2) {
  digitalWrite(relayPin2, !digitalRead(relayPin2));
}

Add Status LED

const int ledPin = 13;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, lightState ? HIGH : LOW);

Add EEPROM Memory (Save state after power loss)

#include <EEPROM.h>
lightState = EEPROM.read(0);
digitalWrite(relayPin, lightState ? LOW : HIGH);

๐Ÿ“ Project Structure

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

๐Ÿ“œ License

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.


๐Ÿ™ Acknowledgments

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

๐Ÿ“ž Support

Running into trouble? Try these troubleshooting steps first:

  1. ๐Ÿ”Œ Double-check your wiring โ€” a loose connection is the #1 culprit
  2. ๐Ÿงช Test the relay separately โ€” upload a basic blink sketch to isolate issues
  3. ๐Ÿ“ก Verify your IR receiver โ€” test with any TV remote using the IRrecvDemo sketch
  4. ๐Ÿ› Still stuck? โ€” Open an issue on GitHub and I'll take a look

๐ŸŽจ The "Totally Worked in Theory" Section

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:

My masterpiece whiteboard drawing

๐ŸŽจ "Trust me, I'm an engineer" ๐Ÿ˜‘๐Ÿ˜‚ probably me, right before everything went wrong


โŒ Reality:

  • 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.

๐Ÿง  What I learned:

Sometimes the universe says "not today, buddy".
So I stuck with the IR remote โ€” it's loyal, quiet, and doesn't have emotional breakdowns.

๐Ÿค— A gentle note for future coders:

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.

โญ Show Your Support

If this project lit up your day (literally), consider giving it a star on GitHub . it means more than you know.


Made with โค๏ธ and a soldering iron . by DIY enthusiasts, for DIY enthusiasts

About

๐Ÿ›‹๏ธ๐Ÿ“บ Control your 230V lamp with any IR remote using Arduino | No WiFi, no cloud, just pure lazy genius | DIY home automation that actually works

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages