2.17 Tilt Switch

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Overview

In this lesson, you will learn about tilt switch. Tilt switch can be used to detect whether objects tilt, which is of great value in practical applications. It can be used to judge the tilt of bridges, buildings, transmission line tower and so on, so it has an important guiding function in carrying out maintenance work.

Components Required

Component Introduction

The principle is very simple. When the switch is tilted in a certain angle, the ball inside rolls down and touches the two contacts connected to the pins outside, thus triggering circuits. Otherwise the ball will stay away from the contacts, thus breaking the circuits.

Fritzing Circuit

In this example, digital pin 2 is used to read the signal of Tilt Switch.

Schematic Diagram

Code

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
}

void loop() {
  int tiltState = digitalRead(2);
  Serial.println(tiltState);
  delay(1);      
}

After the codes are uploaded to the Mega2560 board, you can open the serial monitor to see the readings of pins, which displays 「1」 or 「0」 when Tilt Switch is vertical (bringing the internal metal ball into contacting with the Wire Pins) or tilted. For detailed explanation of codes, you can turn to Part 1-1.4 Digital Read.

Phenomenon Picture