
The Finger Controlled LED project combines computer vision, Python, and Arduino to create a touchless LED control system. Using a webcam and MediaPipe Hand Tracking, the system continuously measures the distance between your thumb and index finger. When the fingers move close together, the LED turns ON. When they move apart, the LED turns OFF.
This project introduces several important concepts:
220Ω Resistor| Component | Connection |
| ------------------ | --------------- |
| LED Anode (+) | Pin 13 |
| LED Cathode (-) | 220Ω Resistor |
| Resistor Other End | GND |
Pin 13220Ω ResistorGNDEnsure the resistor is connected in series with the LED to prevent excessive current that may damage the LED.
Open a terminal and execute:
pip install opencv-python
pip install mediapipe
pip install pyserial
Run the Python script and ensure your webcam is detected properly before connecting the Arduino.
If the webcam does not open, close any applications currently using the camera and try again.
The Arduino listens for serial data sent from Python. Based on the received command:
1 → LED ON0 → LED OFFThe Python application performs three tasks:
When the distance falls below a predefined threshold, Python sends 1 through serial communication. Otherwise, it sends 0.
MediaPipe Landmark ID: 4
MediaPipe Landmark ID: 8
The distance between these two points is calculated using the Euclidean distance formula.
distance = math.hypot(x2 - x1, y2 - y1)
This value determines whether the LED should be turned ON or OFF.
Webcam captures live video.
MediaPipe detects hand landmarks.
Thumb tip (4) and index tip (8) positions are extracted.
Distance between the two fingertips is calculated.
Python compares the distance with a threshold value.
Python sends either:
1 → LED ON0 → LED OFFArduino receives the command and updates the LED state.
Modify the threshold value inside the Python code:
if distance < 60:
Lower values require fingers to be closer together.
Higher values make detection more sensitive.
Modify:
int ledPin = 13;
to any available digital pin.
Remember to update the wiring accordingly.
Verify the LED polarity. The longer leg must connect to the Arduino output pin.
Confirm the correct COM port is specified inside serial.Serial('COM3', 9600).
Ensure no other application is currently using the webcam.
Improve room lighting and keep your hand clearly visible within the camera frame.
Verify the baud rate matches in both programs:
Serial.begin(9600)serial.Serial('COM3', 9600)After completing this project, you will understand:
Use different finger distances to control multiple colors.
Map finger distance to PWM brightness values.
Add support for:
Replace the LED with relays to control real appliances using hand gestures.
This Finger Controlled LED project demonstrates how computer vision and embedded systems can work together to create intuitive touchless control interfaces. By combining Python, MediaPipe, OpenCV, and Arduino, you can build the foundation for advanced gesture-controlled robotics and IoT applications.