This project demonstrates how to control the brightness of an LED connected to an Arduino based on the distance between the index finger and thumb using hand gesture recognition in OpenCV. The project uses Python, OpenCV for hand detection, and the pyFirmata library to interface with the Arduino Uno for controlling the LED brightness.
- Arduino Uno
- LED
- 220Ω Resistor
- Jumper Wires
- Breadboard
- Python (with OpenCV and pyFirmata libraries)
-
Hand Gesture Control: Detects the distance between the index finger and thumb to control the LED brightness.
-
Real-Time Adjustment: The brightness changes dynamically based on finger movement in front of the camera.
-
Arduino Integration: Uses the pyFirmata library to communicate between Python and Arduino for controlling the LED.
- Connect the positive terminal of the LED to Pin 9 of the Arduino through a 220Ω resistor.
- Connect the negative terminal of the LED to the GND pin of the Arduino.
- LED: Positive to Pin 9, Negative to GND
Before running the Python script, ensure your Arduino is ready for communication with the pyFirmata library.
- Upload the StandardFirmata sketch to your Arduino Uno:
- Open the Arduino IDE.
- Go to File > Examples > Firmata > StandardFirmata.
- Select your Arduino board and port.
- Click Upload.
You’ll need the following Python libraries:
- opencv-python
- mediapipe
- pyFirmata
You can install the required libraries using pip:
pip install opencv-python mediapipe pyfirmata
- Hand Detection: The program uses the MediaPipe library (via OpenCV) to detect the user's hand and identify the position of the index finger and thumb.
- Distance Calculation: The distance between the tip of the index finger and the thumb is calculated. This distance is mapped to a value between 0 and 255, which represents the LED brightness.
- Brightness Control: The pyFirmata library sends the mapped brightness value to the Arduino, which adjusts the LED brightness accordingly.
-
Add a graphical user interface (GUI) to display more information and control parameters.
-
Implement gesture-based control for multiple devices, like controlling multiple LEDs or other actuators.
-
Add error handling for connection issues with the Arduino.