Devices & Components
Arduino Uno Rev3
SG90 Micro-servo motor
USB-A to Mini-USB Cable
Jumper wires (generic)
Software & Tools
Arduino IDE
Pycharm IDE
Project description
Code
Arduino Code
c_cpp
1// we first import our libraries 2 3#include "cvzone.h" // this help us to communicate with python over the serial com port 4 5#include "Servo.h" 6Servo servo; // create our servo object 7SerialData data(1,3); // create our serial object 8int value[2]; //create an array to store our received values 9 10void setup () { 11 12 data.begin(9600); // begin our serial communication 13 servo.attach(9);* // connect our servo pin 14} 15 16void loop () { 17 data.Get(value); // read the value from python and store it in value 18 servo.write(value[0]); // since our received value is an array, we only accept the first value since only one servo is attached 19 20 delay(30); // delay for 30 milli seconds 21 22 // All done 23 // lets move to python 24} 25
Python code
python
1# for recording or capturing feed from web cam 2import cv2 3 4#need 5 for our hand detection 6from cvzone.HandTrackingModule import HandDetector 7 8from 9 cvzone.SerialModule import SerialObject 10 11# initialize our camera 12cap = 13 cv2.VideoCapture(0) 14 15# set our hand tracking object 16detector = HandDetector(detectionCon=0.8) 17arduino 18 = SerialObject("COM3") # Select your own com port here 19 20 21# start our 22 while loop 23while True: 24 success, image = cap.read() 25 hands, bboxInfo 26 = detector.findHands(image) 27 if len(hands)==1: 28 print(detector.fingersUp(hands[0])) 29 30 if detector.fingersUp(hands[0]) == [0,1,0,0,0]: 31 arduino.sendData([180]) 32 33 else: 34 arduino.sendData([0]) 35 36 cv2.imshow('image',image) 37 cv2.waitKey(1)
Python code
python
1# for recording or capturing feed from web cam 2import cv2 3 4#need for our hand detection 5from cvzone.HandTrackingModule import HandDetector 6 7from cvzone.SerialModule import SerialObject 8 9# initialize our camera 10cap = cv2.VideoCapture(0) 11 12# set our hand tracking object 13detector = HandDetector(detectionCon=0.8) 14arduino = SerialObject("COM3") # Select your own com port here 15 16 17# start our while loop 18while True: 19 success, image = cap.read() 20 hands, bboxInfo = detector.findHands(image) 21 if len(hands)==1: 22 print(detector.fingersUp(hands[0])) 23 if detector.fingersUp(hands[0]) == [0,1,0,0,0]: 24 arduino.sendData([180]) 25 else: 26 arduino.sendData([0]) 27 cv2.imshow('image',image) 28 cv2.waitKey(1)
Downloadable files
Servo motor circuit connection
Servo pin attached to pinMode 9
Servo motor circuit connection

Servo motor circuit connection
Servo pin attached to pinMode 9
Servo motor circuit connection

Comments
Only logged in users can leave comments