A DHT11 sensor is connected to the STM32L476VGT Discovery Board to monitor temperature and humidity.

Dependencies:   DHT mbed

Fork of DHT11-HelloWorld by WIZnet

Committer:
Camo330
Date:
Sat Apr 14 15:56:03 2018 +0000
Revision:
2:15a255321242
Parent:
1:aedc2645d841
This uses theSTM32L476VGTDI SCO KIT via the DHT11 sensor to read room temperature. The temperature can be read using Real Term or similar program.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaizen 0:3b6dd029d50c 1 #include "mbed.h"
kaizen 0:3b6dd029d50c 2 #include "DHT.h"
WIzMatthew 1:aedc2645d841 3
Camo330 2:15a255321242 4
Camo330 2:15a255321242 5 // STM32L476VGT DISCOVERY BOARD
Camo330 2:15a255321242 6 // DHT11 SENSOR RUNNING FROM 3V3 SUPPLY
Camo330 2:15a255321242 7 // PULL DOWN WITH 10K RESISTOR
Camo330 2:15a255321242 8 // DATA VIA THE PIN PA_0
Camo330 2:15a255321242 9 // COM PORT 4 AT 9600 BAUD
Camo330 2:15a255321242 10
Camo330 2:15a255321242 11
Camo330 2:15a255321242 12 #define DHT_DATA_PIN PA_0 // sets pin PA_0 as data input
kaizen 0:3b6dd029d50c 13
Camo330 2:15a255321242 14 DHT sensor(DHT_DATA_PIN, DHT11);
Camo330 2:15a255321242 15 //DHT(PinName pin, eType DHTtype)
kaizen 0:3b6dd029d50c 16
kaizen 0:3b6dd029d50c 17 int main()
kaizen 0:3b6dd029d50c 18 {
kaizen 0:3b6dd029d50c 19 int error = 0;
Camo330 2:15a255321242 20 float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
Camo330 2:15a255321242 21
WIzMatthew 1:aedc2645d841 22 while(1)
WIzMatthew 1:aedc2645d841 23 {
WIzMatthew 1:aedc2645d841 24 wait(2.0f); //wait 2 second
WIzMatthew 1:aedc2645d841 25 error = sensor.readData(); //read error value
WIzMatthew 1:aedc2645d841 26 if (error == 0) //case: no error
WIzMatthew 1:aedc2645d841 27 {
kaizen 0:3b6dd029d50c 28 c = sensor.ReadTemperature(CELCIUS);
kaizen 0:3b6dd029d50c 29 f = sensor.ReadTemperature(FARENHEIT);
kaizen 0:3b6dd029d50c 30 k = sensor.ReadTemperature(KELVIN);
kaizen 0:3b6dd029d50c 31 h = sensor.ReadHumidity();
kaizen 0:3b6dd029d50c 32 dp = sensor.CalcdewPoint(c, h);
kaizen 0:3b6dd029d50c 33 dpf = sensor.CalcdewPointFast(c, h);
Camo330 2:15a255321242 34 printf("F: %4.2f, \r\n", f); //prints temp in farenheit to Real Term
Camo330 2:15a255321242 35 // printf("H: %4.2f, \r\n", h); //prints humidity to Real Term
Camo330 2:15a255321242 36 printf(" \r\n "); //acts as empty line to space readings in Real Term
Camo330 2:15a255321242 37 printf(" \r\n "); //acts as empty line to space readings in Real Term
WIzMatthew 1:aedc2645d841 38 }
WIzMatthew 1:aedc2645d841 39 else //case: error
WIzMatthew 1:aedc2645d841 40 {
Camo330 2:15a255321242 41 printf("Error: %d\r\n", error); //prints error to Real Term when "if" criteria isn't satisfied
kaizen 0:3b6dd029d50c 42 }
kaizen 0:3b6dd029d50c 43 }
kaizen 0:3b6dd029d50c 44 }