SW-520D tilt sensor with Arduino
FunduinoLast updated on
Mit zwei Metallkugeln erkennen, ob etwas gekippt wurde
You need this
SW-520D tilt sensor - mechanical, switching angle 45°
0,70 € *Item no. F23106767About the product — SW-520D tilt sensor - mechanical, switching angle 45°
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino
2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
All 4 parts together 16,46 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
Material
How the sensor works
1 / 2
Structure
1 / 2
Switch the LED when tilted
Sketch: Turn on LED when tilted
int LED = 6; // Das Wort "LED" steht jetzt fuer den Wert 6.
int TILT = 7; // Der Neigungssensor wird an Pin 7 angeschlossen.
int NEIGUNG = 0; // Hier wird spaeter gespeichert, ob eine Neigung vorliegt.
void setup()
{
pinMode(LED, OUTPUT); // Der Pin mit der LED ist ein Ausgang.
pinMode(TILT, INPUT); // Der Pin mit dem Neigungssensor ist ein Eingang.
}
void loop()
{
// Pin 7 auslesen. Steht der Sensor aufrecht, verbinden die Kugeln
// seine beiden Kontakte: am Pin liegt Spannung an, der Wert ist HIGH.
// Wird der Sensor gekippt, rollen die Kugeln weg, die Verbindung
// ist unterbrochen und der Wert ist LOW.
NEIGUNG = digitalRead(TILT);
if (NEIGUNG == HIGH) // Sensor steht aufrecht ...
{
digitalWrite(LED, LOW); // ... dann bleibt die LED aus.
}
else // Ansonsten ist der Sensor gekippt ...
{
digitalWrite(LED, HIGH); // ... und die LED leuchtet.
}
}Rate the instructions