DHT11 not working on Standalone-ATMega

Hello everyone,

i tried to build a standalone room-thermometer/hydrometer with an LCD-Display and the DHT11-Sensor. So far everything is working but only when i connect it to my Arduino-Board.
I've tried to set it up with a standalone ATMega328 on a Breadboard and all i get is "Hum.: 0.00/ Temp.:0.00".
On the arduino it works just fine. Even if i just plug the Sensor-Cable from the ATMega into my Arduino the Serial-Monitor shows the correct temperature and humidity (or at least it shows some numbers). But neither the LCD nor the Serial-Monitor shows anything but 0.00 on the ATMega.

More Info:

  • The ATMega328 has the Arduino-Bootloader installed, the Board-Setup is "ATMega328 on breadboard (8MHz internal clock).
  • Powercomes from an external Wall-Plug with 5V/1A
  • If i disconnect the Sensor from the ATMega the LCD reads "Failed to read from DHT", which is correct

This is the Code i use. Most of it comes directly from the DHT11-example:

#include "DHT.h"
#include <LiquidCrystal.h>

#define DHTPIN 8     // what pin we're connected to

#define DHTTYPE DHT11   // DHT 11 

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

//LCD Pin1 -> GND
//LCD Pin2 -> 5V
//LCD Pin3 -> GND/Poti
//LCD Pin4 -> 12 (RS)
//LCD Pin5 -> GND (R/W)
//LCD Pin6 -> 11 (E)
//LCD Pins 7-10 -> NC (DB0-DB3)
//LCD Pins 11-14 -> 5-2 (DB4-DB7)
//LCD Pins15/16 (Backlight) -> 5V/GND+Resistor

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
//  Serial.begin(9600); 
//  Serial.println("DHTxx test!");
  lcd.begin(16, 2);
  lcd.print("DHTxx test!");
  dht.begin();
}

void loop() {
  lcd.setCursor(0,0);
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    lcd.print("Failed to read from DHT");
  } else {
    lcd.print("Humidity: "); 
    lcd.print(h);
//    Serial.println(h);
    lcd.setCursor(0,1);
    lcd.print("Temp.: "); 
    lcd.print(t);
//    Serial.println(t);
    lcd.print(" ");
    lcd.print((char)223);
    lcd.print("C");
  }
}

My question: What is wrong?

Where are your decoupling capacitors?

What capacitors? Where should they be?

For the ATMega i used this Layout: http://arduino.cc/en/Tutorial/ArduinoToBreadboard (Minimal Circuit). I didn't see any caps, so i didn't put any on it.
For the DHT i looked here: Overview | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System

On the power supply to the chip, as close to the chip as possible.

You have configured the '328 to use the internal clock haven't you?

The power-supply has has special pins to connect to breadboard-projects(stabilized output and all). I assume that it has decoupling caps built-in. Sort of like the breadboard-power-supply from ladyada, but not clip-on.
The chip is configured, bootloaded and programmed for standalone use.
Both worked in every other circuit so far, even together. The chip still works after being hooked up to this project, so it wasn't damaged by the power-supply.
I even tried switching power from the external supply to the 5V/GND-Pins on my arduino. No luck.

Just a guess - in that case what I would try is a regular, externally clocked '328 with crystal and caps. This would demonstrate if there was a problem with talking to sensor using the internal clock speeds.

Hi,

i have identical problem like @Pteppic1 ,

but, adding external clock does not solve my problem.

That diagram is for uploading the bootloader. What are you actually trying to do?

I wanted to show how connected the clock, this picture illustrates it.

What are you actually trying to do?

"DHT11 not working on Standalone-ATMega" - support(use) DHT11 by ATMEGA328P

Ok, what code are you using?

DTH.h library only works with arduino bootloader.
So u need to upload arduino uno bootloader to atmega328p chip and then try to upload the code using serial programmer like ftdi or pl2303. If u still having trouble then feel free to reply. :slight_smile: