|
|
我用的是DHT11温湿度传感器 1602液晶显示屏 SG90舵机 哪位大神能帮忙写一个当温度达到20度时 舵机开始转动的程序啊我自己弄了一个不能用 请大神帮忙改改吧{:soso_e101:}
#include <Servo.h>
Servo myservo;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = 4;
float temperature = 0;
long val=0;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
myservo.write(93);
lcd.begin(16, 2);
lcd.print("DHT11 Thermometer");
delay(1000);
}
void loop ()
{
val = analogRead(potPin);
temperature = (val*0.0048828125*100);
lcd.clear();
lcd.print("DHT11 Thermometer");
lcd.setCursor(0, 1) ;
lcd.print((long)temperature / 10);
lcd.print(".");
lcd.print( (long)temperature % 10);
lcd.print((char)223);
lcd.print("C");
delay(2000);
int val;
int dat;
val=analogRead(0);
dat=0.488*val;
//Serial.println(dat);
if(dat>20)
{
myservo.write(180);
}
else
{
myservo.write(93);
}
delay(500);
}
|
|