We just have to establish a serial communication with Arduino through the correct baud rate and then perform some basic keyboard actions. The python program for this project is very simple.
You can now read over the complete code for this gesture controlled PC given at the end of the page and try understating it as an whole and then copy it to your Arduino IDE. Based on the action, here the word “Rewind” or “Forward” will be sent out through serial port
That is if we move the right hand towards the sensor it will fast forward the movie and if you move it away from the sensor it will rewind the movie. We can use the same method for the right side sensor also, to control the track of the video. Here the word “Play/Pause” will be sent out through serial port For example if both the hands are placed at a distance of 40 mc then we play/pause the video. Since we know the distance between both the sensors, we can now compare it with predefined values and arrive at certain actions. Before that we use two variables distL and distR which gets updated with current distance value.ĭistL =dist //get distance of left sensorĭistR =dist //get distance of right sensor Inside our main loop we check for the value of distance and perform the actions mentioned above. Void calculate_distance(int trigger, int echo) We have written a function named calculate_distance() which will return us the distance between the sensor and the hand. So we have to do it many times, which means this code should be used as a function. We need to calculate the distance between the Sensor and the hand each time before concluding on any action.
The Serial communication between Arduino and python takes places at a baud rate of 9600.Ĭonst int trigger1 = 2 //Trigger pin of 1st SesnorĬonst int echo1 = 3 //Echo pin of 1st SesnorĬonst int trigger2 = 4 //Trigger pin of 2nd SesnorĬonst int echo2 = 5 //Echo pin of 2nd Sesnor
The trigger pins are output pin and Echo pins are input pins. The two US sensors are connected to Digital pins 2,3,4 and 5 and are powered by +5V pin. So, like all programs we start with defining the I/O pins as shown below. Let us see how the program is written to perform the above actions. If you are new to Ultrasonic sensor, just go through Arduino & Ultrasonic Sensor Based Distance Measurement.īy reading the value of distance we can arrive at certain actions to be controlled with gestures, for example in this program I have programmed 5 actions as a demo.Īction 1: When both the hands are placed up before the sensor at a particular far distance then the video in VLC player should Play/Pause.Īction 2: When right hand is placed up before the sensor at a particular far distance then the video should Fast Forward one step.Īction 3: When left hand is placed up before the sensor at a particular far distance then the video should Rewind one step.Īction 4: When right hand is placed up before the sensor at a particular near distance and then if moved towards the sensor the video should fast forward and if moved away the video should Rewind.Īction 5: When left hand is placed up before the sensor at a particular near distance and then if moved towards the sensor the volume of video should increase and if moved away the volume should Decrease. The complete program is given at the end of this page just below I have given the explanation for the program. The Arduino should be programmed to read the distance of hand from the US sensor. After securing it in a place we can proceed with the Programming. I have used a double side tape to stick it on my monitor but you can use your own creativity. Once the connections are done place them on your monitor as shown below. The Arduino can be connected to the PC/Laptop for powering the module and also for Serial communication. We know US sensor work with 5V and hence they are powered by the on board Voltage regulator of Arduino.
To control the PC with Hand Gestures, just connect the two Ultrasonic sensors with Arduino.