【问题标题】:Implementing Infrared sensor to an arduino在 arduino 上实现红外传感器
【发布时间】: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


    【解决方案1】:

    最简单的方法是使用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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多