用Tinkercad学arduino之 光敏电阻 天黑智能继电器开灯

项目地址:https://www.tinkercad.com/things/6ZSQimwEiC6-spdt-relay-photoresistor

bool isLight = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, INPUT);
}

void loop()
{
  int val = analogRead(A0);
  Serial.println(val);
  if (val < 300) {
    digitalWrite(2,0);
    digitalWrite(4,1);
  } else {
    digitalWrite(2,1);
    digitalWrite(4,0);
  }
}

 

posted @ 2020-12-09 09:59  meetrice  阅读(840)  评论(0编辑  收藏  举报