Introduction
In this project, we are going to make a simple hand gesture control device using Arduino Leonardo and some IR sensors.
We can implement any controls of our PC or mobile phone by just the movement of our hands. What I here made is only just a scratch on the endless possibilities of gesture control. Soon we are going to make a fully functional game control أن شاء الله so be tuned.
Concept
We are using Arduino keyboard library to convert the inputs from IR obstacle sensor to keystrokes for controlling the car in NFS game,
- When the top right and top left sensors are trigged then it will simulate up arrow key.
- When the down right and down left sensors are trigged then it will simulate down arrow key.
- When the top right and
down right sensors are trigged then it will simulateright arrow key. - When the down left and top left sensors are trigged then it will simulate
left arrow key.
Hardware Used
Components | Amazon.in![]() | Amazon.com![]() | Banggood![]() | AliExpress![]() | Utsource![]() |
Arduino Leonardo | ![]() | ![]() | ![]() | ![]() | ![]() |
IR obstacle sensor | ![]() | ![]() | ![]() | ![]() |

Circuit description
Arrange the sensors on the 4 corners of the Leonardo board as shown in the figure in the video. Connect all the VCC of the IR sensor modules to the 3.3 v or 5v of the Leonardo and connect the ground of all the four sensors to the ground of the Arduino,

Output pin of IR sensor | Arduino Leonardo |
Sensor 1 | digital pin 11 |
Sensor 1 | digital pin 9 |
Sensor 1 | digital pin 12 |
Sensor 1 | digital pin 10 |
Watch The Video – Playing NFS

Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
//gesture control #include <Keyboard.h> int up_right = 9; int up_left = 11; int down_right = 10; int down_left = 12; bool up_right_state; bool down_right_state; bool down_left_state; bool up_left_state; void setup() { Keyboard.begin(); Serial.begin(9600); pinMode(up_right, INPUT); pinMode(up_left, INPUT); pinMode(down_right, INPUT); pinMode(down_left, INPUT); } void loop() { up_right_state = digitalRead(up_right); up_left_state = digitalRead(up_left); down_right_state = digitalRead(down_right); down_left_state = digitalRead(down_left); Serial.print(up_right_state); Serial.print(up_left_state); Serial.print(down_right_state); Serial.println(down_left_state); if (digitalRead(up_left) == 0 && digitalRead(up_right) == 0) while ((digitalRead(up_left) == 0 && digitalRead(up_right) == 0)) { Serial.println("move up"); Keyboard.press(KEY_UP_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(down_left) == 0 && digitalRead(down_right) == 0 ) while ((digitalRead(down_left) == 0 && digitalRead(down_right) == 0 ) ) { Serial.println("move down"); Keyboard.press(KEY_DOWN_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(down_left) == 0 && digitalRead(up_left) == 0 ) while (digitalRead(down_left) == 0 && digitalRead(up_left) == 0 ) { Serial.println("move left"); Keyboard.press(KEY_LEFT_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(up_right) == 0 && digitalRead(down_right) == 0) while (digitalRead(up_right) == 0 && digitalRead(down_right) == 0) { Serial.println("move right"); Keyboard.press(KEY_RIGHT_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(up_right) == 0 && digitalRead(down_right) == 1 && digitalRead(down_left) == 1 && digitalRead(up_left) == 1) while (digitalRead(up_right) == 0 && digitalRead(down_right) == 1 && digitalRead(down_left) == 1 && digitalRead(up_left) == 1) { Serial.println("move right up corner"); Keyboard.press(KEY_RIGHT_ARROW); Keyboard.press(KEY_UP_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(up_left) == 0 && digitalRead(down_right) == 1 && digitalRead(up_right) == 1 && digitalRead(down_left) == 1) while (digitalRead(up_left) == 0 && digitalRead(down_right) == 1 && digitalRead(up_right) == 1 && digitalRead(down_left) == 1) { Serial.println("move left up corner"); Keyboard.press(KEY_LEFT_ARROW); Keyboard.press(KEY_UP_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(down_left) == 0 && digitalRead(up_right) == 1 && digitalRead(up_left) == 1 && digitalRead(down_right) == 1 ) while (digitalRead(down_left) == 0 && digitalRead(up_right) == 1 && digitalRead(up_left) == 1 && digitalRead(down_right) == 1 ) { Serial.println("move left down corner"); Keyboard.press(KEY_LEFT_ARROW); Keyboard.press(KEY_DOWN_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } if (digitalRead(down_right) == 0 && digitalRead(up_right) == 1 && digitalRead(up_left) == 1 && digitalRead(down_left) == 1) while (digitalRead(down_right) == 0 && digitalRead(up_right) == 1 && digitalRead(up_left) == 1 && digitalRead(down_left) == 1) { Serial.println("move right down corner"); Keyboard.press(KEY_RIGHT_ARROW); Keyboard.press(KEY_DOWN_ARROW); delay(100); Keyboard.releaseAll(); Keyboard.end(); } } |
You Might Also Like…
To buy electronic components order from UTSOURCE
We need slides and documents for presentation of this project will you plz help us?
Yes I would like to , Please send and email to [email protected] regarding your query