倾斜传感器是一种可检测较小倾斜角度的电子开关,当垂直悬挂的倾斜开关探头在受到外力作用且偏离垂直位置17°以上时,倾斜开关内部的金属球触电断开;当外力撤销后,倾斜开关恢复到垂直状态同时金属球触点也恢复到闭合状态。
Arduino引脚 |
模块引脚 |
D3 |
S |
5V |
VCC |
GND |
GND |
1 int led = 13; 2 int buttonPin = 3; 3 int val; 4 void setup() { 5 // put your setup code here, to run once: 6 pinMode(led, OUTPUT); 7 pinMode(buttonPin, INPUT); 8 } 9 10 void loop() { 11 // put your main code here, to run repeatedly: 12 val = digitalRead(buutonPin); 13 if (vaa == HIGH) 14 { 15 digitalWrite(led, HIGH); 16 } esle{ 17 digitalWrite(led, LOW); 18 } 19 }