/*############################################################# Program Name : ex1_DHT11_measure Author : Grant Phillips Date Modified : 2/05/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program that demonstrates the use of a DHT11 Humidity-Temperature Sensor. It is recommended not to initiate a read() quicker than every 200ms, otherwise the DHT11 will respond with an error. The output is displayed on a PC using the Serial Wire Viewer (SWV). See the SWV examples for an explanation of the use of this feature. Requirements : * STM32F4-Discovery Board Circuit : * The DHT11 sensor connected as: 1. VCC - 3V 2. DATA - PE15 (with a 5K6 pull-up resistor to 3V; pin is 5V tolerant) 3. NC - Not connected 4. GND - GND * A wire link between PB3 and pin6 of the SWD connector (CN2) as explained in the SWV examples section ##############################################################*/ #include "mbed.h" #include "SWO.h" #include "Dht11.h" //Eric Fossum's class library (Feb 2015) SWO_Channel SWO; Dht11 dht(PE_15); //Create a Dht11 object with DATA on PE_15 (must be DigitalInOut compatible pin) int main() { int hum, tempc; float tempf; while(1){ if(dht.read() == 0) { //initiate a read from the DHT11 sensor and check if the result is OK ( = 0) //get the values if result is OK hum = dht.getHumidity(); tempc = dht.getCelsius(); tempf = dht.getFahrenheit(); //display the values SWO.printf("Humidity = %d Temp (Celsius) = %d Temp (Fahrenheit) = %.1f\n", hum, tempc, tempf); } else { SWO.printf("Error!\n"); } wait(0.5); } }