This post shows how to use the tilt sensor module with the Arduino. The tilt sensor is many times referred to as inclinometer, tilt switch or rolling ball sensor. Using a tilt sensor is a simple way to detect orientation or inclination.
The tilt sensor module is the one in the following figure.

The tilt sensor allows to detect orientation or inclination. It detects if the sensor is completely upright or if it is tilted.
This makes it very useful to be used, for example, in toys, robots and other appliances whose working methodology depends on inclination.
The tilt sensor is cylindrical and contains a free conductive rolling ball inside with two conductive elements (poles) beneath.

Here’s how it works:
This way, the tilt sensor acts like a switch that is turned on or off depending on its inclination. So, it will give digital information to the Arduino, either an HIGH or a LOW signal.
You can go to Maker Advisor and find the sensor’s best price.
Wiring the tilt sensor to you Arduino is pretty straightforward. You just need to connect one pin to an Arduino digital pin and GND to GND.
If you connect the sensor like so, you need to activate the arduino internal pull-up resistor for the digital pin to which your sensor is connected to. Otherwise, you should use a 10kOhm pull up resistor in your circuit.

This is just a simple example for you to start put hands on your tilt sensor.
In this example, an LED will be turned off if the sensor is upright, and will be turned on if the sensor is tilted.
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
For this example, you just need to add an LED to the schematics in the “Pin Wiring” section.

To complete this example, upload the following code to your Arduino board.
/* * Rui Santos * Complete Project Details https://randomnerdtutorials.com */ int ledPin = 12; int sensorPin = 4; int sensorValue; int lastTiltState = HIGH; // the previous reading from the tilt sensor // the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime = 0; // the last time the output pin was toggled long debounceDelay = 50; // the debounce time; increase if the output flickers void setup(){ pinMode(sensorPin, INPUT); digitalWrite(sensorPin, HIGH); pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop(){ sensorValue = digitalRead(sensorPin); // If the switch changed, due to noise or pressing: if (sensorValue == lastTiltState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: lastTiltState = sensorValue; } digitalWrite(ledPin, lastTiltState); Serial.println(sensorValue); delay(500); }
In the end, this is what you’ll have.

Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION