Notifications
Clear all

ESP-32 and DHT22

Page 1 / 4

Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

Hi, thanks for all the videos and training material and the great website.

I would like to request interfacing of DHT22 and ESP-32 be demonstrated. I have seen the one you have with the Arduino, but I am looking to learn how the ESP-32 is used with the DHT22.

Thanks in advance.


Quote
Topic Tags
Mark Bolton
(@mark-bolton)
Eminent Member
Joined: 2 months ago
Posts: 48
 

I have had a play with those components. Just enough, to wet my toe but I intend to do some more with them.

More particularly to set up conditional actions. Ie when the temperature goes out side preset tlimits... fans . AC / Heaters etc get invoked.

M


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 
Posted by: @farzad_k

Hi, thanks for all the videos and training material and the great website.

I would like to request interfacing of DHT22 and ESP-32 be demonstrated. I have seen the one you have with the Arduino, but I am looking to learn how the ESP-32 is used with the DHT22.

Thanks in advance.

I have used the DHT22 and the other variants on an ESP32. It was exactly the same as any other arduino. There is a library for DHT sensors that is for ESP32 but I did not need or use that one. I used the original, declared what sensor I was using and chose a pin. Since it is an ESP 32, you can pick any GPIO pin.

 

You may need to add a resistor.

 

Here is a very detailed instruction that also includes Python if you are wanting to go that route:

https://learn.adafruit.com/dht/overview

 

But if you follow Bill's tutorial, it should be exactly the same except for the pin for data.

https://dronebotworkshop.com/arduino-temperature/

 

Was there something particular that you wanted to accomplish? Did you want it to display it on a web page?


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

@madmisha Thanks for the valuable information.

My astro-imaging rig has a stick-PC onboard it and the stick-PC runs all the software and hardware. It is connected to a WiFi access point where I can find it using my other PC, and iOS or OSX by remoting into it using the host access point. At home I just use the home router; in the field I carry a mini portable router which is a little box and needs to be powered and kept track of, etc.

When temperature and humidity is conducive to dew formation, dew may form on the front elements of the telescope, marking the end of imaging session. To remedy that we use heating straps in the vicinity of the front element to increase the temperature to somewhere above the dew temperature. I have a manual dew heater controller. I connect it to 12V from one end, and to the heating strap at the other end, and control how much power I provide to the strap by turning a knob. Because I am not a meteorologist I just begin heating the lens when I start imaging. Heaters can consume power and power is precious when you are in the field.

The ideal device, and they are already out there, will monitor temperature and humidity and in the same measurement loop it determines if dew is about to be formed. Somewhere in the loop there is a condition check that if the dew point is near, a gateway to the 12v/4A power should be opened up to the heating strap using PWM signal into a MOSFET that will be the gateway to the power delivered. Power will range from 0v before reaching trigger point all the way to 12v at the most serious condition. The transition from 0v and 12v should be formulated somehow in the loop, but it is not doo difficult and can be empirical.

The DHT22 along with a microcontroller will eliminate the need for a manual dimmer and will make the work more intelligent, saving power. The system does not have to have a display, but skies are the limit when it comes to that. The Sketch can be sending data via the WiFi or BT, can flash an LED when it has initiated the heater, can vary the flashing frequency depending on the volts it is allowing to pass through, etc.

So, we have the DHT22 send signals to an analog pin, and the microcontroller calculate dew point, and at a pre-designated spot, the loop can turn a digital pin high, signaling closing of the gate so power can pass through. There can be four pins to turn high sequentially as more voltage is needed; so if pin 1 is high, pass through 1 volt, pin 2 pass through 4 volts, pin 3 pass through 6 volts, and so on.

 

At least this is the idea.

Does this make any sense?

 

My first step is to have the DHT22 online and working, and the microcontroller monitoring and telling what it is reading and taking a simple action like blinking an LED or printing the value on an LCD. The rest would come together, and I am sure these codes are available here and there.

 

Thanks again.

 

Farzad

 

 

 

 

 

 

 

 


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 
Posted by: @farzad_k

@madmisha Thanks for the valuable information.

So, we have the DHT22 send signals to an analog pin, and the microcontroller calculate dew point, and at a pre-designated spot, the loop can turn a digital pin high, signaling closing of the gate so power can pass through. There can be four pins to turn high sequentially as more voltage is needed; so if pin 1 is high, pass through 1 volt, pin 2 pass through 4 volts, pin 3 pass through 6 volts, and so on.

With PWM to the MOSFET, you'll only need one output pin to the MOSFET's gate to control the heater all the way from 0-12V.


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

@will I am sure that you are right. But if the outputs are either high or low, how will you tell the MOSFET to allow more voltage to pass through? 


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 319
 

@farzad_k 

That makes sense and sounds easy enough.

I will make a suggestion that you should feel free to ignore if you wish. DHT sensors are not that reliable or accurate. I moved on to an SHT31 sensor. Far more accurate and reliable. They are not that expensive and they do have a heater that can toggle on that I believe is to evaporate any condensation that might form on the sensor(it is beyond what I need so I have mine disabled). That sounds like something you might want or need to be operating this outside.

 

I suggest calling the read temp and humidity as a function and storing a variable. With the DHT sensors, you should have something like this on the data returned(both temp and humidity):

 

if (! isnan(t)) {
    temps = (t);
}

 

This is not as much of an issue with the SHT(there are far less errors returned compared to the DHT) but it is still a good idea. Sometimes the sensors return an error and you might have problems when it returns a non number. This would also be in a while loop if you want to guarantee a reading on that pass.

 

Also, the ESP can work much faster than the polling rate of the sensor. SHT is faster than the DHT but the ESP32 is faster than them both. Add some delays or you might get errors. The above IF statement will also help with that.

 

That should at least get you started on the first step.

 

Edit: Mosfets are a switch. I am a little fuzzy on that part but Will knows more. You might need a different component there.


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@farzad_k 

Because the PWM is not sending a CONSTANT high or low, but a mix of high and low over it's period. If you Google "duty cycle" you'll find more and better definitions and diagrams that I can give you.

The MOSFET acts like a switch turning on or off depending on whether the gate is high or low. The PWM signal is a series of high and low PULSES one varying length (determined by the ratio of high and low values sent to the gate).

So, if the PWM signal always sends low pulses, then the MOSGET gate never opens and none of the 12V is delivered to the heater. If the PWM signal is on 10% of the time, then the MOSFET gate is open 10% of the time and the full 12 V is delivered 10% of the time. If the PWM is always sending high pulses, then the MOSFET delivers 12V the entire time, thereby sending 12V continuously for full power from the heater

The PWM signal controls the gate of the MOSFET which then turns on and off and delivers 12V to the heater in the same rate as the duty cycle. It's not totally continuous, but on the Arduino zero to full power is in 256 graduations, so you have the choice of sending from 0 to 100% at 256 different rates.


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

@madmisha Thanks a lot. I will certainly look into the SHT31. It looks like it has a couple of ports and that it might need a housing of its own.

Yes, we use our gear outdoors in the dark and cold. I know how dew works but don't know off the top of my head what is the trigger point for them. Everybody is using a MOSFET, but we either have something else that regulates the output to the MPSFET gate/switch or the power will be constant.


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

@will I see, and I think you had told me that before.

[1] Sensor sends pertinent data to the microcontroller.

[2] microcontroller decides what duty cycle PW to generate based on internal algorithm.

[3] the pin that MOSFET is connected to goes high and low based on the PWM determined by the microcontroller, opening and closing the gate repeatedly at the same PW as in [2] above, sending in full 12v but at the duty cycle established in [2].

Did I get it?


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@farzad_k 

Yep, you're closing in on it now 🙂 Power available in any of 256 increments from all the way off to all the way on coming from a PWM signal sent from one pin to the MOSFET's gate.


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

I know how dew works but don't know off the top of my head what is the trigger point for them.

Can you specify the formula for calculating the dew point temperature given the current ambient temp and humidity ?


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  
Posted by: @will

I know how dew works but don't know off the top of my head what is the trigger point for them.

Can you specify the formula for calculating the dew point temperature given the current ambient temp and humidity ?

At the moment I have limited success in programming a circuit to respond to temperature change using TinkerCad. Once I fully understand, and can make programmatic corrections to the boundaries of PWM, I will work on the formulation. I have actually seen the algorithm somewhere online.

Unfortunately TinkerCad doesn't have a DHT22 module so I am only working with a temperature control. The load gets brighter as I increase the heat in the temperature module.

I am following online sketch examples, and some things don't make sense to me, such as analog-writing to a digital pin.

 

 

Farzad

2021 09 14 14 10 50

 


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@farzad_k 

What's a CHT22 sensor ?

Since the only thing that you can change is the temperature (by turning on the heater), you'll need to decide when you need to start when to turn it on and how to decide if you need to ramp it up, keep it steady or let it slide.

If you can calculate the dew point temperature, then you can determine what action to take by calculating the dew point and comparing it to the current temperature.

Take a starting threshold of say 5 degrees difference and ramp that up to keep the current temp at least 3 degrees away from the dew point (which will also move as you adjust ambient temperature).

I think you'd find it easier to operate based on the "distance" to the dew point.


ReplyQuote
Farzad_k
(@farzad_k)
Eminent Member
Joined: 3 weeks ago
Posts: 44
Topic starter  

DHT22, sorry, the humidity and temperature sensor.

Eventually, rather than taking action on one element, action should be taken on the result of an equation with two variables T and H. I have seen dew point equation somewhere. The action doesn't need to be that precise. All that I want to happen is that the heater comes on when needed and not at the beginning of the session as I usually do, wasting some power. The next thing is to apply the voltage based on the dew point trend and its acceleration. Maybe go 3-volts at a time (256=12, then 64 = 3 volt, 128 = 6 volts, 192 = 9 volts).


ReplyQuote
Page 1 / 4