Mission 7- Weather Station
 DuinoKit Jr.   Started by Daniel Alich   2017-06-27 18:31:10 -04:00   Comments: 2    Viewed: 570

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1498602610_Mission 7-1.jpg

    252_1498602602_Mission 7-2.jpg

    You will need to install the DTH11 library for this program to compile and upload correctly.  It seems these files keep moving and there are several avilable, however I'll place a download link here for the .ZIP file.

    DHT11.Zip Download Link
     
    The install the .zip file library
    In the top menu select:  Sketch => Include Library => Add .ZIP Library
    Navigate to your "Downloads" folder and select the DHTLib.zip file that was downloaded using the link above.

    #include <LiquidCrystal.h>
    #include <DHT.h> // Sometimes you will see quotes "DHT.h" instead of braces.
    // Quotes will tell the software to include from the same program folder
    // while <> will indicate to use the "library" folder in your software
    #define DHTPIN 8 // pin DHT is connected
    LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);
    #define DHTTYPE DHT11
    DHT dht(DHTPIN, DHTTYPE);

    void setup() {
    dht.begin();
    lcd.begin(16, 2);
    }

    void loop() {
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    t = t* 9/5 + 32;
    if (isnan(t) || isnan(h)) {
    lcd.setCursor(0, 0);
    lcd.print("Failed to read from DHT");
    //Serial.println("Failed to read from DHT");
    } else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Humidity: ");
    lcd.print(h);
    lcd.print("%");
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print(" f");
    delay(1000);
    // Serial.print("Humidity: ");
    // Serial.print(h);
    // Serial.print(" %t");
    // Serial.print("Temperature: ");
    // Serial.print(t);
    // Serial.println(" *C");
    }
    }
    Daniel Alich, 2017-06-27 18:31:10 -04:00
  2. Andy Eades
    Andy Eades Member
    I couldn't get the above sketch to work.  Below is the sketch I created that seems to work with the DHT11.zip libraries in the post and wired as shown.

    //
    //

    #include <LiquidCrystal.h>
    #include <dht.h>
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

    dht DHT;

    #define DHT11_PIN 8
    #define DHT21_PIN 5
    #define DHT22_PIN 6

    void setup()
    {
    Serial.begin(115200);
    Serial.println("DHT TEST PROGRAM ");
    Serial.print("LIBRARY VERSION: ");
    Serial.println(DHT_LIB_VERSION);
    Serial.println();
    Serial.println("Type,tstatus,tHumidity (%),tTemperature (C)");
    lcd.begin(16, 2);
    }

    void loop()
    {

    // READ DATA
    Serial.print("DHT11, t");
    int chk = DHT.read11(DHT11_PIN);
    switch (chk)
    {
    case DHTLIB_OK:
    Serial.print("OK,t");
    break;
    case DHTLIB_ERROR_CHECKSUM:
    Serial.print("Checksum error,t");
    break;
    case DHTLIB_ERROR_TIMEOUT:
    Serial.print("Time out error,t");
    break;
    default:
    Serial.print("Unknown error,t");
    break;
    }
    // DISPLAY DATA
    Serial.print(DHT.humidity,1);
    Serial.print(",t");
    float t = DHT.temperature;
    float h = DHT.humidity;
    t = t* 9/5 + 32;
    Serial.println(t,1);
    if (isnan(t) || isnan(h)) {
    lcd.setCursor(0, 0);
    lcd.print("Failed to read from DHT");
    //Serial.println("Failed to read from DHT");
    } else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Humidity: ");
    lcd.print(h);
    lcd.print("%");
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(t);
    lcd.print(" f");
    }
    delay(1000);
    }
    //
    // END OF FILE
    //
    Andy Eades, 2018-08-24 20:28:39 -04:00
  3. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!