有没有办法在Arduino代码中实现红外传感器作为输入?我希望传感器将数据发送到Arduino的值( IR位置的更改),然后在软件中使用该值作为输入。
代码是一个光阻传感器的例子,它在每次黑暗时打开LED,并在光传感器检测到它的亮度时将其关闭。
int sensor1Value = 0;
void setup()
{
// declare the ledPins as an OUTPUT:
pinMode(13, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensor1Value = analogRead(A0);
{
if(sensor1Value <200) // check the value of sensor
{ //if the value is less than 200 then turn the leds on
digitalWrite(13, HIGH);
delay(500);
}
else // if the value is greater than or equal to 200 then turn leds off
{
digitalWrite(13, LOW);
delay(500);
}
}发布于 2021-10-05 11:53:33
最简单的方法是使用IR phototransistor
在每个digitalWrite()之后不需要延迟,只需将其添加到loop()函数的末尾即可。
void loop() {
// read the value from the sensor:
sensor1Value = analogRead(A0);
if(sensor1Value <200) // check the value of sensor
{ //if the value is less than 200 then turn the leds on
digitalWrite(13, HIGH);
}
else // if the value is greater than or equal to 200 then turn leds off
{
digitalWrite(13, LOW);
}
delay(500);
}https://stackoverflow.com/questions/69447581
复制相似问题