Using a SW-520D Tilt Sensor with an Arduino Nano

Description: A SW-520D Tilt Sensor is tilted to the left and right to turn OFF and ON an LED wired to an Arduino Nano.

Tilt Sensor

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
1 – LED
1 – 220 Ohm Resistor
1 – SW-520D Tilt Sensor

Arduino Code:

int TiltPin = 4;
int LED = 6;

void setup() {

pinMode(TiltPin, INPUT_PULLUP);
pinMode(LED, OUTPUT);

}

void loop() {

  if (digitalRead(TiltPin) == LOW) {

  digitalWrite(LED, HIGH);

}

  else {

  digitalWrite(LED, LOW);

}
}

Leave a Comment

82 − = 81