Project tutorial

Playing NFS By Hand Gesture Control © GPL3+

Hand gesture control using Arduino Leonardo and IR sensors.

  • 5,231 views
  • 3 comments
  • 25 respects

Components and supplies

About this project

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 control of our PC or mobile phone using just the movement of our hands. What I made here only scratches the surface on the endless possibilities of gesture control.

Concept

We are using Arduino keyboard library to convert the inputs from IR obstacle sensor to key strokes 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.

Circuit Description

Arrange the sensors on the four 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 and connect the output pins of sensor to the following Arduino digital pins.

Sensor 1 to digital pin 11

Sensor 2 to digital pin 9

Sensor 3 to digital pin 12

Sensor 4 to digital pin 10

testing - simple application with Adobe Flash

Working Video

Playing Need For Speed :)

Code

gesture_control.inoC/C++
//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();
    }



}

Schematics

gesture_control_schem_YfmDSB3pZl.jpg
Gesture control schem yfmdsb3pzl

Comments

Similar projects you might like

Gesture Control Robot

Project tutorial by Raunak Oberai

  • 6,179 views
  • 8 comments
  • 21 respects

Control Your Computer With A Remote Control

Project tutorial by Arduino_Scuola

  • 5,942 views
  • 1 comment
  • 8 respects

Unlock Your Door With a Hand Gesture

Project tutorial by AdhamN

  • 1,536 views
  • 0 comments
  • 5 respects

Hand Gesture Controlled Robot

Project tutorial by Mayoogh Girish

  • 54,948 views
  • 78 comments
  • 65 respects

Amazing Control Computer Using Hand Motion And Arduino

Project tutorial by Smart Technology

  • 4,948 views
  • 12 comments
  • 10 respects
Add projectSign up / Login