Tilt sensor(SW-520D)
This sensor outputs a HIGH value when tilted.
It is modularized, allowing for direct connection to an Arduino.
The sensitivity of the tilt detection can be adjusted by manipulating the variable resistor on the product.
Specifications
- Operating Voltage: 3.3V ~ 5V
Required Hardware
- Tilt sensor
- Arduino UNO
- UNO Cable
- M-F Cable (3 pieces)
Connection
Can be connected to a digital pin other than D7.
SW-520D | Arduino Uno |
---|---|
D0 | D7 |
GND | GND |
VCC | 5V |
Example Code
Check the execution results on the Serial Monitor. Execution video
// Define the tilt sensor pin number
#define tilt 7
void setup()
{
// Set pin 7 as INPUT
pinMode(tilt, INPUT);
// Start serial communication
Serial.begin(9600);
Serial.println("Serial start");
}
void loop()
{
if(digitalRead(tilt) == 0) // When the tilt sensor output is 0 (balanced state)
{
Serial.println("Balanced");
delay(1000);
}
else if(digitalRead(tilt) == 1) // When the tilt sensor output is 1 (tilted state)
{
Serial.println("Tilted");
delay(1000);
}
}