Project Overview
This project creates a gesture-controlled light switch that turns lights on and off with a simple hand wave. Using a PIR sensor, the system detects motion and toggles a relay that controls the light. A short wave turns the light on, and another wave turns it off.
Difficulty: Beginner
Estimated time: 1-2 hours
Estimated cost: $15-25
How It Works
A PIR sensor detects hand movement within a short range (10-30cm). Each time motion is detected, the Arduino toggles a relay that controls the light. A status LED indicates the current state, and debouncing prevents rapid toggling.
Materials Needed
- Arduino Nano or Arduino Uno (1)
- HC-SR501 PIR sensor (1)
- Relay module (5V, single channel)
- LED for status indication
- 220Ω resistor for LED
- Jumper wires
- Power supply (5V 1A)
- Project enclosure
Circuit Diagram
Connection Table
| Component |
Pin |
Arduino Pin |
PIR Sensor |
VCC
5V
PIR Sensor |
GND
GND
PIR Sensor |
OUT
Digital Pin 2
Relay Module |
IN
Digital Pin 3
Status LED |
Anode
Digital Pin 13 (via 220Ω)
表
Arduino Code
// Gesture-Controlled Light Switch
const int pirPin = 2;
const int relayPin = 3;
const int ledPin = 13;
bool lightState = false;
unsigned long lastTriggerTime = 0;
const unsigned long debounceDelay = 1000;
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
delay(30000);
}
void toggleLight() {
lightState = !lightState;
digitalWrite(relayPin, lightState ? HIGH : LOW);
digitalWrite(ledPin, lightState ? HIGH : LOW);
}
void loop() {
bool motion = digitalRead(pirPin) == HIGH;
if (motion && (millis() - lastTriggerTime > debounceDelay)) {
lastTriggerTime = millis();
toggleLight();
}
delay(50);
}
Enhanced Version with LED Fade Effect
const int pirPin = 2;
const int relayPin = 3;
const int ledPin = 13;
bool lightState = false;
unsigned long lastTriggerTime = 0;
const unsigned long debounceDelay = 1000;
unsigned long fadeStartTime = 0;
bool fading = false;
void fadeLED(int start, int end) {
int duration = 500;
unsigned long startTime = millis();
while (millis() - startTime < duration) {
int brightness = map(millis() - startTime, 0, duration, start, end);
analogWrite(ledPin, brightness);
delay(5);
}
analogWrite(ledPin, end);
}
void toggleLight() {
lightState = !lightState;
digitalWrite(relayPin, lightState ? HIGH : LOW);
if (lightState) fadeLED(0, 255);
else fadeLED(255, 0);
}
void setup() {
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, LOW);
digitalWrite(ledPin, LOW);
delay(30000);
}
void loop() {
if (digitalRead(pirPin) == HIGH && (millis() - lastTriggerTime > debounceDelay)) {
lastTriggerTime = millis();
toggleLight();
}
delay(50);
}
Installation Steps
- Adjust PIR sensor sensitivity to minimum range (10-30cm)
- Assemble circuit on breadboard and test
- Upload code and test gesture detection
- Mount sensor in desired location
- Wire the light to the relay
- Enclose electronics in a safe enclosure
- Wave hand to turn light on/off
Project Extensions
- Add second PIR sensor for dimming control
- Use RGB LED strip and cycle colors with multiple gestures
- Add multiple sensors to control different lights
- Add ESP32 to send state to Home Assistant
- Add rechargeable battery for portable use
Conclusion
This gesture-controlled light switch adds a touch of magic to any room, perfect for kitchens, workshops, or simply for the novelty of waving to control lights.