
No. 20 • Digital
Tilt Sensor (Angle Tilt Switch)
ตรวจจับการเอียงหรือการเปลี่ยนมุมของโมดูล
Component NameTilt Sensor
Part No. / ModelAngle Tilt Switch
Interface TypeDigital
PinsS, VCC, GND
Note: สัญญาณอาจเด้ง ควรใช้ debounce ในโปรแกรม
Wiring Example
ตัวอย่างการต่อวงจรกับ Arduino UNO
| Sensor Pin | Arduino Pin |
|---|---|
| S | D2 |
| VCC | 5V |
| GND | GND |
Arduino IDE Code
// Tilt Sensor (Angle Tilt Switch)
// Board: Arduino UNO
// Read digital output from the sensor module.
const int SENSOR_PIN = 2;
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
int state = digitalRead(SENSOR_PIN);
Serial.print("Sensor state: ");
Serial.println(state);
delay(300);
}