Hand Gesture Controlled Servo Using Python & Arduino
AI arduino project controlled by hand
Component | Description |
Arduino Uno | The microcontroller board for processing data. |
Webcam | Captures real-time video for face detection. |
LED | Lights up when a face is detected. |
220-ohm resistor | Protects LED from excessive current. |
Jumper wires | Used for wiring connections. |
Computer | Runs the Python script. |
Library | Installation Command | Purpose |
OpenCV | pip install opencv-python | Used for image processing. |
MediaPipe | pip install mediapipe | Detects hand gestures. |
PySerial | pip install pyserial | Enables communication between Python & Arduino. |
Software | Installation Link | Purpose |
Python (pip) | Download Python | Runs the hand tracking script. |
Arduino IDE | Download Arduino IDE | Uploads code to the Arduino board. |
VS Code | Download VS Code | Code editor for Python and Arduino. |
pip install opencv-python pyserial
int ledPin = 13; // LED connected to pin 13
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
if (Serial.available() > 0) {
// Read the incoming byte
char command = Serial.read();
if (command == '1') {
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Face Detected: LED ON");
} else if (command == '0') {
digitalWrite(ledPin, LOW); // Turn off LED
Serial.println("No Face Detected: LED OFF");
}
}
}
import cv2
import serial
import time
# Set up serial communication (make sure to use the correct COM port for your system)
arduino = serial.Serial('COM9', 9600) # Replace with the correct port for your system
time.sleep(2) # Wait for Arduino to initialize
# Load the face cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Start capturing video
cap = cv2.VideoCapture(0)
while cap.isOpened():
_, img = cap.read()
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
# If faces are detected, send '1' to Arduino, else send '0'
if len(faces) > 0:
arduino.write(b'1') # Send '1' to indicate face detected
print("Face detected")
else:
arduino.write(b'0') # Send '0' to indicate no face detected
print("No face detected")
# Draw rectangles around the faces
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 3)
# Display the image
cv2.imshow('img', img)
# Exit on pressing 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the video capture and close the serial port
cap.release()
arduino.close()
cv2.destroyAllWindows()
Our Completed Projects
AI arduino project controlled by hand
إصلاح الأجهزة التقنية
روح المثابرة ومحبة العلم
إن فضولي العميق للمعرفة، بالإضافة إلى قدرتي القوية على التعلم الذاتي، ساهم بشكل كبير في تشكيل شخصيتي القوية ومتعددة المواهب في مختلف المجالات.