Arduino Tilt Sensor WIP

Meta Description

Discover how tilt sensors work by building your own circuit using an Arduino board. Learn the science behind these nifty sensors. Starter code available.

Learning Objectives

Understanding how a tilt sensor works.

Implementation and debugging of a microcontroller circuit.

Awareness of other sensor technologies for orientation.

Key Terms


Logic High (High)
A 5V voltage present at the input or output pin of the Arduino. This value can vary within a certain tolerance.

Logic Low (Low)
A 0V voltage present at the input or output pin of the Arduino. This value can vary within a certain tolerance.

Open Circuit
Remove the connection between two terminals in an electric circuit, stopping current from flowing between them.

Polarised device
An electrical device which only allows current flow in a single direction.

Single Axis Sensor
A sensor which can only sense a limited angle of movement along a single axis (up and down or left and right).

Short Circuit
Connect two terminals together in an electric circuit, allowing current to flow between them.

Tilt Sensor
A sensor which senses a change in orientation.


Step 1
Wire the circuit as shown in the Fritzing diagram in the figure below. Place the 100Ω resistor in series with the LED. This resistor limits the amount of the current the LED can drain from the microcontroller, protecting both the microcontroller output pin and the LED from burning out. Use the 1 kΩ resistor as the pull-up resistor connecting the tilt sensor to the board.

Arduino Tilt Sensor (

Step 2
Connect the Arduino board to the computer via the USB cable. It is advisable to unplug the laptop from it’s charger before starting the experiment – a connection to the mains power line can affect the stability of the circuit. Place the Arduino board on a non-conductive surface such as glass, wood or plastic to prevent current conduction through the surface which can damage the board.

Step 3
Launch the Arduino IDE software on the computer. For initial setup for first-time users please consult the link.

Step 4
Paste the code into a sketch within the Arduino IDE.

Step 5
Click Upload in the IDE.

Step 6
Gently change the orientation of the tilt sensor by tilting the breadboard left and right and forwards and backwards. What do you observe?

  1. Always safely eject the USB connector from the computer.
  2. Store the Arduino board in an antistatic bag to prevent damage due to electrostatic discharge.
  3. A rollerball tilt sensor should be used instead of a mercury switch sensor because it is more environmentally friendly.
  4. Keep liquids away from the work surface and do not place any of the equipment on a damp surface. Preferably, floors near the work surface should also be dry.
  5. Never short the power pins (5V or 3V) of the microcontroller with its ground (GND) pins. This creates a short circuit which can damage the device and cause substantial heating which may lead to burns.
  6. The Arduino board and the components usually have sharp edges which can prick fingers, particularly when wiring the breadboard, so care should be taken during assembly and disassembly of the circuit.
  7. Place the Arduino board on a non-conductive surface such as glass, wood or plastic to prevent current conduction through the surface which can damage the board.
  8. The safest way to power the Arduino board is from the laptop via the USB cable. In the unlikely case that the Arduino must be powered via a power supply and not from the laptop, set a current limit of around 100mA on the supply. Take good care to keep the positive and negative supply terminal outputs from touching to avoid a short circuit condition which can lead to current limiting (which could lead to impaired performance), heating, damage to the circuit or laptop and in rare cases sparking.

Imagine you’re in a little cabin on a boat. Its rough sea and the floor is tilting left and right, throwing you back and forth against the walls of the cabin. A similar situation  occurs when you’re standing on a bus and getting thrown every which way by the movement of the bus. In both cases, you are very sensitive to the movement of the vehicle you are in, but you have no control over that movement.

Inside the metal can of the sensor there is a tiny metallic rollerball. Every time the tin can is shifted, the ball moves. It is sensitive to the direction of motion of the sensor just like you’re sensitive to the movement of a boat or bus.

When the sensor is in the upright position, the ball closes a little switch in the sensor, letting current pass through the sensor – it outputs a high voltage. When the angle of the sensor is changed, the ball rolls out of position, the switch is opened and current no longer passes through the sensor – it outputs a low voltage.

Why does the LED not switch on if it is reversed?
Polarised device.

What technology does the sensor use?
Roll ball type sensing technology.

What is a logic high and a logic low?
High: 5V, Low: 0V

How does the microcontroller switch the LED on or off?
It outputs a high to switch on the LED, low to switch it off.

How does the microcontroller know that the sensor was activated?
Programmed to notice change between high and low on the input pin associated with the sensor.

Tilt sensors sense the angle of tilt of an object. Several different types of sensors are used in electronics. Single axis sensors, like the one used in this experiment, can only sense a limited angle of movement along one direction of movement: either up and down or left and right. It is used for very basic motion and orientation sensing. Triple axis sensors, like accelerometers in phones, can sense movement in all directions in 3D space.

The sensor works like a light switch. A small metal ball inside the sensor moves as the sensor’s orientation changes. There are two contacts inside the sensor. In the upright position, the ball shorts these contacts and current flows through the sensor – it acts like a closed switch. When the sensor is moved and the ball rolls out of position, the circuit is opened, the current stops flowing – the sensor acts as an open switch.

The Arduino input pin is programmed to notice these switched-on and switched-off conditions. When the sensor contacts are shorted (switch on), the LED is turned switched on, when the contacts are opened, the LED is switched off. The LED is switched on by the Arduino putting a logic high (a 5V voltage) on the output pin. This causes current to flow through the LED and it illuminates.

Single axis sensors are limited to narrow angles along a single axis. Dual axis sensors use two sensors and are sensitive to movement within the x-y plane. Three axis tilt sensors can sense a change in orientation along all axes in 3D space. 

Single axis tilt sensors can be mercury based or rollerball based. The operation of both is similar, with the metallic rollerball replacing a blob of mercury in modern sensors. Although modern sensors are more environmentally friendly, the roller ball creates mechanical bouncing at the switch contacts. The sketch code compensates for this with software switch debouncing.

The resistors in the circuit had a precautionary function. The pull up resistor ensures that the pin of the Arduino always has a definite voltage level, thus avoiding a floating input scenario. The small resistance in series with the LED performs a current limiting function. This prevents the LED from draining more current than the microcontroller pin can safely source and lengthens the lifetime of the LED.

Tilt sensors are used in a wide variety of applications. They are used in mobile phones to sense changes in the phone’s position. This information is used, for example, to rotate the screen, monitor body movement and to play some games. They are popular sensors because they are low-power.

High-tech tilt sensors are used in aircraft to provide the pilot and on-board computers information about the craft’s horizontal and vertical inclinations. 

Tilt sensors are also used in car alarms. If thieves try to take a car using a tow truck, as the car is lifted and its inclination changes the sensors are triggered by this suspicious change and set off an alarm. 

Fun fact: Some animals have evolved tilt sensors of their own! Ctenophores are animals that are closely related to jellyfish. These animals have a small rock of calcium carbonate (called a statolith), that acts like a roll ball. As the ctenophore moves through the water, the ball moves according to it’s orientation. The ctenophore has receptors that can detect where the statolith is, and uses this information to determine up and down directions.

Sensors surround us. They are an essential part of mobile phones, vehicles and industrial processes. They can measure, amongst other things, velocity, temperature, humidity or pressure. One big problem with having so many sensors is processing the huge volumes of data they produce. Poor processing can lead to loss of data, computer overload and security issues, particularly in the Internet of Things (IoT). To reduce sensor data, researchers developed a system using Teraki software, which is developed by an international company. Instead of using compression as other data reduction techniques have used in the past, this software uses a less computationally intensive algorithm. This shift is very important considering the limited battery life of mobile devices, which are key contributors to the IoT. The project aimed to identify the most viable ways to commercialize IoT solutions to a group of consumers with specialized needs. These issues need to be investigated for IoT solutions to be adopted in all sectors of the economy. 

  • Use a multimeter to observe how the voltage at pin 2 of the Arduino (the input pin associated with the sensor) varies with sensor orientation. To do this, attach the common (black) lead of the meter to the GND terminal of the board. Attach the red lead of the meter to pin two of the Arduino board. Vary the orientation of the breadboard and observe how the voltage changes. How does this relate to the motion of the rollerball?
Download as PDF

Time Required

  • ~30 minutes

  • Preparation: 15 minutes

  • Conducting: 15 minutes

  • Clean Up: 5 minutes

Recommended Age

Number of People



1kΩ resistor

100Ω resistor

Arduino Uno Board


Computer with Arduino IDE software installed. To download the software.

Jumper wires


Tilt sensor

USB connector for Arduino Board


First published: October 1, 2017
Last modified: October 30, 2017

0 0
[caldera_form id="CF59c90c0240779"]

Leave a Reply