Skip to content

Instantly share code, notes, and snippets.

@techzeero
Created December 7, 2019 10:24
/*
Tilt Switch with Arduino
For more details, visit: https://techzeero.com/arduino-tutorials/tilt-sensor-with-arduino/
*/
int tiltSensorPin = 2; //Pin for tilt sensor
int notTiltLED = 11; //Pin for Not Tilt Output LED
int TiltLED = 12; //Pin for Tilt Output LED
void setup()
{
pinMode(tiltSensorPin, INPUT);
digitalWrite(tiltSensorPin, HIGH); //Pull-up resistor
pinMode(notTiltLED, OUTPUT);
pinMode(TiltLED, OUTPUT);
}
void loop()
{
if(digitalRead(tiltSensorPin)) //check if the pin is high
{
digitalWrite(notTiltLED, HIGH);
digitalWrite(TiltLED, LOW);
}
else
{
digitalWrite(notTiltLED, LOW);
digitalWrite(TiltLED, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment