极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11116|回复: 1

求求大神帮忙写一个当温度达到某一个值时舵机开始转动的程序

[复制链接]
发表于 2015-1-7 11:14:08 | 显示全部楼层 |阅读模式
我用的是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);
}
回复

使用道具 举报

发表于 2015-1-7 17:06:25 | 显示全部楼层
DHT11是单总线通信的,你的程序没体现。你买个LM35D接上去,直接读电压就是温度了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 13:51 , Processed in 0.055730 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表