Accelerometer Controlled Tilt Breakout Game

by electric_piano_5k in Circuits > Arduino

133 Views, 1 Favorites, 0 Comments

Accelerometer Controlled Tilt Breakout Game

image0.jpeg
Tilt Breakout

This is an Arduino version of the video game Breakout, but with the ball controlled by tilting the game and using a BMI160 accelerometer to sense the tilting. There are no buttons or knobs for control, the only control is by tilting the game! The display is a 16x16 color LED array (WS2812B type). It is a simple project, there is not much to it as you can see in the picture, but it is quite fun to play!

Supplies

image1.jpeg

You need:

An Arduino (any type). I used Leonardo, but Uno or another Arduino would work just the same. The only thing to watch for is that some Arduinos have the I2C connections SCL and SDA on different pins, these are used to communicate with the accelerometer module.

16x16 color LED array (WS2812B type).

BMI160 accelerometer module. A MPU6050 accelerometer is more common and would also work, with some changes to the circuit connections and the software. I included code for interfacing to the MPU6050, but I didn't test it because I don't have the MPU6050.

Passive buzzer (16 ohm, 2kHz), NPN transistor (S8050), and 1k ohm resistor. These items are included in most Arduino kits.

Breadboard and wires.

USB 5V power supply.

A piece of cardboard or wood to attach everything to.

Tape or twist ties to hold things together.

For connecting the LED array to the Arduino, I used about a foot of solid core wire, solder, soldering iron, and heat shrink tubing.

Construction

image2.jpeg
buzzer_schematic.jpg

The assembly is easy, just attach everything to the cardboard or piece of wood and make the electrical connections.

I used a piece of heavy cardboard to hold everything. First I cut holes in the cardboard for the wires of the LED array to pass through (see picture). Then I attached the LED array to the cardboard with double sided tape. I poked holes in the cardboard and used long twist ties to hold the Arduino and breadboard to the cardboard. I used cardboard because I wanted to get it running quickly to see how it would work. Now that I know it works well, I might cut a piece of wood and hide the circuitry on the back of the piece of wood.

I desoldered the DOUT connector from the LED array and used it to make the connection from DIN to the Arduino. I soldered some solid core wire to the connector leads so that I could plug them into the Arduino connectors, and I protected the connections with heat shrink tubing.

Note that I installed the accelerometer "upside down", with the circuitry on the bottom, this was so that I could see the lettering identifying the pinouts. So, the way I have installed it, X is towards you, Y is to the left, and Z is toward the floor. If you install the accelerometer in a different orientation, you will have to make some simple changes to the function handleInput(), see the comments in the program. It is VERY important that the accelerometer is oriented with X and Y aligned with the LED array, otherwise the control will be unnatural. This could be fixed with some trigonometric calculations in function handleInput(), but this will be calculation intensive so I strongly recommend against this, just orient the accelerometer correctly.

I cut a piece of white paper and taped it over the LED array to act as a diffuser. This makes the display more attractive, but is not essential.

The electrical connections are as follows:

LED array:

5V to Vin on Arduino. NOTE: this is assuming that you are powering the project using the Arduino's USB port, and that your USB power supply can provide enough current to run the LED array. If you are powering the Arduino in some other way, you will need to power the LED array separately. The Arduino's built in 5V regulator can handle only 500-800 mA, which may not be enough to power the LED array. WS2812b LEDs can draw about 60 mA per LED if set to white at full brightness, so the entire array of 256 LEDs could draw about 15 amps. In this project the brightness is set at a low level (50 out of a possible 255) and less than half of the LEDs are lit at any time, but still that could amount to about 1.5 amps.

GND to GND on Arduino.

DIN to pin 5 on Arduino.

BMI160 accelerometer module: (For MPU6050 accelerometer, the connections are the same except where indicated)

VIN to 5V on Arduino (for MPU6050: VCC to 5V on Arduino)

GND to GND on Arduino

SCL to SCL on Arduino

SDA to SDA on Arduino

SA0 to GND (for MPU6050: AD0 to GND)

Passive Buzzer:

Connect as shown in the schematic diagram. The buzzer + connects to 5V, the buzzer - connects to the transistor. The resistor connects to pin 6 on the Arduino.


The Program

You will need to install the DFRobot_BM160.h library and the Adafruit_Neopixel.h library, which are available in the Arduino IDE's library search tool. Then, just connect the Arduino to your computer's USB port and upload the program to the Arduino.

How to play:

Hold the game approximately level. Tilt to control the ball (blue dot) motion. You need to hit all 21 of the colored bricks at the top of the screen. If you hit the red line behind the bricks, the game is over! If you hit all the bricks, you move on to the next level. Each level has more red dots to avoid, so you have to control the ball more carefully to avoid hitting any red. (The bricks are assigned random colors, sometimes they appear reddish, but they don't count as game-ending red.) There are a total of 5 levels. I still haven't finished level 5!

If you hit red, ending the game, your score is displayed and a smiley face appears with a green dot beneath. Roll the ball to the green dot to re-start the game.

A few comments about the program:

The starting point for the program was a monochrome 8x8 Breakout game by mircemk (June 2025), but it has been significantly modified for a 16x16 color LED array and control using an accelerometer instead of buttons to control a paddle. Some parts like the text scrolling are unchanged.

For the fastest computing speed, I have used integer arithmetic throughout. The ball position and speed are 16-bit integers, calculated at 1024 times the pixel resolution. The ball position is divided by 1024 (right shift 10 bits) to obtain the pixel coordinate on the LED display. All divisions have been done using bit shift operations which are far faster than arithmetic divide operations. The only floating point calculation remaining is the coefficient of restitution of the bouncing ball, but this calculation only happens once each time the ball bounces so the delay if any is negligible. The refresh rate is 50 Hz (20 ms frame time). The data transfer to the LED array takes about 8 ms, so this leaves 12 ms for Arduino computation.

If you are using the MPU6050 accelerometer, search within the program for "MPU6050" where you will find commented-out lines which are for use with the MPU6050 accelerometer. Remove the "//" to un-comment these lines, and comment out the corresponding lines for the BMI160. Note that these program lines have not been tested, since I don't have the MPU6050 accelerometer, they are just what I found in documentation and other programs.

You may have to make adjustments to the function handleInput(), depending on how your accelerometer is oriented. You may need to interchange "x" and "y" or "+" and "-" in the assignments of difx and dify.