zoukankan      html  css  js  c++  java
  • 【Arduino】使用LCD1602和DHT11制作温湿度显示器

    材料:
    1.DHT11
    2.LCD1602
    3.LCD1602 转接板
    4.Arduino UNO
    5.Arduino 传感器扩展版

    那个Arduino UNO 我当初挑类个便宜的山寨货买,结果发来和正版的长得一样 O(∩_∩)O吓死我了,,,,
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述

    
    double Fahrenheit(double celsius) 
    {
            return 1.8 * celsius + 32;
    }    //摄氏温度度转化为华氏温度
    
    double Kelvin(double celsius)
    {
            return celsius + 273.15;
    }     //摄氏温度转化为开氏温度
    
    // 露点(点在此温度时,空气饱和并产生露珠)
    // 参考: [url=http://wahiduddin.net/calc/density_algorithms.htm]http://wahiduddin.net/calc/density_algorithms.htm[/url] 
    double dewPoint(double celsius, double humidity)
    {
            double A0= 373.15/(273.15 + celsius);
            double SUM = -7.90298 * (A0-1);
            SUM += 5.02808 * log10(A0);
            SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
            SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
            SUM += log10(1013.246);
            double VP = pow(10, SUM-3) * humidity;
            double T = log(VP/0.61078);   // temp var
            return (241.88 * T) / (17.558-T);
    }
    
    // 快速计算露点,速度是5倍dewPoint()
    // 参考: [url=http://en.wikipedia.org/wiki/Dew_point]http://en.wikipedia.org/wiki/Dew_point[/url]
    double dewPointFast(double celsius, double humidity)
    {
            double a = 17.271;
            double b = 237.7;
            double temp = (a * celsius) / (b + celsius) + log(humidity/100);
            double Td = (b * temp) / (a - temp);
            return Td;
    }
    
    #include <dht11.h>
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    
    LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
    
    dht11 DHT11;
    
    #define DHT11PIN 2
    
    void setup()
    {
      lcd.init();                      // initialize the lcd 
      lcd.backlight();
      lcd.print("Waiting...");
      Serial.begin(9600); 
    }
    void loop()
    {
      int chk = DHT11.read(DHT11PIN);
    
      switch (chk)
      {
        case DHTLIB_OK: 
                    lcd.setCursor(0, 0);
                    lcd.print("Temp:");
                    lcd.print((float)DHT11.temperature,2);
                    lcd.write(0xDF);
                    lcd.print("C");
    
                    lcd.setCursor(0, 1);
                    lcd.print("Humidity:");
                    lcd.print((float)DHT11.humidity,2);
                    lcd.print("%");
    
                    break;
        case DHTLIB_ERROR_CHECKSUM: 
                    lcd.clear();
                    lcd.print("Checksum error"); 
                    delay(1000);  
                    lcd.clear();
                    break;
        case DHTLIB_ERROR_TIMEOUT: 
                    lcd.clear();
                    lcd.print("Time out error"); 
                    delay(1000);             
                    lcd.clear();
                    break;
        default: 
                    lcd.clear();
                    lcd.print("Unknown error"); 
                    delay(1000);                
                    lcd.clear();
                    break;
      }
      delay(1000);
    }
  • 相关阅读:
    URAL 1998 The old Padawan 二分
    URAL 1997 Those are not the droids you're looking for 二分图最大匹配
    URAL 1995 Illegal spices 贪心构造
    URAL 1993 This cheeseburger you don't need 模拟题
    URAL 1992 CVS
    URAL 1991 The battle near the swamp 水题
    Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力
    Codeforces Beta Round #7 D. Palindrome Degree hash
    Codeforces Beta Round #7 C. Line Exgcd
    Codeforces Beta Round #7 B. Memory Manager 模拟题
  • 原文地址:https://www.cnblogs.com/wolfray/p/5547268.html
Copyright © 2011-2022 走看看