About: PrimeRobotics is a E-Commerce site, which focus on supplying right products to Electronics Hobbyists, Enthusiast & Students.

The tilt switch used here is a ball one with a metal ball inside. It is used to detect small angle of inclination.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components Required

Step 2: Principle

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.

Step 3: Schematic Diagram

Step 4: Procedures


Build the circuit.

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board. Click the Upload icon to upload the code to the control board.If "Done uploading" appears at

the bottom of the window, it means the sketch has been successfully uploaded.

Now, tilt the switch, and the LED attached to pin 13 on Arduino Uno board will light up.

Step 5: Code


const int ledPin = 13;//the led attach to

void setup()


pinMode(ledPin,OUTPUT);//initialize the ledPin as an output

pinMode(2,INPUT);//set pin2 as INPUT

digitalWrite(2, HIGH);//set pin2 as HIGH



void loop()


int digitalVal = digitalRead(2);//Read the value of pin2

if(HIGH == digitalVal)//if tilt switch is not breakover


digitalWrite(ledPin,LOW);//turn the led off


else ////if tilt switch breakover


digitalWrite(ledPin,HIGH);//turn the led on






    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest