Finger Controller with Servo Motor.
Preview - How to work
Please find rotating propeller on image. It works by my fingers How it works : Detected? then control the motor
Prologue🤔
After I’ve learned how to send serial signal to arduino device, I wanted to make its application based on computer vision. but it should simple.
concept of serial communication
My idea was combining just like object detection and something could make any values from it.
Yes, nothing very special, but through this project I could understand and remind me of the logic again by making the application. Of course, It was very exciting that I could use computer vision tech in the same time.
Development Environment⚙️👨💻
- OS : Windows 11
- IDE : Visual Studio Code
- Languages : python, C(for arduino)
- Refered libraries:
Tasks and Key functions🛠️🖼️
[ Processing the tasks ]
- Detecting finger landmarks
- Calculating a distance between first and second finger.
- Sending the distance value to arduino.
- Controlling Servo motor communicating with the arduino based on the distance value.
[ Key functions ]
1. Detecting Finger Landmarks and Calculating the distance
- Refered
Hand landmark detection
ofMediaPipe
, You can also refer to this page and code. - It can detect each point of hand landmarks so that coordiante information of landmarks could be gained by the index.
- So I just picked the data of
4.THUMP_TIM
and8.INDEX_FINGER_TIP
to calculate its distance. - The value could be increased and decreased when I enlarge and narrow down two fingers, just like zoooming in and out the photos on my iphone.
Index of hand landmark by mediapipe Anyway, now I could use this value to control servo motor integrated in a breadboard. easy.
2. Sending the distance value to arduino by serial communication protocol.
- This is kind of the protocol, you can refer this article.
- Even though I used encapsulated library
cvzone
, I could find the origin and the process to handle serial communication.
arduino code on the deivce
-
SerialData
defined inino
file, hasGet
method.1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <cvzone.h> SerialData serialData(1, 3); //(numOfValsRec,digitsPerValRec) ... void setup() { ... serialData.begin(); ... } ... void loop() { ... serialData.Get(valsRec); ... }
- I could assume that it is related with commonly used library
Serial
in arduino.read method of
Serial
python code in host device
-
senddata
one of methods fromcvzone
is actually referingwrite
method ofpyserial
.
1
2
3
4
5
6
7
8
from cvzone.SerialModule import SerialObject
arduino = SerialObject()
...
def send_int_toArduino(self, dist):
arduino.sendData([dist])
...
3. Integrating Servo motor and make it move with the distance value.
The board looks like this.. bread board setup
- By using
Servo
libary, servo motor can communicatig with arduino and rotating the wheel. - In the codes, I attached it to a specific pin of arduino, And wrote the distance depend on my finger movement.
- What I found about adjustable angle range, It ranges from 0 to 179 degree.(correct me if i’m wrong 😅)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(servoOutPin);
...
}
void loop() {
...
myServo.write(dist_servo);
...
}
Details of the code(Github) ⚙️
Let’s keep make tiny projects. See ya.🤖