Introduction: Tilt Sensor LED Dice

This project creates a LED dice that produces a new number every time the tilt sensor is tilted. This project could be modified to use a button, but the code would need to be altered accordingly.

Before starting this project be sure to connect 5V and GND to each side of the breadboard.


  • SW-520D Tilt Sensor
  • 7 LEDs
  • 7 220 or 330 ohm resistors
  • Breadboard
  • Jumper Wires

Step 1: Step 1: Set Up LEDs

The First thing you want to do is setup the LEDs in an 'H' formation to give the outline of a dice. Following the picture above, line up 3 LEDs vertically on each side (making sure each leg has its own row), and placing one led in the middle.

After that is done, connect the short leg of each LED to GND.

To make the code a little bit easier there will only be 4 digital pins for the 7 LEDs, There will be 3 groups of 2 and the middle LED will have its own digital pin (see picture above)

  • Connect Group 1's long legs together and connect it to digital pin 10
  • Connect Group 2's long legs together and connect it to digital pin 9
  • Connect Group 3's long legs together and connect it to digital pin 8
  • Connect LED 4 long leg to digital pin 7

Step 2: Step 2: Connect Tilt Sensor

To give some background on how the Tilt sensor works, it can be coded to have an OFF state and an ON state similar to an Arduino button. If the sensor is vertically upright, it is usually considered in an ON state and if it in vertically facing down, it is usually considered in an OFF state,

In this project when the tilt sensor is facing down, it will signal the 'dice' to roll a random number.

  • Connect the short leg of the tilt sensor to GND and connect the long leg to digital pin 2

Step 3: Step 3: the Code

Here is the link to the code. If you have any questions, don't hesitate to ask.