The small inexpensive easy to use sensor, it allows you to detect orientation or inclination. By connecting this tilt sensor with arduino we can control LED, buzzer or other output devices.
Here we interfaced tilt sensor with arduino board and LED as output indicator, remember to connect 10KΩ bias resistor between ground (GND) and one terminal of tilt sensor that is connected to arduino digital input pin.
Circuit diagram
In this sensor two conducting poles placed and the mass roller placed between these two pole elements. When the orientation of sensor changes to downwards the mass role shorts the two pole and act as a switch throw.
Arduino Tilt Switch sensor sketch code
[code]
/*www.theorycircuit.com*/
int SensorPin = 2;
int LEDPin = 13;
int LEDstate = HIGH;
int reading;
int previous = LOW;
long time = 0;
long debounce = 50;
void setup()
{
pinMode(SensorPin, INPUT);
digitalWrite(SensorPin, HIGH);
pinMode(LEDPin, OUTPUT);
}
void loop()
{
int switchstate;
reading = digitalRead(SensorPin);
if (reading != previous) {
time = millis();
}
if ((millis() – time) > debounce) {
switchstate = reading;
if (switchstate == HIGH)
LEDstate = LOW;
else
LEDstate = HIGH;
}
digitalWrite(LEDPin, LEDstate);
previous = reading;
}
[/code]
Components List
S.No | Name | Quantity |
1. | Arduino uno | 1 |
2. | Tilt switch sensor | 1 |
3. | LED | Red 1 |
4. | Resistor 220 Ω 100 KΩ |
1 1 |
5. | Connecting wires | as required |