Arduino Sensors & Actuators guide series

Detect tilt and impact

The tilt and impact sensors are simple switches which close a circuit when positioned in a particular way. They are very cheap and come in a variety of shapes. They are usually made of a tiny metallic cylinder with a thin copper wire coming out of one end.

In many cases, knowing the exact force and direction applied to our gadgets is an overkill; just knowing that a bottle has been tipped over is enough to know that the lid should close automatically.

For simple cases like that, a 3-axis accelerometer is an overkill. We could use a simple sensor that can detect the shock of an impact or for being upside down.

Tilt and impact sensor

The tilt and impact sensor is a simple switch which closes a circuit when positioned in a particular way. They are very cheap, around $5 on eBay for a pack of 10. They come in a variety of shapes, but usually they are made of a tiny metallic cylinder with a thin copper wire coming out of one end.

The cylinder contains wires or a metal ball. When the device is hit or when its orientation changes, the wires or the ball come in contact with the wall of the cylinder and closes a circuit between the cylinder and the external wire.

They can be very sensitive, so care must be given to compensating for this sensitivity, otherwise we would be getting readings that look chaotic. We are going to ignore this sensitivity for now.

Here is what a tilt sensor looks like from the outside…

Cylindrical tilt and impact sensor

... and on the inside.

Assembly

To put this circuit together, we'll just use the Arduino, no breadboard is required.

We need to do a bit of soldering in order to connect the sensor to wires which we can connect to the Arduino. If you have never done soldering before, follow this tutorial for some instructions. Be careful not to get burned!

Here's what we are going to build.

Connect one wire to 5V and the other wire to A0 analog pin

Sketch

This is another very simple sketch. We'll just use the analog pin to determine if the switch inside the sensor is closed or open. You could just as easily have used a digital pin since there are only two states to detect, open or close, which nicely translate to HIGH or LOW.

Here is the sketch on Github.

int out;

void setup()
{
	Serial.begin(9600); // sets the serial port to 9600
}

void loop()
{
	out = analogRead(0); // read analog input pin 0
	Serial.println(out, DEC);
	delay(100); // wait 100ms for next reading
}

Try out by connecting the sensor to the Arduino and moving the sensor in different directions. This is easier if you use some electrical tape to keep the sensor wires tidy. You could even stick the sensor onto the Arduino, and move the whole assembly instead of only the sensor. This will help in keeping the connections firm.

Ready for some serious Arduino learning?

Start right now with Arduino Step by Step Getting Started

This is our most popular Arduino course, packed with high-quality video, mini-projects, and everything you need to learn Arduino from the ground up.

Browse this article
[publication_date]

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community. One email per week, no spam; unsubscribe at any time

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}