Introduction: Rick & Morty: Escape the Universe! Ultrasonic Proximity Sensor Game

What is the game about?

The game is pretty simple.

You control the spaceship that Rick and Morty are in by hovering your hand up and down the ultrasonic proximity sensor.

Objective:

  1. Collect the portal guns to gain score, coward Jerry the Worm double points
  2. Avoid the meteorite, if you hit it minus 1 live.
  3. 1 live will deducted if u exceed the screen as well.

The backstory on why I created the game.

Being an avid fan of Rick and Morty series, I wanted to create a game based on it. Thus, I embark on this journey to create this game hoping that all Rick and Morty fans can be gathered and enjoy the game. I do hope that you guys enjoyed it even if you are not a fan of Rick & Morty series. ^_^

Step 1: Gather Your Parts!

For this project, you will need 3 parts and 2 software downloaded.

  1. An Arduino Uno Board
  2. Ultrasonic proximity sensor
  3. 4 Male to Female jumper wires
  4. Arduino Software
  5. Processing 3

Alternatively, you can get some buttons module if you want the input to be totally dependant on the Arduino.

Step 2: Arduino Setup: Connecting Proximity Sensor to Arduino Board

On the Ultrasonic Proximity Sensor, you should see 4 Pins. VCC (Power), Trig (To send out pings), Echo (Output), GND.

  1. Connect the VCC pin to the Arduino 5V
  2. Connect the Trig to Arduino Digital Input/Output (I/O) Pin 3
  3. Echo to Arduino Digital I/O Pin 2
  4. GND to any available GND pin on the Arduino

Basic Explanation of the Module

Trig and echo are basically used to calculate the distance by -> Dividing the number of microseconds it was high by 58 and you have the distance in centimetres between the module and your hand.

For more information, you may want to visit https://randomnerdtutorials.com/complete-guide-for...

Step 3: Program the Arduino Board

Before we program the board, you may wish to run a simple blink test using the sketch files available in the Arduino software to ensure that the uno board is running fine.

Connect the Arduino board to your computer and open up Arduino Software. Once it is loaded, open Serial Monitor and check the COM port number.

Alternatively, you can check it by going to Tools -> Port. You should be able to see the COM port number. We will be using this number to gather input from the sensor to the Processing software. In my case, it is COM 3.

Once you confirmed that you can see some numbers in the Serial Monitor. You can proceed.

Step 4: Program the Game!

Please keep everything in the folder otherwise it will not run. (Null pointer as it cannot find the images that are needed to load)

Look for this line:

myPort = new Serial(this, Serial.list()[0], 9600);

You would need to change the Serial Port "Serial.list()[0]"-> the number "0" in code to the equivalent of the COM port you are using.

You may use the attached file "Serial.pde" to identify the serial port/ processing port equivalent of the COM port.

The reason we are doing this is that Processing software does not work directly with COM port. Once you are through this step, the serial data gathered from the sensor should be able to reach the Processing sketch file. We will be using this data to move the UFO Rick and Morty are sitting in.

Music and Text

Please install processing sound and controlp5 libraries in the processing software. This is for the various music to run in the game if you are using the codes and for the text at the various screens as well.

You can find the "how to" here:

https://stackoverflow.com/questions/30559754/how-t...

How it Works

The Arduino Software will only send the data only if the sensor detects an object moving above it (in this case the player's hand.). Once we received this data on the Processing sketch, we will be using the values to check for the range and have it act according to certain rules that are in the code. This is all happening while the game continues to run.

To understand the code, you can view the attached "Version 1.zip" file. I have added as much comment as I could to aid you in understanding what each line meant.

Hope you guys have fun making it! I would love to see the different variations that you guys come up with!

Step 5: Improvement in the Future

Hey guys, actually I had another incomplete version of this game with shooting capabilities. However, I am unable to fully code it yet.

The idea is to shoot the meteorite to destroy it and newly implemented object to make it more difficult and interesting. The input can be from a button on the Arduino board or as simple as a mouse click.

I will upload the codes here. If any of you are interested in it.

Step 6: Possible Problems Faced & Solutions

  1. When wiring makes sure to wire it correctly according to the wiring diagram otherwise it may not run as expected. Tip: Before you execute anything, carry out a simple blink test to check if your Arduino board is working.
  2. When unsure of which part of the setup is not working- run the individual test for each sensor module. You can find codes to test them online easily.
  3. Code not running as expected even though it was compiled and uploaded successfully.
  4. Check if the digital input is wired to the correct input number as specified in the codes.Re-plug your Arduino board and restart the Arduino software and try again.
  5. Port Busy -> Try to restart the Arduino software. If it did not solve the problem restart your computer.Otherwise, you may want to set the programmer to ArduinoISP. Tools>Programmer>ArduinoISP
  6. To loop the music, please convert it to monotone.
  7. When adding music to the draw function, it will cause the program to hang if you did not add in specific conditions for it to only run once.

Step 7: References: