Arduino学习之PIR Sensor

毕和志
2023-12-01

刚接触Arduino,代码参考价值极小,请路过的神棍多多指教

环境

Arduino UNO R3开发板,Arduino IDE 1.8.9

代码

#include <Arduino.h>
const int aaa=A0;
const int red_led =7;
const int blu_led=5;
const int gre_led=3;

void setup()
{
  Serial.begin(9600);
  pinMode(red_led, OUTPUT);   //设置工作方式
  pinMode(blu_led, OUTPUT);
  pinMode(gre_led, OUTPUT);
}

void loop()
{
  
  Serial.print("Sensor data : ");
  int data = analogRead(aaa);
  Serial.println( data );
  if(data==0)
  { 
    digitalWrite(gre_led, LOW);  //红灯亮
    digitalWrite(blu_led, HIGH);   //蓝绿灯灭
    digitalWrite(red_led,HIGH);  
  }
  else
  {
     digitalWrite(red_led, LOW);
     digitalWrite(blu_led, HIGH);
    digitalWrite(gre_led, HIGH);
     
  }  
}

原本想的效果是,有人红灯亮,没人绿灯亮,奈何技术不到家,脑洞也不够大,结果出来了个人工智障,算了算了是我写的 我的错 …

 类似资料: