📚 Course contents
Projects Hub, build 65 of 81
Gesture-Controlled Light with Arduino and Ultrasonic Sensor
In a rapidly advancing technological landscape, the integration of smart devices into our daily lives has become commonplace. One such innovation is gesture-controlled smart lighting, a system that allows users to control their lighting fixtures with simple hand movements. This blend of technology and convenience offers an engaging and intuitive way to interact with our living spaces. In this article, we will delve into the fascinating world of gesture-controlled smart lighting, exploring its working principle, required components, circuit diagram, working with Arduino, and the necessary code.
Introduction
Gesture-controlled smart lighting is an innovative application of electronics and automation that enables users to control the lighting in their surroundings using hand gestures. This technology utilizes sensors and microcontrollers to interpret specific hand movements, triggering corresponding actions to adjust the brightness, color, or on/off state of the lights. It brings a futuristic and interactive element to the conventional way we interact with lighting systems.
Working Principle
The working principle of gesture-controlled smart lighting is based on the use of sensors, typically infrared or ultrasonic, to detect hand gestures within a predefined range. These sensors capture the movements and transmit the data to a microcontroller, usually Arduino, for processing. The Arduino interprets the data and triggers actions based on predefined gesture patterns, adjusting the lighting accordingly.
Things We Need
To create a gesture-controlled smart lighting system, you will need the following components:
- Arduino Board: Acts as the brain of the system, processing sensor data and controlling the lighting.
- HC-SR04 Ultrasonic Sensor: Detects the hand and transmits the data to the Arduino.
- LED and 220Ω resistor: The light that will be controlled by the gesture.
- Breadboard and Jumper Wires: Used to connect and prototype the circuit.
Circuit Diagram
To set up the circuit for gesture-controlled smart lighting, follow this simple circuit diagram:
| Part | Goes to the Arduino |
|---|---|
| HC-SR04 VCC | 5V |
| HC-SR04 GND | GND |
| HC-SR04 Trig | pin 9 |
| HC-SR04 Echo | pin 10 |
| LED long leg, through a 220Ω resistor | pin 6 |
| LED short leg | GND |
Working of the System with Arduino
- Sensor Data Acquisition: The ultrasonic sensor measures how far away the nearest thing is, ten times a second.
- Data Processing: Arduino checks if something came closer than 15 cm. Only the moment it arrives counts, so holding your hand still does not make the light flicker.
- Action Triggering: Each wave toggles the light.
- Controlling LED Lighting: The Arduino sends HIGH or LOW to the LED on pin 6.
Arduino Code
Here's a simple example of Arduino code: wave your hand over the ultrasonic sensor to switch the light on, and wave again to switch it off.
// Wave your hand over the sensor to switch the light ON or OFF
const int trigPin = 9;
const int echoPin = 10;
const int ledPin = 6;
const int waveDistance = 15; // a hand closer than this (in cm) counts as a wave
bool lightOn = false;
bool handWasThere = false;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
// Distance in cm, or 999 when there is no echo
int readDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
unsigned long time = pulseIn(echoPin, HIGH, 30000);
if (time == 0) return 999;
return time * 0.0343 / 2;
}
void loop() {
int distance = readDistance();
bool handIsThere = distance < waveDistance;
// only when the hand arrives, not all the time it stays there
if (handIsThere && !handWasThere) {
lightOn = !lightOn;
digitalWrite(ledPin, lightOn ? HIGH : LOW);
Serial.println(lightOn ? "Light ON" : "Light OFF");
}
handWasThere = handIsThere;
delay(100);
}Conclusion
Gesture-controlled smart lighting represents an exciting leap into the future of home automation. By leveraging sensors and microcontrollers like Arduino, we can create intuitive and engaging interfaces for everyday devices. This innovation not only enhances convenience but also adds a touch of sophistication to our living spaces. With ongoing advancements in technology, gesture-controlled smart lighting is just a glimpse of what's possible in the realm of electronics and automation. Explore, experiment, and illuminate your world with the power of gestures.

