Tilt-a-Whirl Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Contributors: Toni_K
Favorited Favorite 1

Tilt-a-Whirl Overview

The RPI-1031 Tilt-a-Whirl is a tilt sensor on a breakout board that senses a change in orientation in four different directions. Internally, the sensor has optical sensors that are blocked when a small metal ball rolls in the direction of the orientation change. The sensor then outputs a signal indicating which side the ball is touching.

Tilt-a-Whirl Breakout

The board works at both 3.3V and 5V and breaks out the pins to the standard 0.1" headers.

Required Materials

We recommend you have access to the following materials to follow along with this tutorial.

Suggested Reading

These sensors are pretty easy to get started using, but you may want to check out some of the additional material below if you haven’t done much work previously on Arduino boards.

Hardware Hookup

There are only four pins that need to be hooked up in order to start using this sensor in a project. One for VCC, one for GND, and two data lines for outputting the photointerrupter data.

For this example, we are using an Arduino Uno to show the connections. However, you can use any microcontroller you prefer with this sensor.


  • VCC → 5V (or 3.3V)
  • GND → GND
  • S1 → D2
  • S2 → D3

Here is a Fritzing diagram showing the actual connections between the Tilt-a-Whirl and an Arduino Uno.

Tilt-a-Whirl Connected to Arduino

Multiple Sensors

You can connect multiple sensors to a single Arduino board, you will just need to use 2 digital pins for each sensor you would like to connect. For example, if you want to hook up two additional sensors (3 total), you would need to connect to digital pins 2, 3, 4, 5, 6, and 7 on the Arduino.

Talking to the Sensor

Now that the hardware is hooked up and ready to go, we need to upload code to the Arduino in order to start communicating with the sensor.

You can download the example Arduino sketch here. The most up-to-date code is also available on GitHub. Feel free to take this code, and modify it for your own purposes and projects!

At the beginning of the sketch, both S1 and S2 are initialized as integers, connected to pins D2 and D3 respectively.

int tilt_s1 = 2;
int tilt_s2 = 3;

This would be where you would initialize any additional sensors you would like to connect to the Arduino. Each additional pin would need to be defined as an integer and would need to be assigned to a digital pin that is still available.

Moving on to the set up loop, pins D2 and D3 are set as inputs, and serial communication is initialized at 9600 bps.

void setup()
    pinMode(tilt_s1, INPUT);
    pinMode(tilt_s2, INPUT);

Keep in mind, if you add in additional sensors, you will need to define the pinMode for each additional sensor pin as an input. You can also change the serial communication speed if necessary for your particular application.

Within the function loop, we simply use two functions. First, the function getTiltPosition() is called, which digitally reads the input from the two sensor pins. The received data is then processed using bitwise math, and returned to the main loop.

int getTiltPosition()
    int s1 = digitalRead(tilt_s1);
    int s2 = digitalRead(tilt_s2);
    return (s1 << 1) | s2; //bitwise math to combine the values

The function loop then assigns the data to the variable ‘position’, which is then printed out over the serial connection.

void loop()
    int position = getTiltPosition();
    delay(200); //only here to slow down the serial output

The sensor data will then be displayed every 2 milliseconds on the serial display.

That’s it! It really is that simple to get communication with your sensor started.

Resources and Going Further

Now that you know how to communicate with the Tilt-a-Whirl sensor, it’s time to go out and apply this to your own project! Check out the additional resources below if you need, otherwise, feel free to leave us feedback on this tutorial, or let us know how you apply this in your projects.