DHT11 Arduino pro mini no temp readings
-
Hi,
I'm trying to get my first sensor working. A DHT11 temp/ humidity sensor. I followed the instructions from the build part on Mysensors. Uploaded the sketch and had a look at the serial monitor.
There it appeared that no temperatures are coming up. So I had a look at the connections and all seems fine to me. What could be the problem? Power?
Also, having a look at the serial log, does it communicate with the gateway? I think so, but which lines are referring to that?
The parts with: TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1 ?Any advise on how to get the DHT11 to work? Thanks.
Using the DHTlibrary as mentioned in the instructions.
Arduino 1.8.2
Mysensors 2.1.1
Arduino pro mini ordered from aliexpress I am not sure which version I have both 3.3 volt and 5volt version (how to determine?).0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 4 TSM:INIT 4 TSF:WUR:MS=0 12 TSM:INIT:TSP OK 14 TSM:INIT:STATID=1 16 TSF:SID:OK,ID=1 18 TSM:FPAR 18 TSM:FPAR:STATP=0 20 TSM:ID 22 TSM:ID:OK 24 TSM:UPL 32 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 47 TSF:MSG:READ,0-0-1,s=255,c=3,t=25,pt=1,l=1,sg=0:1 53 TSF:MSG:PONG RECV,HP=1 55 TSM:UPL:OK 57 TSM:READY:ID=1,PAR=0,DIS=1 71 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 79 TSF:MSG:READ,0-0-1,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 90 TSF:MSG:SEND,1-1-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 100 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2117 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:TemperatureAndHumidity 2129 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.1 2144 TSF:MSG:SEND,1-1-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2154 TSF:MSG:SEND,1-1-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK: 2160 MCO:REG:REQ 2166 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2226 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2232 MCO:PIM:NODE REG=1 2234 MCO:BGN:STP 2236 MCO:SLP:MS=1000,SMS=0,I1=255,M1=255,I2=255,M2=255 2242 MCO:SLP:TPD 2244 MCO:SLP:WUP=-1 2246 MCO:BGN:INIT OK,TSP=1 Failed reading temperature from DHT! Failed reading humidity from DHT 2269 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 2279 MCO:SLP:TPD 2281 MCO:SLP:WUP=-1 Failed reading temperature from DHT! Failed reading humidity from DHT 2304 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 2314 MCO:SLP:TPD 2316 MCO:SLP:WUP=-1 Failed reading temperature from DHT! Failed reading humidity from DHT 2336 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 2347 MCO:SLP:TPD 2349 MCO:SLP:WUP=-1``` Any help would be appreciated. Thanks. W.
-
Well, something is wrong with either the wiring or sensor. If you have a multimeter, you should probably do a continuity test on the connections.
-
@hek Thanks for the reply. I just did a test with my multimeter and measuring at the dht11 it shows 3.46 so that should be ok right?
I used the DHT11 some time ago with an esp8266 and than it was working fine. Could the pin 3 data be the problem?
-
Hi, which sensor do you use ?
A DHT put on a pcb or without pcb ?
If you haven't a DHT with pcb, you need to put a 5k resistor between pin 1 and 2 of the DHT
More information here : https://www.mysensors.org/dl/57c3ec0c4d04abe84cd93e0f/design/DHT11.pdf
-
@tonnerre33 No I have one with pcb.
-
@Mr_sensor Stil get the message
Failed reading temperature from DHT!
Failed reading humidity from DHTAlso tried it with an dh22 I had (included a pull-up resistor between vcc and data) but get the same result. What can I do to get this working?
If I use the arduino pro mini for an other sensor they are working fine (tested with a magnet-reed switch).
-
have you set all the waiting/delay times and the initialization before reading the temperature (as seen in the examples)?
-
This is the sketch I'm using.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0: Henrik EKblad * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz) * * DESCRIPTION * This sketch provides an example of how to implement a humidity/temperature * sensor using a DHT11/DHT-22. * * For more information, please visit: * http://www.mysensors.org/build/humidity * */ #define MY_NODE_ID 2 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //#define MY_RS485 #include <SPI.h> #include <MySensors.h> #include <DHT.h> // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 3 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 60000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void presentation() { // Send the sketch version information to the gateway sendSketchInfo("TemperatureAndHumidity", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); metric = getControllerConfig().isMetric; } void setup() { dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); } void loop() { // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy sleep(UPDATE_INTERVAL); }
-
since I did not get these Dht11 or Dht22 working, I decided to try an other sensor type to see if that would work better.
So I connected a HTU21D sensor and included the library from sparkfun. Using there demo sketch I can see the sensor is working fine:HTU21D Example!
Time:192 Temperature:20.8C Humidity:998.0%
Time:1318 Temperature:20.8C Humidity:47.3%
Time:2445 Temperature:20.7C Humidity:47.4%
Time:3571 Temperature:20.7C Humidity:47.4%
Time:4698 Temperature:20.7C Humidity:47.5%
Time:5824 Temperature:20.7C Humidity:47.5%
Time:6948 Temperature:20.7C Humidity:47.6%
Time:8075 Temperature:20.7C Humidity:47.6%
Time:9201 Temperature:20.7C Humidity:47.6%But when I include the "adapted" Mysensors sketch I found here in the forum it seems the temperatures are not read or something else is wrong?
This is what is in the log file in a ongoing loop:
MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 4 TSM:INIT 4 TSF:WUR:MS=0 12 TSM:INIT:TSP OK 14 TSM:INIT:STATID=2 16 TSF:SID:OK,ID=2 18 TSM:FPAR 18 TSM:FPAR:STATP=0 20 TSM:ID 22 TSM:ID:OK 22 TSM:UPL 28 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 47 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1 53 TSF:MSG:PONG RECV,HP=1 55 TSM:UPL:OK 57 TSM:READY:ID=2,PAR=0,DIS=1 63 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 75 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 86 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 96 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2107 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity 2119 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0 2129 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2140 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK: 2146 MCO:REG:REQ 2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2220 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2226 MCO:PIM:NODE REG=1 2228 MCO:BGN:INIT OK,TSP=1 2 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 6 TSM:INIT 6 TSF:WUR:MS=0 14 TSM:INIT:TSP OK 16 TSM:INIT:STATID=2 18 TSF:SID:OK,ID=2 20 TSM:FPAR 20 TSM:FPAR:STATP=0 22 TSM:ID 24 TSM:ID:OK 26 TSM:UPL 30 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 57 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1 63 TSF:MSG:PONG RECV,HP=1 67 TSM:UPL:OK 67 TSM:READY:ID=2,PAR=0,DIS=1 73 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 92 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 102 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 112 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 2121 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:Humidity 2134 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:2.0 2144 TSF:MSG:SEND,2-2-0-0,s=0,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2154 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK: 2160 MCO:REG:REQ 2164 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 2234 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1 2240 MCO:PIM:NODE REG=1 2242 MCO:BGN:INIT OK,TSP=1
This is the sketch I use now I had to adopt it since it seemed to be for an older version of Mysensors. I'm no programmer so it might be messed up somehow
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0: Henrik EKblad * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz) * * DESCRIPTION * This sketch provides an example of how to implement a humidity/temperature * sensor using a DHT11/DHT-22. * * For more information, please visit: * http://www.mysensors.org/build/humidity * HTU21D Humidity Sensor Hardware Connections (Breakoutboard to Arduino): -VCC = 3.3V -GND = GND -SDA = A4 (use inline 330 ohm resistor if your board is 5V) -SCL = A5 (use inline 330 ohm resistor if your board is 5V) */ #define MY_NODE_ID 2 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //#define MY_RS485 #include "SparkFunHTU21D.h" #include <MySensors.h> #include <Wire.h> #include <SPI.h> // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] //static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; boolean metric = true; void presentation() { // Send the Sketch Version Information to the Gateway sendSketchInfo("Humidity", "2.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); //metric = getControllerConfig().isMetric; } unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) //Create an instance of the object HTU21D myHumidity; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void loop() { float temperature = myHumidity.readTemperature(); //if (!metric) { // temperature = (temperature * 1.8) + 32.0; //} send(msgTemp.set(temperature, 1)); float humidity = myHumidity.readHumidity(); send(msgHum.set(humidity, 1)); sleep(SLEEP_TIME); //sleep a bit }
Can anyone advise me on the code and the error log so I understand what's going on and what needs to be done to get it working? Thanks a lot.
W.
-
@Mr_sensor I think you need to add
void setup() { myHumidity.begin(); }
Without that, the sensor/sensor library is not initialized.
(I looked at sparkfun's example sketch)
-
Great! That helped a lot. I Kicked that out when reading the Converting a sketch from 1.5 to 2.x article.
4911 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.4 4954 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:50.2 4962 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 4968 MCO:SLP:TPD
Now I only have to find out what to use for mqtt to read this sensor values. Thats still not very clear to me:
Guess it would be something like:
mygateway1-out/2/2/0/0/ or 2/2/0/0/1 ?Would it be possible to have something like this:
mygateway-out/2/2/Temperature ?
-
Ok found out what topic is send to mqtt turned out to be:
mygateway1-out/2/1/1/0/1 or mygateway1-out/2/0/1/0/1How to get an % and "C" to this topic value?
-
Just use any mqtt client and subscribe to topic # , you will be able to see all messages and pick the one you are looking for