Balkrishna Wagle
/
mbed_dht11_MYBOARDCODE
DHT11 - P22
main.cpp@0:62fe467ea077, 2018-03-08 (annotated)
- Committer:
- rajivwagle
- Date:
- Thu Mar 08 12:18:32 2018 +0000
- Revision:
- 0:62fe467ea077
DHT11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rajivwagle | 0:62fe467ea077 | 1 | #include "mbed.h" |
rajivwagle | 0:62fe467ea077 | 2 | #include "DHT.h" |
rajivwagle | 0:62fe467ea077 | 3 | |
rajivwagle | 0:62fe467ea077 | 4 | DigitalOut myled(LED1); |
rajivwagle | 0:62fe467ea077 | 5 | Serial pc(USBTX,USBRX); |
rajivwagle | 0:62fe467ea077 | 6 | DHT sensor(p22,DHT11); // Use the SEN11301P sensor |
rajivwagle | 0:62fe467ea077 | 7 | |
rajivwagle | 0:62fe467ea077 | 8 | int main() { |
rajivwagle | 0:62fe467ea077 | 9 | int err; |
rajivwagle | 0:62fe467ea077 | 10 | pc.printf("\r\nDHT Test program"); |
rajivwagle | 0:62fe467ea077 | 11 | pc.printf("\r\n******************\r\n"); |
rajivwagle | 0:62fe467ea077 | 12 | wait(1); // wait 1 second for device stable status |
rajivwagle | 0:62fe467ea077 | 13 | while (1) { |
rajivwagle | 0:62fe467ea077 | 14 | myled = 1; |
rajivwagle | 0:62fe467ea077 | 15 | err = sensor.readData(); |
rajivwagle | 0:62fe467ea077 | 16 | if (err == 0) { |
rajivwagle | 0:62fe467ea077 | 17 | pc.printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); |
rajivwagle | 0:62fe467ea077 | 18 | pc.printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); |
rajivwagle | 0:62fe467ea077 | 19 | pc.printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); |
rajivwagle | 0:62fe467ea077 | 20 | pc.printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); |
rajivwagle | 0:62fe467ea077 | 21 | pc.printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
rajivwagle | 0:62fe467ea077 | 22 | pc.printf("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); |
rajivwagle | 0:62fe467ea077 | 23 | } else |
rajivwagle | 0:62fe467ea077 | 24 | pc.printf("\r\nErr %i \n",err); |
rajivwagle | 0:62fe467ea077 | 25 | myled = 0; |
rajivwagle | 0:62fe467ea077 | 26 | wait(100); |
rajivwagle | 0:62fe467ea077 | 27 | } |
rajivwagle | 0:62fe467ea077 | 28 | } |