
Control an AC bulb using any infrared remote with an Arduino and relay
Control an AC Bulb with Any Infrared Remote
This project demonstrates how to control an AC bulb (or any AC load) using an Arduino, a relay, and an infrared (IR) remote. This setup allows you to switch the bulb on and off remotely, opening up several practical applications:
- Creating a remote-controlled lamp
- Building a simple home automation system
- Controlling appliances from a distance
- Prototyping remote switching mechanisms for various projects
Hardware/Components
- Arduino Uno (or any compatible board)
- Relay module (rated for your AC load)
- IR receiver module (VS1838B recommended)
- IR remote control (any remote can be used)
- AC bulb and socket/lamp
- Jumper wires
- Soldering iron and solder (optional)
Wiring Guide
The wiring is crucial for safety and functionality. Ensure the AC power is OFF before making any connections. Connect the components as follows:
- IR Receiver: Connect the VCC pin to the Arduino's 5V pin, the GND pin to GND, and the OUT pin to digital pin 11 (or any other suitable digital pin).
- Relay: Connect the VCC pin of the relay module to the Arduino's 5V pin, the GND pin to GND, and the IN pin to digital pin 2 (or another digital pin as defined in the code).
- AC Bulb: Cut one of the wires leading to the AC bulb. Connect each of the cut ends to the normally open (NO) contacts of the relay. (in video at 03:51)
- Power: Connect the AC power to the relay as per its specifications. Caution: Mains voltage is dangerous. Ensure proper insulation and double-check connections.
The relay acts as a switch, controlled by the Arduino. When the relay is activated, it completes the circuit to the AC bulb, turning it on. (in video at 03:07)
Code Explanation
The provided code uses the IRremote library. Download and install this library in your Arduino IDE. This code detects IR signals, decodes them, and controls the relay based on the received command.
Configurable Parameters:
const char type ='W';// 'W' for white remote, 'B' for black remote
const boolean PCB = 1;// 1 if using PCB receiver, 0 if bare module (in video at 11:04)
boolean displayCode = true;// Set to true to print received codes to serial monitor (in video at 13:28)
const int RELAY_PIN = 2;// Define the Arduino pin connected to the relay (in video at 06:38)
const String ON="3";// Key on the remote to turn the relay ON (in video at 06:58)
const String OFF="1";// Key on the remote to turn the relay OFF (in video at 06:58)
Customizing for Your Remote:
- Identify Remote Type: Determine if your remote is similar to the "black" or "white" remote referenced in the code. Set the
type
variable accordingly. - Receiver Type: Indicate whether your IR receiver is a bare module or comes on a PCB. Set the
PCB
variable to 0 or 1, respectively. - Relay Pin: Specify the Arduino pin connected to the relay's control pin.
- ON/OFF Keys: If you are using a custom remote, you'll need to determine the hexadecimal codes for the desired ON and OFF buttons. Use
displayCode = true
, open the Serial Monitor, and press the buttons on your remote. Copy the hexadecimal codes displayed and use these values for theON
andOFF
variables. (in video at 13:15)
Live Project/Demonstration
(in video at 09:52) The project demonstrates the AC bulb being switched on and off using both the provided white remote and a black remote. The Serial Monitor displays the decoded IR signals and the relay's status.
Chapters
- Introduction and Project Overview (00:00)
- Explanation of Remotes and Receivers (00:49)
- Safety Precautions with AC Wiring (02:09)
- Hardware Explanation: Relay and AC Bulb Connection (02:48)
- Code Explanation and Configuration (05:29)
- Project Demonstration with White Remote and PCB (09:52)
- Demonstration with Bare Module (10:54)
- Demonstration with Black Remote (11:53)
- Using a Custom Remote (13:15)
- Conclusion and Future Project Ideas (15:56)
Comments will be displayed here.