【发布时间】:2021-11-25 13:31:11
【问题描述】:
有没有办法在 Arduino 代码中实现红外传感器作为输入?我希望传感器以值(IR 位置的变化)向 Arduino 发送数据,然后将该值用作软件中的输入。
代码是一个光阻传感器示例,它在每次变暗时打开 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);
}
}
【问题讨论】:
标签: arduino sensors data-transfer adc infrared