Make your controllers for any game using Arduino

0
11332
Build game controllers using Arduino

 

Nowadays, we have lots of game controllers that are improving the gaming experience over the years. There are number of factors responsible for a game to get a good fan base. Graphics quality, story line, the way in which user interacts with the game etc., Gaming experience can be improved to a good extent with the help of controllers, but these controllers are quite expensive. Have you ever thought of making your own controllers for games? This project takes you through a series of simple steps to help you make your own game controller using Arduino for any games you want to play. This project designs a throttle system for Microsoft flight simulator.

Arduino to build game controls

 The first image is the game controller using Arduino, designed for flight simulator. It has a throttle system, control switches (Lights, landing gear control, APU Switches and seat-belts ON/OFF).

The concept of a game controller

This project explains the concept of the game controller with help of a flight simulator game. In this game, to speed up the flight that to increase the engine speed we use F3 key for gradual set by step increase or F4 key for max throttle and F2 for gradual step by step decrease or F1 for Idle throttle. We are going to programmatically trigger the corresponding keys based on some conditions.

This project uses an ULTRASONIC SENSOR to measure the distance between the sensor and the obstacle (say a cardboard box) in front of it. We use an Arduino board to get the distance value and send it in serial to pc in a specific COM port. In order to program the Arduino we need Arduino IDE.

Distance (unit inches) – Approximately 73.7 microseconds per inch (i.e. sound travels at 1130 feet per second).  This gives the distance travelled by the wave from the sensor to the obstacle and again back to sensor, so we divide by 2 to get the distance of the obstacle.

The HC-SR04 module produces a duration in microseconds as the output that the time taken to receive the echo. The following convention is used to convert the distance (inches) in place of duration:

Distance = duration / 74 / 2

Next we design a small application that reads this serial value and programmatically triggers the keys based on the following condition.

if past distance < new distance (this condition is satisfied is the obstacle is moved towards the sensor)

tigger F3

else if past distance > new distance (this condition is satisfied if the obstacle is moved away from the sensor)

trigger F2

else if new distance > max_idle_limit

trigger F1 key once and release all the keys

else if new_distance <= max_speed_limit

trigger F4 once and release all the keys

else (i.e. when the past = new distance)

there is no movement

release all the keys

The above conditions are tested for each and every distance value sent by the Arduino board in serial port. This application should run in parallel to the game for which the controller is designed.

flowchart for game controller using arduino

Components and software required

  • Arduino: This project uses Arduino UNO R3. If you have Arduino Leonard/Due board then there is no need to make the software in C# since the board has its own keyboard libraries for triggering keys.
  • Ultrasonic Sensor HC-SR04
  • Jumper Wires
  • Arduino IDE
  • Visual Studio IDE

Circuit diagram

  • circuit diagram for game controller using arduinoArduino Board pin 7 – Echo Pin Ultrasonic Sensor
  • Arduino Board pin 6 – Triger Pin Ultrasonic Sensor
  • 5V – Vcc of Ultrasonic sensor
  • Gnd pin to GND of ultrasonic sensor

If you want to add more functionalities to the game, add some toggle switches and button to some other pins and you can listen and respond to them by treating them as interrupts. But now lest don’t complicate this ill just take you through the basic setup.

Arduino boards are available for purchase on kitsNspares.com.

This article was first published in electronicsforu.com.

LEAVE A REPLY

Please enter your comment!
Please enter your name here