L O A D I N G
blog banner

Build your own Gyroscope Controlled Game with Arduino Nano and Processing in just $5

Greetings folks, this post will be about developing your own game with the help of a Gyroscope sensor and an Arduino Nano using Arduino IDE and Processing 3. For those who don’t have any idea about what processing is, do check out Daniel Shiffman’s YouTube channel “The Coding Train” as it has great tutorials based on Processing 3, Processing JS (which is very helpful in developing web applications and games), ML5.js (For integrating Machine Learning on the Web). His tutorials are very easy to understand, even if you’re a beginner in the big bad world of programming. For the starters, you can start learning Processing either from Daniel Shiffman’s Tutorials or by reading the documentation.

If you’re already familiar with Processing or you just wanna skip the Processing part and just wanna jump straight towards playing with the Processing and Arduino code, you can keep reading ahead. In this tutorial, I’ll be explaining to you my Gyroscope Game Project named “Gyro-Drive” and how to run it. To understand the code, you can go through the comments and feel free to play with it, but don’t get carried away!

For the starters, download and install Processing 3 from this link and Arduino IDE from here, if you don’t have it in your PC already. Also, connect the hardware in this manner:

Image result for gyroscope sensor analog gy 61
Scene 1 of Gyro-Game

Firstly, the ‘gyro_game’ folder contains 5 .pde files, which is nothing but the extension for Processing and a folder, which consists of a .ino file, which is the extension for Arduino. Here are the attributes of every file:

  • Camera.pde file is just for moving the camera around with our car.
  • Game_1.pde file contains the code for the Serial communication between Arduino and Processing. It is required for loading all the scenes and looping them throughout the program as required.
  • Scene1.pde file contains the layout and design for the introductory scene or the first page of my game.
  • Scene2.pde contains the code for main part of the game, where we have to get the car moving and it contains the code for all the obstacles, reducing the score whenever there’s an encounter with the obstacles or whenever the car gets into the sandy area.
  • Scene3.pde contains the code for final conclusion of the calculated score.
  • Rest of the files are just background or sprite images.
Scene 2 of Gyro-Drive

Secondly, in the case of Arduino, I’ve taken the Analog data from the X-axis of the GY-61 Gyroscope Sensor and with the help of Serial communication, Processing reads that data from that specific COM Port and with that particular data, I’ve mapped it with the suitable dimensions in the game using the map() function.

Gyro-Game Gameplay

That’s it for today, folks and feel free to play with the code and use it for the society. I know that it’s just a game but Gyroscope sensors have a lot of applications, while some of them might be helpful towards humanity and why not turn out a profitable business out of it, if it can help the people of our society and might as well benefit you?

If you’ve read this far, I’d like to thank you for doing so, your support is what gets me to write for you guys, so keep sharing my articles as you know that knowledge multiplies by sharing.

Happy Tinkering!

  • I simply want to say I am just beginner to weblog and absolutely enjoyed your website. Very likely I’m want to bookmark your blog . You actually have good article content. Many thanks for sharing your web-site.

  • Oh my goodness! Awesome article dude! Thank you so much, However I am experiencing issues with your RSS. I don’t know why I can’t subscribe to it. Is there anybody having identical RSS problems? Anyone who knows the answer can you kindly respond? Thanx!!

Leave a Reply

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



shares