Notifications
Clear all

DHT Sensors  

Page 2 / 2
  RSS

Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-12 8:15 pm  

Ok, let's make sure we are on the same page.

 

* Have you ever got the sensor to work while connected to the 5V source, power switching or not?

    If not we may have new problems to deal with.

* If you haven't got it to work while connected to 5V, did you level shift the 5V signal out of the sensor down to the 3.3V signals your processor needs. If not please do this before damage is done to the processor. Or switch back to the 3.3V source for the sensor.

 


ReplyQuote
MikeBurton_2000
(@mikeburton_2000)
Active Member
Joined: 9 months ago
Posts: 13
2020-05-13 10:14 pm  

@byron Hi again Byron. I think it's my poor description that's clouding the waters.

If the sketch is left as is and D5 is used to connect to VCC on the sensor, it will power up when the pin is on, but the sensor returns "nan".

With no other changes, only moving the VCC of the sensor to either a 3v pin on the MCU or 3.3v or 5v supply from a breadboard power supply, then the sensor returns a T & H reading as it should.

In another scenario, again with the same sketch set up using D5 to switch a 2N2222 transistor in turn switching on the sensor, it again returns nan.

I've also tried connecting it into the transistor switching the soil moisture probes on the larger project (different example of the same NodeMCU) but again, nan is the result.

I am awaiting some PNP transistors to come to try instead of the NPN, as per the reply from Ruplicator above.

I hope this clears things a little but let me know if not. Thanks again for your assistance.

Ooops, I did it again!


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 303
2020-05-13 11:16 pm  

@mikeburton_2000

OK a couple of thoughts for what they're worth. From your explanation the only difference from a working DHT11 to a not working one is how you supply the VCC.  If 3.3 or 5 volts is direct supplied it works but if VCC comes from the D5 is does not.  So whats going on with D5? Well you are driving it high though code. but whats voltage are you getting from the pin.  Also, the 3,3 or 5 volts supplied direct to VCC is presumable on all the time.  What happens if you put a switch in this circuit to mimic the on-off you do with the D5 pin in code. Does the DHT11 still play?

This post was modified 2 months ago 2 times by byron

ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-14 1:03 am  

Mike,

Trying Byron's suggestion is good and will give you another diagnostic point. I believe this is all pointing to 2 different problems in the same area.

1. Trying to drive the DHT directly from the GPIO is not providing enough stable power to the sensor. The 3.3V output is very close to the DHT11's operational limits and any fluctuation in the sensor's power source is causing data corruption which results int nan you keep seeing.

2. Trying to use the 2N2222 means you are not switching the power to the sensor but you are removing the ground. If it was a perfect world where transistors were perfect switches it wouldn't matter. But the transistor has a voltage drop across it when it is turned on. The 2N2222 is one of the better switching transistors with only about .3 volts between the collector and emitter when it is turned on hard. However, this means your sensor's ground is not the same as the processor and this is never good when trying to transfer digital data.

After reading the spec sheet I believe you will need to use the 5V source (because of transistor losses) and you will need to also add a capacitor between the PNP transistor's output collector and ground. My guess it will need to be larger than what the spec sheet called out as it was written with the assumption that power would be continuously supplied with no components in series between the sensor and the supply voltage. You may want to start with something like a 1 uf and see if that is enough.

Also when I proposed the PNP circuit I was thinking your processor would have and open collector output on its GPIO pins during output. That is a mistaken assumption on my part. The GPIO pin on your processor swings between 0V for a LOW output and 3.3V for a HIGH output. The base on the PNP transistor connected in the configuration I proposed earlier will be setting .6V below the supply voltage ( 5V - .6V = 4.4V). You can see the GPIO pin does not go high enough to ever turn the PNP transistor off. 

There is an easy solution. Use your current 2N2222 setup to drive the 4.7K resistor on the base of the PNP transistor. When the existing 2N2222 is turned off it will place 5V on the base of the PNP turning it off. When the 2N2222 is turned on current will flow through the PNP emitter to base junction turning it on, providing power to the sensor.

Don't forget that you will need a voltage divider on the sensor's data pin to ensure there is no damage done to your processor. The sensor will now output 0-5V on its data pin and your processor input accepts 0-3.3V.


ReplyQuote
MikeBurton_2000
(@mikeburton_2000)
Active Member
Joined: 9 months ago
Posts: 13
2020-05-27 5:20 pm  

Hi all, I am sorry it has been a while since I last updated this thread with my progress; I have been quite busy with work.

I thought I would let you know that I have now solved the problem I was having and have the GreenHouse monitor up and running using transistors to switch both the soil moisture sensors and the DHT sensor on and off. Not only that but I have implemented the Deep Sleep mode between reads to increase battery life (I was getting about 2 - 2.5 days out of a 6v Lead Acid battery); I will let you know how long it runs for.

I ended up doing a bit more learning and testing and failing and re-learning etc. The final solution came in the form of using the existing NPN transistor that was switching the soil sensors on and off and using its output to switch a PNP transistor to send the 5v to the DHT. I think the required resistor on the N side may have been the source of my initial failure as once I had read more, done some calculations and a test build or two, I got it working and reading the DHT correctly.

Greenhouse Monitor 3x Soil DHT Deep Sleep bb

 

//INCLUDES
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Blynk.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
//------------------------------

// DEFINITIONS
int16_t adc0, adc1, adc2; //create 16bit integer for adc channel A0
//int16_t adc1;
//int16_t adc2;

#define BLYNK_PRINT Serial
#define TRANS D8 // Digital pin for Transistor
#define DHTPIN D4 // Digital pin for T and H
#define LEDG D7 // Digital pin for LED Green
#define LEDR D6 // Digital pin for LED Red
#define DHTTYPE DHT11 // DHT 11
//------------------------------

//WiFi & Blynk Info
char auth[] = "put your Blynk auth here";
char ssid[] = "TP-LINK_B12408";
//char ssid[] = "Riverside 4G 2.4Ghz";
char pass[] = "password goes here";
//char pass[] = "password goes here";
int status = WL_IDLE_STATUS;

//Class
DHT dht(DHTPIN, DHTTYPE);
Adafruit_ADS1115 ads;
BlynkTimer timer;
WiFiClient client;
//------------------------------

//SETUP

void setup() {
Serial.begin(9600);
ads.begin();
dht.begin();
ads.setGain(GAIN_ONE);

timer.setInterval(5000L, SendSensor);

pinMode(LEDG, OUTPUT);
pinMode(TRANS, OUTPUT);
pinMode(LEDR, OUTPUT); // set the digital pin as output

digitalWrite(LEDG, LOW);
digitalWrite(LEDR, LOW);

Serial.println("Connecting to ");
Serial.println(ssid);
SendSensor();
}

//------------------------------

//FUNCTIONS

void SendSensor() //Sending DHT Sensor Info
{

Blynk.run(); // T&H
timer.run(); // T&H

// read the value from Moisture sensors:
digitalWrite(TRANS, HIGH); //Turn on transistor
delay(15000); //Allow to stabilise for 15-20s

float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}

delay(150);
adc0 = map(ads.readADC_SingleEnded(0), 9000, 30784, 98, 0);
delay(250);
adc1 = map(ads.readADC_SingleEnded(1), 9000, 30784, 98, 0);
delay(250);
adc2 = map(ads.readADC_SingleEnded(2), 9000, 30784, 98, 0); //Calibration Note: Compost is less resistive then soil/soil & compost mix. Use 8000-9000 for wet compost 6500 - 8000 for wet soil. dry sand = 30784
delay(250);

digitalWrite(TRANS, LOW);
delay(500);
Wificonnect();
delay(1000);

Blynk.begin(auth, ssid, pass);
delay(500);

Blynk.virtualWrite(V5, h);
Serial.print(h);
Serial.println("% ");
Blynk.virtualWrite(V6, t);
Serial.print(t);
Serial.println("°C");

Blynk.virtualWrite(V7, adc0);
Serial.print("Moisture Sensor 1 ");
Serial.println(adc0);
Serial.println(ads.readADC_SingleEnded(0));

Blynk.virtualWrite(V8, adc1);
Serial.print("Moisture Sensor 2 ");
Serial.println(adc1);
Serial.println(ads.readADC_SingleEnded(1));

Blynk.virtualWrite(V9, adc2);
Serial.print("Moisture Sensor 3 ");
Serial.println(adc2);
Serial.println(ads.readADC_SingleEnded(2));

Serial.println("----------------------------------------");

//adc0 = 1;
//adc1 = 2;
//adc2 = 3;

WiFi.disconnect();
delay(250);
WiFi.forceSleepBegin();
digitalWrite(LEDG, LOW);
digitalWrite(LEDR, HIGH);
Serial.println("WiFi Sleep");
delay(100);
ESP.deepSleep(1.2e+9);
}
//------------------------------

void Wificonnect() {
WiFi.forceSleepWake();
delay(250);
WiFiClient client;

WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
digitalWrite(LEDG, HIGH);
digitalWrite(LEDR, LOW);
delay(150);
Serial.print(".");
digitalWrite(LEDG, LOW);
digitalWrite(LEDR, HIGH);
delay(150);
}
digitalWrite(LEDR, LOW);
{
Serial.println("");
if (WiFi.status() == WL_CONNECTED)
{
digitalWrite(LEDG, HIGH);
Serial.println("Wifi OK");
}
if (WiFi.status() == WL_DISCONNECTED)
{
digitalWrite(LEDR, HIGH);
Serial.print("WiFi Not Connected");
}
}delay(500);
}
//------------------------------

 

void loop() {

}

Still probably needs some tidying up but I changed the sketch around a bit to incorporate the Deep Sleep and it is currently running in the greenhouse giving me sensible reads etc. I know the DHT11 is less accurate than the DHT22 and this, in turn, is a poor cousin to som either sensor types. However, at the moment it is working for me and helping me keep everything alive.

I am looking to change to capacitive sensors instead of resistive for the soil moisture, and will probably switch to a DHT22 as I notice the RH is very high first thing in the morning and the DHT11 does not like being in the top end of the scale. That said, it seems to dry out and get back to normal by mid-morning. I guess it will die sooner or later, but for the price, it does not matter too much.

Next steps include changing to Capacitive soil moisture sensors and adding a solar panel and charge controller to keep the battery topped up. I will probably also seek out better temperature and hydrometer sensors for longevity. I'm looking at increasing the moisture sensing zones and adding auto watering too.

I would like to thank all those who offered info, guidance and solutions thus far.

This post was modified 2 months ago by MikeBurton_2000

Ooops, I did it again!


ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-27 5:54 pm  

Glad to hear of your progress. I also tried the ESP8266 on a weather station project I'm working on but unfortunately I had to switch to the ESP32 because the number of I/O pins on the ESP8266 was much less in reality than I thought. Have you thought about making your own capacitance probes? 

 


ReplyQuote
MikeBurton_2000
(@mikeburton_2000)
Active Member
Joined: 9 months ago
Posts: 13
2020-05-28 6:54 am  

@ruplicator Yes I would like to make the probes at some point. I am taking baby steps at the moment in developing my ability but it is something I am interested in trying. I made the resistive probes because I understood how and why they work as I use something similar in my work. I am balancing things around available time for the hobby and "real life" at the moment and whilst we are in the midst of this pandemic I find I have some extended periods of hobby time followed by random periods of manic working time. 

I will continue to tinker and add to this project until I have something I am happy is working correctly and has the possibility of a sensible life span. As it is with the cheap sensors etc I don't think it is a viable long term 'product' and despite it only being for my personal interest it needs to last.

Adding the auto watering for certain zones within the greenhouse comes next but the pumps and valves will have a bit of power draw so I am awaiting the Orient Express to bring the solar power stuff to run it all. Then as we head towards winter, everything will need keeping warm, so there is an excuse to add temperature control too.

The whole reason for picking up the gauntlet with microcontrollers again was because I want to make a rig to test 3 phase BLDC pumps I use at work. I have a lot to learn to before I get to a solution for that and this project was a complete diversion (though most if not all the principals in the project can relate back to things found in my work), but I have learned some valuable stuff - not least the power of community!

Ooops, I did it again!


ReplyQuote
JoeLyddon
(@joelyddon)
Reputable Member
Joined: 10 months ago
Posts: 273
2020-05-28 7:03 am  

@ruplicator

I'm curious as to what you are doing that requires so many IO pins?

For my master station, it's primarily a Collector from the remotes using the LRF24L01's to communicate with all of the remotes.

So far, it appears that the Arduino NANO could be used for the remotes which would only report Temp, Humidity, & possibly a soil moisture Reading to the Master...  when the Master calls for it.

The Master will probably be the UNO because of the Program Memory required...  but will not be strapped for IO pins.

Thank you.

 

Have Fun,
Joe Lyddon

www.woodworkstuff.net


ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-28 1:32 pm  

A little background to explain all the I/O required for my project. The weather station project I'm working on uses ultrasonic sound for wind speed and direction. The 4 sonic transducers used for measurement have to be used in both transmit and receive mode. To accomplish this and use low-cost components I used the transducers from 2 HC-SR04 and an analog multiplexer to route the signals from the transducers to one HC-SR04 logic unit.

The I/O requirements are 2 outputs for mux addressing and 1 for mux chip enable. One output for the HC-SR05 trigger and one input for Echo. So just for wind measurements there are 4 outputs and 1 input. The other sensors in the station include rain amount and rate requiring one input, a BME280 for temp, humidity and pressure taking 2 pin for the I2C interface, one analog input for the UV sensor and another digital input for particle detection unit for pollen detection.

The ESP8266 was very close to accomplishing my needs but there are additional restrictions that some pins can't be pulled low and other can't be pulled high during boot that I was not aware of when I started with the MCU that kept tripping me up. After several days of research, trial and error experimentation, no combination gave the needed I/O without a restriction.

The ESP32 is much more functionality than I needed but for a similar cost I now see why people are switching to it. In my short experience with the two MCUs I found the ESP32 is less finicky about it's power requirements and has significantly less got-ya's on boot restrictions.


ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-28 1:54 pm  

@mikeburton_2000

I think a lot of us hobbyist are in the mode of having a solution that is looking for a problem they can solve. It's great to see some practical application for these MCUs.

I was watching a YouTube video last night about a guy who built a robot (it looked very much like a scaled-up version of a 3D printer) called FarmBot.  The bot had access to several different types of tools that magnetically attached to a movable head for planting, watering and weeding. It looked like a lot of technology and cost to solve minor problems. But is was fun to watch it watering and weeding unattended.


ReplyQuote
JoeLyddon
(@joelyddon)
Reputable Member
Joined: 10 months ago
Posts: 273
2020-05-28 11:31 pm  
Posted by: @ruplicator

@mikeburton_2000

I think a lot of us hobbyist are in the mode of having a solution that is looking for a problem they can solve. It's great to see some practical application for these MCUs.

I was watching a YouTube video last night about a guy who built a robot (it looked very much like a scaled-up version of a 3D printer) called FarmBot.  The bot had access to several different types of tools that magnetically attached to a movable head for planting, watering and weeding. It looked like a lot of technology and cost to solve minor problems. But is was fun to watch it watering and weeding unattended.

Do you have a LINK to such a Video?!   Sure sounds interesting!  YES?!

And it knows a weed from a tomato seedling?  🙂

 

 

Have Fun,
Joe Lyddon

www.woodworkstuff.net


ReplyQuote
JoeLyddon
(@joelyddon)
Reputable Member
Joined: 10 months ago
Posts: 273
2020-05-29 12:10 am  

@ruplicator

WOW!  You're really into it!

I picture Remotes...  Wind Reporting Remote...  Rain Measurement Remote... Temp., Humidity, Pressure Remote...  Pollen sensing Remote...  etc. etc.

Then, in the Master Station, all remotes will be interrogated as required gathering & processing it's information...  Setting OFF any required ALERTS and communications to Action Remotes like Turn on the Water...  Activate Weed Eating remote...  Remote to call the cat due to recognizing a mouse / rat...

The Master is just controlling when to look at the various remotes... 

All remotes having their own I.D. Char/number... using the NRF24L01's to communicate to the Master,   Saving all readings (+ date & time stamp) from all remotes to a SDcard file for further analysis... as well as Displaying key information on a screen...  Buttons to control various screens for various types of information.

Some remotes may be super simple using the ATiny MCU...  NANO...  UNO...  as required to do the job.

Result is using the KISS principle... 

The Master may have to be a MEGA just for the additional memory that may be needed.  (?)

Am I on the wrong track thinking this way?

Bill has done a great job in introducing & working with the ESP32...  Makes one think a little... 

Could be using an ESP32 CAM in certain Remotes to report VIDEO of someone stealing those Avocados from your avocado tree, sounding off a Silent alarm causing the police to be called, if required.   

Of course, the WeedEating Remote would have to have the ESP32 Cam so it could detect good-stuff from weeds!  🙂   

Then comes the Laser Armed Remotes to detect insects like Grasshoppers, Beetles, etc. and ZAP them in their tracks stopping them from eating those great tomatoes, etc.!

Isn't this FUN!  🙂

 

 

Have Fun,
Joe Lyddon

www.woodworkstuff.net


ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-29 1:31 pm  
Posted by: @joelyddon

Do you have a LINK to such a Video?!   Sure sounds interesting!  YES?!

And it knows a weed from a tomato seedling?  🙂

Here is the link to FarmBot

And yes and no on does it know weed from seedling. Since it is used to plant the seedlings it knows where they should be and it was implied that it tracks the growth of the plant. With that information any thing outside of the calculated area of the plant is defined as a weed.


ReplyQuote
Ruplicator
(@ruplicator)
Trusted Member
Joined: 3 months ago
Posts: 95
2020-05-29 2:06 pm  
Posted by: @joelyddon

WOW!  You're really into it!

Ha ha! Well not to that degree. I only got into this stuff a month or so back. I had dabbled in software in my career but nothing serious, just small hacks to solve specific problems. But being exposed to these inexpensive MCUs and sensors peeked my interest. Like most I wanted to try something that would use a number of functions and would like to create something useful. 

The primary thing that got me fired up was the discovery of the sonic wind sensor. Even though I could buy one off the shelf I was very interested in the technology, the math, the fact there would be no moving parts and I thought I had a chance to build some of it myself. The rest of the sensors got added just because I could.

Using components from HC-SR05 that is built for measuring distance and repurposing them to measure the difference in sound speed due to wind movement was very appealing to me. Using these sensors for an outdoor project is not the smartest idea but it started as more of a proof of concept and if it appears to work I can always change them out.

I must admit I'm at the limit of what the HC-SR05 and it's components can perform. I now have is a lot of software involved to make up for its lack of repeatability and the noisy environment. My current environment is a mass of wires on a breadboard. The electrical noise with all the sensors running is having a significant impact on repeatability of my wind sensor readings. When I recently moved to the ESP32 I had to rebuild most of the circuitry. I started with the wind sensor and got very stable reading with no other sensors operational. So I'm hoping the move from breadboard to perf board will reduce the electrical noise associated with long wires.


ReplyQuote
JoeLyddon
(@joelyddon)
Reputable Member
Joined: 10 months ago
Posts: 273
2020-05-29 9:16 pm  

@ruplicator

Thank you!

That's awesome!  It's just like a CNC machine!!

Great work he did...   If he could use a Magazine for seeds, it could be a lot faster to plant'em!  🙂 ll seeds might be a problem... very fine to larger...  looks like it would like Radish & onion seeds...

Yes, if he used a Pi with a Camera, it could be trained to recognize GOOD plants vs weeds and pluck'em before they got very big.

Thank you!  COOL!

 

 

Have Fun,
Joe Lyddon

www.woodworkstuff.net


ReplyQuote
Page 2 / 2