Project tutorial
GamePad using Android mobile sensors and Arduino

GamePad using Android mobile sensors and Arduino

Play video games on your laptop using your phone as a gamepad

  • 6,705 views
  • 7 comments
  • 15 respects

Components and supplies

About this project

//www.youtube.com/embed/EG_SuqxBBjE?theme=light&color=red

All we need from the mobile phone is its rotation to change direction and pressing one of 2 buttons to check whether forward or backward. To get the orientation of the mobile you can use either the gyro sensor or the gravity sensor. Yet, I used the gravity since I found it more stable in the readings or you can use as well the Orientation shield in the application which is based on gyro. We will use the Keyboard Library of Arduino to take the action as if it is the real keyboard, so that's the reason we need Arduino Leonardo or any one support this library.

From the Keyboard Library, you have got that: 

KEY_UP_ARROW 0xDA 218

KEY_DOWN_ARROW 0xD9 217

KEY_LEFT_ARROW 0xD8 216

KEY_RIGHT_ARROW 0xD7 215

Here you will find the code:

https://codebender.cc/sketch:53866

After Uploading the code, open your Mobile Application, you have to pair the 1Sheeld with the mobile using Bluetooth. Then choose the Gravity shield and the Game pad shield from the application and then click next.

Now you can move the car using the upper and lower bottoms and by rotating the mobile you can change direction of the car left or right.


Code

Untitled fileArduino
#include <OneSheeld.h>

void setup() 
{
  OneSheeld.begin();
  Serial.begin(9600);
  Keyboard.begin();
}

void loop() 
{
  if (GamePad.isUpPressed())
  {Keyboard.press(0xDA);}
  else
  {Keyboard.release(0xDA);}
  
 if(GamePad.isDownPressed())
  {Keyboard.press(0xD9);}
  else
  {Keyboard.release(0xD9);}

 if (GravitySensor.getY() < -1)
  {Keyboard.press(0xD8);}
  else{Keyboard.release(0xD8);}
  
 if (GravitySensor.getY() > 1)
  {Keyboard.press(0xD7);}
  else
  {Keyboard.release(0xD7);}
  
  if (GamePad.isGreenPressed())
  {Keyboard.press(0x80);}
  else
  {Keyboard.release(0x80);}
  //delay(30);
  
}
Codebender
https://codebender.cc/sketch:53866

Comments

Created by

Ashraf Nabil

Are you Ashraf Nabil? Claim this project and add it to your profile.

This is mine

Posted by

Amrousy
Amr Saleh
  • 3 projects
  • 50 followers

Published on

November 19, 2014

Members who respect this project

PhotoUntitled 211825847 832623906854899 5433167265337580769 nDefaultMachoteDefault19060093 1919335755008185 2688611279129114234 nDefault

and 10 others

See similar projects
you might like

Similar projects you might like

Skype Mobile

Project tutorial by Guest

  • 1,111 views
  • 0 comments
  • 3 respects

Unlock your door with a knock

Project tutorial by Ashraf Nabil

  • 24,325 views
  • 15 comments
  • 64 respects

Create Mobile Apps for Android and iOS Connecting to the MKR

Project tutorial by Chandana Pathirage

  • 6,019 views
  • 4 comments
  • 16 respects

Universal Remote Control

Project tutorial by Ashraf Nabil

  • 3,540 views
  • 0 comments
  • 12 respects

Control Robot Arm with your Android Phone

Project tutorial by Ammar Atef Ali

  • 11,308 views
  • 0 comments
  • 24 respects

4x4x4 LED cube with Arduino Uno and 1sheeld

Project tutorial by Hassan Ibrahim

  • 30,960 views
  • 7 comments
  • 61 respects
Add projectSign up / Login