Shourya wadhwa
Published © GPL3+

How to make Arduino gamepad

Let's learn to make Arduino gamepad or controller to play games or even automate them

BeginnerFull instructions provided1 hour1,630
How to make Arduino gamepad

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
You can go for any board u like
×1
Resistor 10k ohm
Resistor 10k ohm
Any resistor above 500 ohms
×2
Push button
×2
Jumper wires (generic)
Jumper wires (generic)
You will need 1 set of this wire
×1

Software apps and online services

Processing
The Processing Foundation Processing
This is for game control
Arduino IDE
Arduino IDE
This is for game commands

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

Gamepad Schematics or how to connect wires to arduino

This is the circuit to connect wires to Arduino and breadboard so u have a gamepad ready

Code

Arduino code

Arduino
This is code for Arduino u have to play on Arduino ide
const int UpButton = 9;//9 and 11 pins both only work as per circuit rest are not working as per circuit
const int DownButton = 11;
const int LeftButton = 10;
const int RightButton = 8;
void setup(){
   Serial.begin(9600);
   pinMode(UpButton, INPUT);
   pinMode(DownButton, INPUT);
   pinMode(LeftButton, INPUT);
   pinMode(RightButton, INPUT);
} 
void loop(){
    if(digitalRead(UpButton) == HIGH){
  //for(int i; i < 10; i++){ (this code is for to click button once but run the player 10 times ps: delete this line only not for int etc u understand)
    Serial.println("Up:");
    delay(1);
    }
   //}
    if(digitalRead(DownButton) == HIGH){
    //for(int i; i < 10; i++){
    Serial.println("Down:");
    delay(1);
    //break;
    }
   //}
    if(digitalRead(LeftButton) == HIGH){
    //for(int i; i < 10; i++){ 
    Serial.println("Left:");
    delay(1);
    //break;
    }
   //}
    if(digitalRead(RightButton) == HIGH){
    //for(int i; i < 10; i++){
    Serial.println("Right:");
    delay(1);
    //break;
    }
   //}
}

Processing code

Processing
This processing code edit with your needs
import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
Serial MyPort;                                
String KeyString = "";
void setup()
{
  System.out.println("Hi");
  size(700, 500);
  MyPort = new Serial(this, "COM3", 9600);// My Arduino is on COM3. Enter the COM on which your Arduino is on.
  MyPort.bufferUntil('\n');
}
void draw(){//Not really necessary
  background(0, 0, 0);
  fill(255, 10, 0);
  text("Press any key this is non interactable screen open game or browser to test", 100, 175);
}
void serialEvent(Serial MyPort)throws Exception {
   KeyString = MyPort.readStringUntil('\n');
   KeyString = KeyString.substring(0, KeyString.indexOf(':'));//The string is split. the whole string leaving the colon is taken
   System.out.println(KeyString);//prints the serial string for debugging purpose
   Robot Arduino = new Robot();//Constructor of robot class
   switch(KeyString){
     case "Up" :
       Arduino.keyPress(KeyEvent.VK_W);//presses up key.
         delay(5);
       Arduino.keyRelease(KeyEvent.VK_W);//releases up key
       break;
     case "Down" :
       Arduino.keyPress(KeyEvent.VK_S);/// CHANGE ACCORIND TO YOUR NEEDS more info here https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
        delay(5);
       Arduino.keyRelease(KeyEvent.VK_S);
       break;
      case "Right" :
       Arduino.keyPress(KeyEvent.VK_D);
        delay(5);                                                                                                              
       Arduino.keyRelease(KeyEvent.VK_D);
       break;
      case "LEFT" :
       Arduino.keyPress(KeyEvent.VK_A);
        delay(5);
       Arduino.keyRelease(KeyEvent.VK_A);      
       break;
   }
   
}

Credits

Shourya wadhwa
0 projects • 0 followers
Hi, guys, this is the official account for sourceboxtv and its youtube channel so go and subscribe to it. I like to make iot stuff, code etc

Comments