arduino 学习(5)
一些其他传感器
- 声音传感器
暂时还没有读出值,还没有找到问题原因。
1 |
|
- 触摸传感器
1
2
3
4
5
6
7
8
9
10
11
12
13
14void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = digitalRead(5);
Serial.println(sensorValue);
delay(100);
}
触摸时为1,放开时为0;
- 蜂鸣器模块
1 |
|
- RGB LED 模块
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
analogWrite(3, 155);
analogWrite(5, 123);
analogWrite(6, 0);
delay(1000);
analogWrite(3, 0);
analogWrite(5, 255);
analogWrite(6, 0);
delay(1000);
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(6, 255);
delay(1000);
} - MQ2烟雾传感器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
} - 直流电机
这是一个触摸板操控直流电机小风扇的程序
这里将触摸板放到二号GPIO引脚,做外部中断输入,然后去改变风扇状态,在触摸板不抽风的情况下还挺好用的。
1 |
|
遇到的问题,
- tone函数和IRremote库定时器冲突。
ANS:https://blog.csdn.net/GreatSimulation/article/details/108982522
这里我才用了重新再写一个函数的方法,修改TIMER在我的UNO板子上无法生效。
arduino 学习(5)
https://leiz-eng.github.io/2023/08/10/arduino-5/