• LearnElectronics

Interfacing Tilt Sensor with Arduino UNO

Code:

const int ledPin = 9;   //led is connected to arduino pin 9

const int sensorPin=8;    // tilt switch is connected to pin 8

void setup()
{ 
  pinMode(ledPin,OUTPUT); 
  pinMode(sensorPin,INPUT);
  digitalWrite(sensorPin, HIGH);
} 

void loop() 
{  
  if(digitalRead(sensorPin) == HIGH)    // switch is open
  { digitalWrite(ledPin,LOW); }     //turn the led off
  else                            // switch is closed
  { digitalWrite(ledPin,HIGH); }    //turn the led on 
}

Tilt_Ball_Switch
.txt
Download TXT • 492B



16 views
  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2021