This project uses OpenCV and cvzone to track hand gestures from a webcam and control a servo motor connected to an Arduino board. The servo moves based on the number of fingers detected as "up."
- Detects fingers raised using a webcam.
- Controls a servo motor on Arduino through serial communication.
- Simple gesture-based servo positioning:
- All fingers up → servo rotates to 0°.
- All fingers down → servo rotates to 180°.
- Python 3.9+
- Arduino board (e.g., Uno, Mega)
- Servo motor connected to Arduino pin 9 (PWM pin)
- Libraries:
- OpenCV
- cvzone
- pyfirmata
-
Clone this repository or download the files.
-
Create a Python virtual environment (optional but recommended):
python -m venv env source env/bin/activate # Linux/macOS .\env\Scripts\activate # Windows Install dependencies:
pip install opencv-python cvzone pyfirmata Connect your Arduino board and upload the standard Firmata sketch:
Open Arduino IDE
Go to File > Examples > Firmata > StandardFirmata
Upload to your board
Connect your servo to Arduino pin 9.
Modify the controller.py file if your Arduino COM port is different from 'COM4'.
Usage Run the main hand tracking script:
python main.py The webcam will open and detect hand gestures.
The servo motor will rotate based on finger count.
Press k to quit.
Files main.py: Main script for hand tracking and video feed.
controller.py: Arduino servo control logic using pyfirmata.
Troubleshooting Make sure the Arduino is connected and Firmata firmware is uploaded.
Close other programs accessing the COM port.
Use Python 3.9 for compatibility with some dependencies.
Update pip if you get errors: python -m pip install --upgrade pip
License This project is open source and free to use.
Acknowledgments cvzone for easy hand tracking.
pyfirmata for Arduino communication.