108个传感器之-魔术光杯模块(23)

108个传感器之-魔术光杯模块(23)

介绍

当检测到冲击时,魔术灯杯模块将打开或关闭LED。如果检测到振动,则激活或停用LED,并将相应的控制信号转发为信号输出。可以读取此信号以监视LED的状态。该模块是使用对运动或振动反应的应用,例如交互式灯,玩具或警报系统。通过将触发信号转发到信号输出中,其他系统或微控制器可以检测到振动并相应地做出反应。

Input voltage Series resistor
3.3 V 120 Ω
5 V 220 Ω

引脚连接

pin 引脚连接开发板的 gpio 接口即可:

DEV BOARD Sensor
Pin 2 signal
5 V +V
GND GND
Pin 5 signal

代码示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int led = 2 ;// Declaration of the LED output pin
int shock_sensor = 5; // Declaration of the sensor input pin
int value; // Temporary variable

void setup () {
pinMode(led, OUTPUT); // Initialization output pin
pinMode(shock_sensor, INPUT); // Initialization sensor pin
digitalWrite(shock_sensor, HIGH); // Activation of internal pull-up resistor
}

void loop () {
value = digitalRead(shock_sensor); // The current signal at the sensor is read out
// If a signal is detected, the LED is switched on.
if (value == HIGH) {
digitalWrite (led, LOW);
delay(200);
}
else digitalWrite(led, HIGH);
}

小结

待完善…

108个传感器之-魔术光杯模块(23)

http://blog.jzxer.cn/20241225/20241225-magic-cup/

作者

dev

发布于

2024-12-25

更新于

2025-01-12

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×