Hand Gesture control using Arduino

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 simulate right arrow key.
  • When the down left and top left sensors are trigged then it will simulate left arrow key.

Hardware Used

ComponentsAmazon.inamazonAmazon.comamazonBanggoodbanggoodAliExpressali expressUtsource
utsource logo
Arduino Leonardocart iconcart iconcart iconcart iconcart icon
IR obstacle sensorcart iconcart iconcart iconcart icon

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,

arduino gesture control
Output pin of IR sensor  Arduino Leonardo
Sensor 1digital pin 11
Sensor 1digital pin 9
Sensor 1digital pin 12
Sensor 1digital pin 10

Watch The Video – Playing NFS

Code


//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

2 thoughts on “Hand Gesture control using Arduino”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top