Arduino Tilt Sensor Tutorial | Interfacing Tilt Ball Switch Sensor With Arduino

About: Nice place to learn electronics, Arduino, Raspberry pi & diyelectronics Projects.

A Tilt Sensor switch is an electronic device that detects the orientation of an object and gives its output High or Low accordingly. Basically, it has a ball inside it which moves and makes the circuit. So tilt sensor can turn on or off the circuit based on its orientation.
In this project, we are interfacing Tilt sensor with Arduino UNO & We are controlling a LED according to the output of the tilt sensor. Whenever we tilt the sensor LED will be turned on.

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: Things You Need

For this project you'll need following things :-
Arduino uno : https://www.utsource.net/itm/p/9221687.html


1x Tilt sensor :
1 x LED
1x Resistor ( from 220 ohm to 1k ohm : any value )
1x relay module :
https://www.mob.utsource.net/ic-datasheet/7708783
1x Breadboard
Few jumpers

Step 2: Circuit

Connect everything According to as shown in the image and then we will be ready to upload th code.

Step 3: Code

Now we come to coding part open your arduino ide and copy the following code & upload it to arduino uno :
Code :-

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);
}

Step 4: Final Step

We completed everything so when you change the orientation of your tilt sensor LED will be ON & when taking it back to its previous orientation will turn it off as you can see in images & video. And even instead of LED you can attach a relay module & your AC bulb will turn on whenever you will change the orientation of your tilt sensor.

Video link : https://youtu.be/wcgRUfgFVf0

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions