Tilt sensor(SW-520D) CN: 두 판 사이의 차이
(새 문서: center|class=coders100 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 t...) |
잔글편집 요약 없음 |
||
| (같은 사용자의 중간 판 하나는 보이지 않습니다) | |||
| 1번째 줄: | 1번째 줄: | ||
[[File:기울기대표이미지1.jpg|center|class=coders100]] | {{#seo:|title=Arduino维基:Arduino倾斜传感器(SW-520D)指南|title_mode=append|keywords=Arduino, 信息科学, 创客学习, 性能评估, 倾斜传感器(SW-520D), Arduino项目, 毕业设计项目, Arduino示例代码|description=介绍如何使用Arduino控制倾斜传感器(SW-520D)(基本信息、电路、示例代码)。可用于信息科学和创客课程。}}[[File:기울기대표이미지1.jpg|center|class=coders100]] | ||
当倾斜时,这个传感器会输出HIGH值。 | |||
它是模块化的,可以直接连接到Arduino。 | |||
通过调整产品上的可变电阻,可以调节倾斜检测的灵敏度。 | |||
== ''' | == '''规格''' == | ||
* | * 工作电压: 3.3V ~ 5V | ||
== ''' | == '''所需硬件''' == | ||
* | * 倾斜传感器 | ||
* Arduino UNO | * Arduino UNO | ||
* | * UNO电缆 | ||
* M- | * M-F电缆(3根) | ||
== ''' | == '''连接''' == | ||
可以连接到D7以外的数字引脚。 | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
| 40번째 줄: | 40번째 줄: | ||
[[File:Sw520d 회로.png|center|class=coders100]] | [[File:Sw520d 회로.png|center|class=coders100]] | ||
== ''' | == '''示例代码''' == | ||
在串行监视器上查看执行结果。 [https://blog.naver.com/gongzipsa/222888559217 Execution video]<syntaxhighlight lang="c++" line="1"> | |||
// Define the tilt sensor pin number | // Define the tilt sensor pin number | ||
#define tilt 7 | #define tilt 7 | ||
| 56번째 줄: | 56번째 줄: | ||
void loop() | void loop() | ||
{ | { | ||
if(digitalRead(tilt) == 0) // | if(digitalRead(tilt) == 0) // 当倾斜传感器输出为0(平衡状态)时 | ||
{ | { | ||
Serial.println("Balanced"); | Serial.println("Balanced"); | ||
delay(1000); | delay(1000); | ||
} | } | ||
else if(digitalRead(tilt) == 1) // | else if(digitalRead(tilt) == 1) // 当倾斜传感器输出为1(倾斜状态)时 | ||
{ | { | ||
Serial.println("Tilted"); | Serial.println("Tilted"); | ||
2025년 3월 20일 (목) 19:55 기준 최신판

当倾斜时,这个传感器会输出HIGH值。
它是模块化的,可以直接连接到Arduino。
通过调整产品上的可变电阻,可以调节倾斜检测的灵敏度。
规格
- 工作电压: 3.3V ~ 5V
所需硬件
- 倾斜传感器
- Arduino UNO
- UNO电缆
- M-F电缆(3根)
连接
可以连接到D7以外的数字引脚。
| SW-520D | Arduino Uno |
|---|---|
| D0 | D7 |
| GND | GND |
| VCC | 5V |

示例代码
在串行监视器上查看执行结果。 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) // 当倾斜传感器输出为0(平衡状态)时
{
Serial.println("Balanced");
delay(1000);
}
else if(digitalRead(tilt) == 1) // 当倾斜传感器输出为1(倾斜状态)时
{
Serial.println("Tilted");
delay(1000);
}
}