DHT and LDR separately working, but together not, what's wrong?
-
@sundberg84 My node is approx 3 meters away from the gateway, and now I am powering it from the computer, it's an Arduino Nano with USB cable.
-
I have now rebooted my GW so sending will be OK:
send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5 send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0 sensor started, id=1, parent=0, distance=1 send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=fail:HumidityAndLight send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.2 send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail: send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail: find parent send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: send: 1-1-0-0 s=2,c=0,t=16,pt=0,l=0,sg=0,st=fail: Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=fail:61.2 L: 61.2 Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:6.9 L: 6.9 Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:7.1 L: 7.1 -
I have now rebooted my GW so sending will be OK:
send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5 send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0 sensor started, id=1, parent=0, distance=1 send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=fail:HumidityAndLight send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:0.2 send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=fail: send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=fail: find parent send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: send: 1-1-0-0 s=2,c=0,t=16,pt=0,l=0,sg=0,st=fail: Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=fail:61.2 L: 61.2 Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:6.9 L: 6.9 Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:7.1 L: 7.1@DannyM You still have some failures. I noticed that they're present in the Humidity only sketch as well.
In my experience it's better to power nothing from the Arduino. The radio only works always, but using a phone charger will give you 5v and using a buck boost converter (80 euro cents on aliexpress) can provide 3.3V. As an alternative for the buck converter a low drop LE33 works perfectly for me.
But please attache capacitor to all radio's (gateway and nodes). And try to power as less as you can from the arduino. The arduino just wasn't designed to deliver a lot of current.
-
Maybe This has something to do with it:
dht.setup(LIGHT_SENSOR_ANALOG_PIN);The Lightsensor isn't belonging to the DHT sensor.. I think :-\
@DannyM Could be. But I doubt it. Look here.
TempHum only: send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5 send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0st=fails means that the radio can't deliver the message to the gateway. If a message could be delivered st will be ok
Failed reading temperature from DHT Failed reading humidity from DHT send: 1-1-0-0 s=2,c=1,t=23,pt=7,l=5,sg=0,st=ok:6.9The failed reading is certainly caused by initializing the DHT with the wrong pin.
Anyway I hope that you're able to get this to work with the help of others. I wouldn't be much online this weekend. But I'm hoping to see a positive post from you in this thread (meaning you got it working ;-)).
Might be a good idea to start with the humidity temp sensor only. And see if you can get to work without any st=fail's in your log. Then you can go to the next step.
-
Hi all,
Now I have bought a stepdown regulator to regulate the power for the radio.
The readings of the sensor are the same as not using the stepdown regulator. So what can be wrong?
Or is it not possible to use a LDR and a DHT11 together?Yes you can use LDR and a DHT11 together.
* 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 * * DESCRIPTION * Example sketch showing how to measue light level using a LM393 photo-resistor * http://www.mysensors.org/build/light */ // Enable debug prints to serial monitor #define MY_DEBUG // NodId #define MY_NODE_ID 99 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //Including nescessary libraries #include <SPI.h> #include <MySensors.h> #include <DHT.h> // 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; //Defining child ID #define CHILD_ID_LIGHT 0 #define CHILD_ID_HUM 1 #define CHILD_ID_TEMP 2 //Defining Pin #define DHT_DATA_PIN 3 #define LDR_PIN A0 //Defining values to store sensor information float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; int lastLightLevel; //Defining sleep and wait times unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)(30 seconds) #define MESSAGEWAIT 500 MyMessage LightMsg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); 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 and Controller sendSketchInfo("Temp Fukt Ljus", "1.0"); // 2017 02 05 // wait(MESSAGEWAIT); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); // wait(MESSAGEWAIT); present(CHILD_ID_HUM, S_HUM); // wait(MESSAGEWAIT); 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++; } int lightLevel = (1023-analogRead(LDR_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(LightMsg.set(lightLevel)); lastLightLevel = lightLevel; } sleep(SLEEP_TIME); }LDR pin A0
DHT pin 3
And i use pro mini.
//Mattias
-
Yes you can use LDR and a DHT11 together.
* 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 * * DESCRIPTION * Example sketch showing how to measue light level using a LM393 photo-resistor * http://www.mysensors.org/build/light */ // Enable debug prints to serial monitor #define MY_DEBUG // NodId #define MY_NODE_ID 99 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //Including nescessary libraries #include <SPI.h> #include <MySensors.h> #include <DHT.h> // 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; //Defining child ID #define CHILD_ID_LIGHT 0 #define CHILD_ID_HUM 1 #define CHILD_ID_TEMP 2 //Defining Pin #define DHT_DATA_PIN 3 #define LDR_PIN A0 //Defining values to store sensor information float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; int lastLightLevel; //Defining sleep and wait times unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)(30 seconds) #define MESSAGEWAIT 500 MyMessage LightMsg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); 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 and Controller sendSketchInfo("Temp Fukt Ljus", "1.0"); // 2017 02 05 // wait(MESSAGEWAIT); // Register all sensors to gateway (they will be created as child devices) present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); // wait(MESSAGEWAIT); present(CHILD_ID_HUM, S_HUM); // wait(MESSAGEWAIT); 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++; } int lightLevel = (1023-analogRead(LDR_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(LightMsg.set(lightLevel)); lastLightLevel = lightLevel; } sleep(SLEEP_TIME); }LDR pin A0
DHT pin 3
And i use pro mini.
//Mattias
-
Hi, thanks for your input, whit setup of the pins you used I have no more failed to read from DHT sensors in my serial monitor.
Now I need to revise my sketch, so it will send correct values.
Thanks again!
-