Back to Basic Projects

Hand Gesture Distance Control

Control LED brightness or motor speed with your hand position — no buttons, no wires, just gesture and ultrasonic sensing.

📋 Overview

By continuously measuring hand distance with an HC-SR04, we convert physical position into a control value. Moving your hand toward the sensor increases speed or brightness; moving it away decreases it — a simple but intuitive human-machine interface.

Technical Insight: The HC-SR04 delivers accurate readings from 2cm to 400cm. We map the range 5–30cm (a comfortable hand-movement zone) to PWM 0–255 using Arduino's map() and constrain(). A moving average over the last 5 readings smooths noise for a stable response.

In simple terms: Your hand becomes a wireless knob. Hover it 5cm above for full brightness; 30cm away for off. Any position in between gives a proportional output. No physical contact needed.

What you'll learn: HC-SR04 operation and timing, pulseIn(), value smoothing/filtering, map() function, gesture-based HMI design, and analog output from digital sensors.

Estimated time: 30-45 minutes. Difficulty: ⭐⭐ Easy.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
HC-SR04 Ultrasonic Sensor2–400cm, ±3mm1
LED5mm1Brightness controlled by hand
Resistor220Ω1For LED
16x2 LCD with I2COptional1Shows distance + brightness %
Breadboard + WiresHalf-size1

🗺️ Component Pin Mapping

Hand Gesture Distance Control Component Pin Mapping Infographic

📖 Step-by-Step Tutorial

1

Wire the HC-SR04

VCC → 5V, GND → GND, TRIG → pin 9, ECHO → pin 10. Point the sensor upward for best hand-gesture results.
2

Wire the LED

LED anode → pin 3 (PWM) via 220Ω resistor. Cathode → GND.
3

Upload and Test

Upload code. Open Serial Monitor to see distance readings. Move your hand above the sensor — LED brightness changes.
4

Tune the Range

Adjust DIST_MIN and DIST_MAX constants for your preferred gesture zone (default: 5–30cm).
5

Control a Motor

Replace analogWrite(LED_PIN, brightness) with a transistor-driven DC motor for speed control instead of brightness.
💡
Point the sensor straight up (sensor face upward) and use it as a 'theremin-like' controller. For best results, keep your hand flat and parallel to the sensor face — angled hands cause reflections and erratic readings.

💻 Arduino Code

hand_gesture_control.ino
INO
// Hand Gesture Distance Control — Volt X
// HC-SR04 controls LED brightness via hand distance

const int TRIG = 9, ECHO = 10;
const int LED_PIN = 3;      // PWM pin
const int DIST_MIN = 5;     // cm — closest (full brightness)
const int DIST_MAX = 30;    // cm — farthest (off)

// Smoothing buffer
const int SMOOTH = 5;
long readings[SMOOTH];
int readIndex = 0;

long getDistance() {
  digitalWrite(TRIG, LOW);  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  return pulseIn(ECHO, HIGH) * 0.034 / 2;
}

long smoothedDistance() {
  readings[readIndex] = getDistance();
  readIndex = (readIndex + 1) % SMOOTH;
  long sum = 0;
  for (int i = 0; i < SMOOTH; i++) sum += readings[i];

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
...

Loading reviews...