This is an example program to fetch data of DHT11 Sensors

Dependencies:   mbed

Fork of DHT11_with_Nucleo by Adatgy2014

main.cpp

Committer:
kaliczp
Date:
2015-01-06
Revision:
4:62b680fac6ed
Parent:
3:6228ab73d420
Child:
5:76a9332af64c

File content as of revision 4:62b680fac6ed:

#include "mbed.h"

DigitalOut myled(LED1); // Activate LED
DigitalIn mybutton(USER_BUTTON); // Activate button
DigitalInOut data_pin(A0); // Activate digital in
Serial pc(SERIAL_TX, SERIAL_RX); // Initialize UART connection
// Use a terminal program (eg. TeraTerm).

// Function to initialize DHT11
void dht_read(void) {
    data_pin.output(); // Set A0 as output
    // Initialize measurement > 18 ms low
    data_pin = 0;
    wait_ms(20);
    // After high and release the pin switch input mode
    data_pin = 1;
    data_pin.input();
}

int main() {
    pc.printf("Read the DHT11 temperature and humidity sensor!\n"); //Welcome message
    while(1) {
        if (mybutton == 0) { // Button is pressed
            myled = 1; // LED is ON
            dht_read(); // Call the function
            wait_ms(200); // Wait 0.2 sec till continue.
        } else {
            myled = 0; // LED is OFF
        }
    }
}