ATMEga328P internal 8mhz plus DHT22 doesn't work fine

Hi, i have created a little temperature station with : ATMEGA328 P with internal 8MHZ that runs with 3,3 v supply, an OLED display and four DHT22. The problem is that the value detected by the sensors is not always correct. I mean sometimes (random) the value is NaN. I tried to change sensor, I tried with pullup resistor, I changed the sensor power supply (from 3.3v to 5v) while that of the Atmega remained 3,3V. ( I need to mantein 3,3 v for power saving). The same project works fine on Arduino UNO Board .
Suggestions or help

Hi, welcome to the forum.

Suppose you have long wires that collect noise, then a wrong value is no problem. Just ignore the wrong values.

Each DHT22 requires a pullup resistor.

They work better at 5V then at 3.3V, but sometimes they still work at 3.0V.

Can you tell which DHT library you use ? There might be better and simpler libraries. Some (old) versions caused a shortcut in the signal. That is extra bad if you don't have enough decoupling capacitors.

Can you show a photo of your project with the wires and the DHT sensors ?

Did you make your own board with a ATmega328P chip ? Then the first thing we will ask is where your decoupling capacitors are. You also need to connect all the (A)VCC and all the GND pins.

So where are your decoupling capacitors ?

It sounds like the board you are using is not an Arduino board but perhaps a custom board.

If so, has this board ever worked before?
Can you post a schematic of the board?

Hi Koepel,
below info you required :
1.DHT library download from GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
2. No decoupling capacitors. If i need them what is the right place?
3. Pull up resistors are in place ( n°2 sensor with 10K pullup resistor and n°2 sensor with 5K pullup Resistor. (because I have finished 10K resistors!))
4.Sensor Wire lenght about cm 70
5. Sensor works at 5V, atmega328 works at 3.3v ( I use an AMS 1117 converter )
Foto display random NaN value for sensor C, but the same with the others one ( not very frequently)

many thanks for help me

You need decoupling capacitors and also a few larger capacitors.
Is there a schematic that you used to wire the ATmega328P chip ? Or can you show the button side ?

A decoupling capacitor is often 100nF between VCC and GND.
The ATmega328P needs them, and the voltage regulator needs them.

Hi Koepel,
I posted a photo .Sorry i had to draw by myself. I hope it is understandable.
you can also see the DC/DC converter that I use.

A photo of a drawing is very good.

As I said before, you need to connect all the AVCC and VCC to 3.3V and you need to connect all the GND pins to GND.
You have to add 100nF decoupling capacitors at the ATmega. Add a larger capacitor as well, for example 100µF.
The voltage regulator module has already decoupling capacitors. They are the four light-brown components. I don't know if such small capacitors are according to the datasheet.
Some Arduino users add 100nF decoupling capacitors at the DHT sensors as well (to 3.3V and GND).
Power the DHT sensors with 3.3V or else there is a voltage mismatch between the signals of the DHT sensors and the Arduino.

Thanks for your fast reply.
Done: sensors power supplier -->3,3 v
I added the decoupling capacitor between VCC and GND ( pin 7 and 8 pin). The value is 47µF 25v, the only size i found.The capacitor voltage is important?.
It seems a little bit better...only few NaN. If I try with a 100µF capacitor can i resolve the issue definitively?

The high frequency spikes are the most important. Therefor 100nF decoupling capacitors are the most important.
A 47µF electrolyte capacitor has a high internal impedance for high frequencies.

Voltage does not matter. A 47µF 6V and a 47µF 400V are both 47µF.

ok i understood. Many thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.