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?