Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA cheap IR receiver module decodes the pulses from almost any remote. The ESP32 listens with the IRremote library, prints the code of every button you press, and toggles a relay when it sees the code you chose. It works with a spare TV, set-top box or fan remote, so a lamp can be controlled from the sofa without buying anything else.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Tick anything you already have and the total updates.
IR receiver module
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger. Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
ir_relay.inoVerify & upload in Electrolark#include <IRremote.hpp>
const int IR_PIN = 15, RELAY_PIN = 26;
const uint32_t TARGET_CODE = 0; // 0 = just print codes; then paste your button's code here
bool on = false;
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // most relay modules are OFF when the input is HIGH
IrReceiver.begin(IR_PIN, DISABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
uint32_t code = IrReceiver.decodedIRData.decodedRawData;
if (code != 0) Serial.printf("code: 0x%08X\n", code);
if (TARGET_CODE != 0 && code == TARGET_CODE) {
on = !on;
digitalWrite(RELAY_PIN, on ? LOW : HIGH);
}
IrReceiver.resume();
}
}
Check that the IR OUT pin goes to GPIO 15 and the receiver has 3.3 V. Point the remote straight at it.
Some remotes send repeat codes. Press once, briefly, and use the first printed code.
Add a short delay after toggling so a repeat code is ignored.
Many send long codes the library may only partly decode, but a TV or set-top box remote is easy.
Yes. Use one code per relay.
IR needs no pairing and any old remote works.
5 parts: ESP32-WROOM-32 38-Pin Development Board, Generic Infrared IR Receiver Module for Arduino – 38kHz TSOP1838 Sensor, 5V Relay Module with Optocoupler, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (ir_relay.ino).
About ₹553 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading IR remote codes with the IRremote library; Toggling a relay with a button; Finding a button's code first, then using it.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Ideas that reuse this build: ESP32 web server relay switch. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.