Drone Coding
Drone Coding
pinMode(trigger1, OUTPUT);
pinMode(echo1, INPUT);
pinMode(trigger2, OUTPUT);
pinMode(echo2, INPUT);
}
We need to calculate the distance between the Sensor and the hand each time before
concluding on any action. So we have to do it many times, which means this code
should be used as a function. We have written a function named calculate_distance()
which will return us the distance between the sensor and the hand.
Inside our main loop we check for the value of distance and perform the actions
mentioned above. Before that we use two variables distL and distR which gets
updated with current distance value.
calculate_distance(trigger1,echo1);
distL =dist; //get distance of left sensor
calculate_distance(trigger2,echo2);
distR =dist; //get distance of right sensor
Since we know the distance between both the sensors, we can now compare it with
predefined values and arrive at certain actions. For example if both the hands are
placed at a distance of 40 mc then we play/pause the video. Here the word
�Play/Pause� will be sent out through serial port
if ((distL >40 && distR>40) && (distL <50 && distR<50)) //Detect both hands
{Serial.println("Play/Pause"); delay (500);}
If the Right hand alone is placed before the module then we fast forward the video
by one step and if it is left hand we rewind by one step. Based on the action, here
the word �Rewind� or �Forward� will be sent out through serial port
if ((distL >40 && distL<50) && (distR ==50)) //Detect Left Hand
{Serial.println("Rewind"); delay (500);}
if ((distR >40 && distR<50) && (distL ==50)) //Detect Right Hand
{Serial.println("Forward"); delay (500);}
Foe detailed control of volume and track we use a different methodology so as to
prevent false triggers. To control the volume we have to place the left hand
approx. At a distance of 15 cm , then you can either move it towards the sensor to
decrease the volume of move it away from the sensor to increase the volume. The
code for the same is shown below. Based on the action, here the word �Vup� or
�Vdown� will be sent out through serial port
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.
Follow the below steps to install pyautogui for windows. If you are using other
platforms the steps will also be more or less similar. Make sure your
computer/Laptop is connected to internet and proceed with steps below
Step 1: Open Windows Command prompt and change the directory to the folder where
you have installed python. By default the command should be
cd C:\Python27
Step 2: Inside your python directory use the command python �m pip install �upgrade
pip to upgrade your pip. Pip is a tool in python which helps us to install python
modules easily. Once this module is upgraded (as shown in picture below) proceed to
next step.