This project uses hand gesture detection with a webcam to recognize finger positions and control an Arduino-based LED and buzzer system. The system simulates a traffic signal/pedestrian detection system by interpreting different finger counts as traffic control signals.
- π€ Real-time Hand Detection: Uses MediaPipe for accurate hand tracking
- πΉ Webcam Input: Real-time video feed processing with OpenCV
- π‘ LED Control: 5 LEDs controlled based on finger count
- π Buzzer Feedback: Audio alerts for hand detection and gestures
- π‘ Serial Communication: Arduino communication via USB/COM port
- π¦ Traffic Signal Simulation: Different finger counts represent different signals
| Component | Arduino Pin | Description |
|---|---|---|
| LED 1 | Pin 8 | For 5 fingers (STOP) |
| LED 2 | Pin 9 | For 4 fingers (Pedestrian Lane) |
| LED 3 | Pin 10 | For 3 fingers (GO) |
| LED 4 | Pin 11 | For 2 fingers (Slow Down) |
| LED 5 | Pin 12 | For 1 finger (Warning) |
| Buzzer | Pin 6 | Audio alert (1200Hz for hand detection, 500Hz for no fingers) |
| Fingers | Signal | LED | Buzzer | Status |
|---|---|---|---|---|
| 0 | No one manage | OFF | 500Hz (300ms) | Error state |
| 1 | Warning | LED at Pin 12 | Silent | Caution |
| 2 | Slow Down | LED at Pin 11 | Silent | Reduced speed |
| 3 | GO | LED at Pin 10 | Silent | Safe to proceed |
| 4 | Pedestrian Lane Walking | LED at Pin 9 | Silent | Pedestrian mode |
| 5 | STOP | LED at Pin 8 | Silent | All stop |
- Arduino Board (Uno, Mega, or compatible)
- Webcam (USB camera)
- Python 3.7 or later
- Windows, macOS, or Linux
- USB Cable (for Arduino communication)
- Connect your Arduino board to your computer via USB cable
- Open Arduino IDE
- Select the board type: Tools β Board β Arduino Uno (or your board type)
- Select the COM port: Tools β Port β COM4 (check which COM port Arduino uses)
# Navigate to the project directory
cd "C:\Users\Sam Nahutdo\Desktop\samnahutdo\MS101"
# (Optional) Create a virtual environment
python -m venv venv
venv\Scripts\activate # On Windows
# Install required modules
pip install opencv-python
pip install mediapipe
pip install pyserialIf you don't have Python installed, download it from https://www.python.org/downloads/ and make sure to check "Add Python to PATH" during installation.
- Open Arduino IDE
- Open the sketch file: Arduino.cpp
- Upload to Arduino:
- Click Upload button (or Ctrl+U)
- Wait for "Done uploading" message
The Arduino.cpp file is already in the correct Arduino format. Here's how to compile and upload it:
- Open Arduino IDE
- File β Open β Select Arduino.cpp
- Verify Code (Ctrl+R)
- This compiles the code and checks for errors
- Upload (Ctrl+U)
- Compiles and uploads the code to the Arduino board
- Wait for the message:
"Avrdude done. Thank you."
- Check Serial Monitor (Tools β Serial Monitor)
- Set Baud Rate to 9600
- Should show connection messages
-
Open Command Prompt or PowerShell
-
Navigate to project directory:
cd "C:\Users\Sam Nahutdo\Desktop\samnahutdo\MS101"
-
Activate virtual environment (if created):
venv\Scripts\activate
-
Run the Python script:
python main.py
-
What happens:
- Webcam window opens with live hand detection
- Green text = Hand detected
- Red text = No hand detected
- LEDs light up based on finger count
- Press ESC to exit the program
# OpenCV - For video capture and image processing
pip install opencv-python
# MediaPipe - For hand landmark detection
pip install mediapipe
# PySerial - For Arduino communication
pip install pyserialTest that modules are installed correctly:
python -c "import cv2; print('OpenCV OK')"
python -c "import mediapipe; print('MediaPipe OK')"
python -c "import serial; print('PySerial OK')"All three should print "OK" messages.
- Upload fails: Check COM port is correct (Tools β Port)
- No serial connection: Reinstall Arduino USB drivers
- LEDs don't light up: Check pin connections and power supply
- "ModuleNotFoundError": Run
pip installcommands again - Webcam not working: Check webcam is not in use by another program
- Serial port busy: Close Arduino IDE or other serial apps
- Change COM port: Edit
main.pyline 9:serial.Serial(port='COM4', ...)to your port
- Hand not detected: Ensure good lighting and clear hand visibility
- Fingers not detected: Make sure hand is fully in frame with fingers extended
MS101/
βββ Arduino.cpp # Arduino microcontroller code
βββ main.py # Python hand detection & control script
βββ README.md # This file
βββ pic1.png # Project photo 1
βββ pic2.png # Project photo 2
βββ pic3.png # Project photo 3
-
Python Side (main.py):
- Captures video from webcam
- MediaPipe analyzes hand landmarks
- Detects which fingers are extended
- Sends finger states to Arduino via serial port (9600 baud)
-
Arduino Side (Arduino.cpp):
- Receives 5 bytes representing finger states (0 or 1)
- Counts how many fingers are detected
- Controls LEDs inversely (5 fingers β LED pin 8, 1 finger β LED pin 12)
- Triggers buzzer on hand detection or when no fingers are found
Laptop (Python)
β USB Cable
Arduino Uno
βββ Pin 8 β LED 1
βββ Pin 9 β LED 2
βββ Pin 10 β LED 3
βββ Pin 11 β LED 4
βββ Pin 12 β LED 5
βββ Pin 6 β Buzzer
βββ GND β Ground connection
- The project uses inverse LED mapping (5 fingers lights LED at pin 8, 1 finger lights LED at pin 12)
- Buzzer plays two 1200Hz beeps when hand is first detected
- Serial communication runs at 9600 baud rate
- Ensure Arduino and Python are synchronized on the same COM port
Sam Nahutdo
MS101 Project - Hand Gesture Recognition Traffic Control System
This project is for educational purposes.
yes yes yes
jcbercebicbeibve dd oh damn dawg
this must b echange
chdcuhc


