Created
December 7, 2019 10:24
Tilt Switch with Arduino - https://techzeero.com/arduino-tutorials/tilt-sensor-with-arduino/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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