Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsThe VL53L1X measures distance with a laser pulse. When your hand sits between 3 and 15 cm from it for half a second, the ESP32 toggles a relay, then waits for the hand to leave before it can toggle again. That makes a clean no-touch switch for messy hands in the kitchen or workshop. Dark or very shiny surfaces can confuse it, so test it on your own hand.
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.
VL53L1X laser distance sensor
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.
wave_switch.inoVerify & upload in Electrolark#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
const int RELAY_PIN = 26;
const bool ACTIVE_LOW = true;
const int NEAR_MM = 30, FAR_MM = 150;
const unsigned long HOLD_MS = 500;
bool on = false, armed = true;
unsigned long since = 0;
void setRelay(bool v) { on = v; digitalWrite(RELAY_PIN, (v == ACTIVE_LOW) ? LOW : HIGH); }
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
setRelay(false);
Wire.begin(21, 22);
sensor.setTimeout(500);
sensor.init();
sensor.setDistanceMode(VL53L1X::Short);
sensor.setMeasurementTimingBudget(30000);
sensor.startContinuous(40);
}
void loop() {
int mm = sensor.read();
bool hand = (mm >= NEAR_MM && mm <= FAR_MM);
if (hand && armed) {
if (since == 0) since = millis();
if (millis() - since > HOLD_MS) { setRelay(!on); armed = false; }
} else if (!hand) {
since = 0;
armed = true;
}
}
Something sits within 15 cm of the sensor. Lower FAR_MM or move the sensor.
Check the distances in the Serial Monitor (add Serial.println(mm)).
Flip ACTIVE_LOW.
Otherwise the relay would toggle repeatedly while the hand stays there.
Strong sunlight reduces range. Use it indoors.
Yes, with a PWM output and a MOSFET instead of a relay.
5 parts: ESP32-WROOM-32 38-Pin Development Board, Generic TOF400C VL53L1X Laser Ranging Sensor Module – I2C Interface, 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 intermediate project and takes about 1.5 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (wave_switch.ino).
About ₹1,089 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading distance from a VL53L1X; Requiring a hold time to avoid false triggers; Waiting for the hand to leave before re-arming.
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 VL53L1X laser distance meter. 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.