A gesture-controlled robotic hand that mimics your hand movements in real-time using MediaPipe hand tracking, OpenCV, and ESP32 microcontroller to control 11 servo motors.
RoboticHand_p1.mp4
RoboticHand_p2.mp4
- Real-Time Hand Tracking: Uses Google's MediaPipe for accurate hand landmark detection
- 11 Servo Control: Independently controls 11 servos for realistic finger movements
- Pinky (tip & base)
- Ring finger (tip & base)
- Middle finger (tip & base)
- Index finger (tip & base)
- Thumb (tip, middle, & spread)
- High-Speed Communication: 250,000 baud rate for minimal latency
- Optimized Performance: Multi-threaded architecture for smooth real-time control
- Right Hand Detection: Automatically detects and tracks right hand movements
- Safety Features: Angle constraints (0-180Β°) to prevent servo damage
- Low Latency: Optimized camera settings and processing for responsive control
- ESP32 Development Board - Microcontroller for servo control
- 11 x Servo Motors (e.g., SG90 or MG996R) - Actuators for finger movement
- Webcam - For hand tracking
- Power Supply - 5V external power for servos (recommended)
- USB Cable - For ESP32 programming and serial communication
- Jumper Wires - For connections
- Python 3.7+ - Main programming language
- OpenCV - Computer vision and camera interface
- MediaPipe - Hand tracking and landmark detection
- PySerial - Serial communication with ESP32
- Arduino IDE - ESP32 programming
- ESP32Servo Library - Servo motor control
βββββββββββββββββββ USB Serial ββββββββββββββββ
β Python Script β ββββββ250000 baudβββββΊ β ESP32 β
β (Hand Tracker) β (Angle Data) β Microcontrollerβ
βββββββββββββββββββ ββββββββββββββββ
β β
β β
Webcam 11 Servos
(Camera) (Robotic Hand)
β β
βΌ βΌ
ββββββββββββ βββββββββββββββββ
βYour Hand β βRobotic Hand β
βMovements β βMimics Actions β
ββββββββββββ βββββββββββββββββ
- Hand Detection: Webcam captures your hand movements
- Landmark Extraction: MediaPipe identifies 21 hand landmarks
- Angle Calculation: Python calculates finger joint angles from landmarks
- Mapping: Angles are mapped from hand coordinates (30-160Β°) to servo range (0-180Β°)
- Serial Transmission: Angle data sent to ESP32 as comma-separated values
- Servo Control: ESP32 updates all 11 servos simultaneously
- Real-Time Feedback: Process repeats at high FPS for smooth movement
Connect servo motors to the ESP32 GPIO pins as follows:
| Servo Number | Finger Joint | ESP32 GPIO Pin |
|---|---|---|
| 1 | Pinky Tip | 4 |
| 2 | Pinky Base | 13 |
| 3 | Ring Tip | 12 |
| 4 | Ring Base | 14 |
| 5 | Middle Tip | 27 |
| 6 | Middle Base | 26 |
| 7 | Index Tip | 33 |
| 8 | Index Base | 32 |
| 9 | Thumb Tip | 21 |
| 10 | Thumb Middle | 19 |
| 11 | Thumb Spread | 23 |
ESP32 Servo Motors
βββββ ββββββββββββ
GPIO 4 βββββββββββββββΊ Pinky Tip (Signal)
GPIO 13 βββββββββββββββΊ Pinky Base (Signal)
GPIO 12 βββββββββββββββΊ Ring Tip (Signal)
GPIO 14 βββββββββββββββΊ Ring Base (Signal)
GPIO 27 βββββββββββββββΊ Middle Tip (Signal)
GPIO 26 βββββββββββββββΊ Middle Base (Signal)
GPIO 33 βββββββββββββββΊ Index Tip (Signal)
GPIO 32 βββββββββββββββΊ Index Base (Signal)
GPIO 21 βββββββββββββββΊ Thumb Tip (Signal)
GPIO 19 βββββββββββββββΊ Thumb Middle (Signal)
GPIO 23 βββββββββββββββΊ Thumb Spread (Signal)
5V Power Supply βββββββΊ All Servos VCC (Red Wire)
GND ββββββββββββββββββββΊ All Servos GND (Brown/Black Wire)
- DO NOT power all servos directly from ESP32's 5V pin
- Use an external 5V power supply (2-3A recommended)
- Connect ESP32 GND to power supply GND (common ground)
- Each servo draws 100-500mA under load; 11 servos can draw 1-5A total
- Download from Arduino Official Website
- Install following the platform-specific instructions
- Open Arduino IDE
- Go to
FileβPreferences - Add this URL to "Additional Boards Manager URLs":
https://dl.espressif.com/dl/package_esp32_index.json
- Go to
ToolsβBoardβBoards Manager - Search for "ESP32" and click Install
- Go to
SketchβInclude LibraryβManage Libraries - Search for "ESP32Servo"
- Click Install
- Connect ESP32 to your computer via USB
- Open the provided ESP32 code in Arduino IDE
- Select your board:
ToolsβBoardβESP32 Dev Module(or your specific model) - Select the correct port:
ToolsβPortβCOM X(Windows) or/dev/cu.usbserial-XXX(Mac) - Click Upload button (β)
- Wait for "Done uploading" message
# Install required packages
pip install opencv-python mediapipe pyserial numpy
# Or use requirements.txt
pip install -r requirements.txtCreate a requirements.txt file:
opencv-python>=4.5.0
mediapipe>=0.10.0
pyserial>=3.5
numpy>=1.21.0
Edit the Python script to match your serial port:
Windows:
ser = serial.Serial('COM3', 250000, timeout=0) # Change COM3 to your portMac/Linux:
ser = serial.Serial('/dev/tty.usbserial-110', 250000, timeout=0) # Update port nameTo find your port:
- Windows: Device Manager β Ports (COM & LPT)
- Mac:
ls /dev/tty.*in Terminal - Linux:
ls /dev/ttyUSB*orls /dev/ttyACM*
-
Connect Hardware
- Connect ESP32 via USB
- Ensure servos are properly wired and powered
-
Upload ESP32 Code
# Already done in software setup- Run Python Hand Tracker
python hand_tracking.py-
Position Your Hand
- Place your right hand in front of the webcam
- Keep hand within camera frame
- Ensure good lighting for best tracking
-
Watch the Magic! β¨
- Move your fingers - the robotic hand will follow
- Check console for FPS readings
- Press 'q' to quit
- FPS Display: Console shows real-time FPS (aim for 15-30 FPS)
- Immediate Response: Robotic hand mirrors your movements with minimal delay
- Smooth Motion: Servos update only when angles change to reduce jitter
Try these gestures to test your robotic hand:
| Gesture | Description |
|---|---|
| β Fist | Close all fingers - robotic hand makes a fist |
| β Open Hand | Extend all fingers - robotic hand opens fully |
| βοΈ Peace Sign | Index and middle finger up - robot mimics |
| π Thumbs Up | Thumb extended, others closed |
| π€ Pinch | Thumb and index together - precise control |
| π€ Rock On | Pinky and index up, others down |
Serial error: could not open port...
Solutions:
- Check ESP32 is connected via USB
- Update serial port name in Python script
- Ensure no other program is using the port (close Arduino Serial Monitor)
- Try unplugging and reconnecting ESP32
No hand landmarks detected
Solutions:
- Ensure good lighting
- Show your right hand (code configured for right hand)
- Keep hand within camera frame
- Try adjusting
min_detection_confidence(default: 0.5)
FPS: 8.5
Solutions:
- Close other applications
- Lower camera resolution (already optimized to 240x180)
- Reduce
max_num_handsto 1 (already set) - Check CPU usage
Solutions:
- Verify servo connections to correct GPIO pins
- Check power supply is connected and adequate (5V, 2A+)
- Test individual servos with Arduino examples
- Ensure serial baud rate matches (250000)
Solutions:
- Improve lighting conditions
- Keep hand steady
- Add smoothing filter (optional - uncomment filtering code)
- Increase
min_tracking_confidence
ModuleNotFoundError: No module named 'cv2'
Solutions:
pip install opencv-python
pip install mediapipe
pip install pyserial- Low Resolution: 240x180 camera capture
- High Frame Rate: 60 FPS camera setting
- Multi-Threading: Separate threads for camera and processing
- Minimal Buffer: Buffer size = 1 to reduce lag
- Conditional Updates: Servos update only when angles change
- Single Hand: Tracks max 1 hand for speed
# Increase confidence for faster but less sensitive tracking
min_detection_confidence=0.7
min_tracking_confidence=0.7
# Add smoothing filter
from scipy.signal import savgol_filter
angles_smooth = savgol_filter(angles, window_length=5, polyorder=2)- Left Hand Support: Add left hand tracking option
- Gesture Recognition: Detect specific gestures (peace sign, thumbs up, etc.)
- Wireless Control: Replace serial with WiFi/Bluetooth
- Both Hands: Control two robotic hands simultaneously
- Force Feedback: Add sensors to detect grip strength
- GUI Interface: Control panel with calibration options
- Recording Mode: Record and replay gesture sequences
- Machine Learning: Train custom gestures
robotic-hand-control/
β
βββ hand_tracking.py # Main Python hand tracking script
βββ esp32_servo_control.ino # ESP32 Arduino code
βββ requirements.txt # Python dependencies
βββ README.md # This file
β
βββ demo/ # Demo videos and images
β βββ demo_video.mp4
β βββ setup_photo.jpg
β
βββ docs/ # Additional documentation
β βββ wiring_diagram.png
β βββ calibration_guide.md
β
βββ 3d_models/ # 3D printable files (optional)
βββ robotic_hand.stl
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request