#include "Arduino.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
DHT dht(2, 11);
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
unsigned long previousMillis = 0;
const long reportInterval = 1000;
void setup()
{
lcd.init();
Serial.begin(9600);
dht.begin();
lcd.backlight();
delay(2000);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= reportInterval) {
previousMillis = currentMillis;
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(dht.readTemperature());
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(dht.readHumidity());
}
if (Serial.available() > 0) {
// read the incoming byte:
int incomingByte = Serial.read();
// c = 99
if (incomingByte == 99){
Serial.print("{\"temperature\": ");
Serial.print(dht.readTemperature());
Serial.print(",\"humidity\": ");
Serial.print(dht.readHumidity());
Serial.print(",\"light\": ");
Serial.print(+analogRead(0));
Serial.println("}");
}
}
}
The DHT lib is from adafruit.
I have tried changing the wires and the pins, testing the resistors in the PCB (All seems to be good...?) tested the resistance of the actual "sensor" (It went up and down when I breathed into it). Is this another dead component?
Please check all the points here: [SOLVED] DHT11/DHT22 - Failed to read from DHT sensor | Random Nerd Tutorials
Also please check the continuities of your jumper wires with a multimeter if possible.
Yup, I know the USB can handle this much load because it was working before, and I have tested the wires for continuity.
Oh I see. Have you tried any simple code? like only reading the temperature and humidity and showing the value on the serial monitor? Have you tried the DHTtester example of the adafruit library? Currently I am working with DHT11 and this library worked. I recommend you to try DHTtester example. From your picture it seems like you're using a shield. Omit the shield and connect the sensor directly to the Arduino Uno. Still, if it does not work, probably you got a faulty product.
Hi!
If you still have the problem, take a look at this line:
anon45998427:
DHT dht(2, 11);
According to the library documentation, the correct syntax for this statement would be:
DHT dht(2, DHT11);
Why are you using wire.h here?
Also, see if this works and let me know
#include "DHT.h"
#include "Arduino.h"
#include <LiquidCrystal_I2C.h>
#define dht_dpin D4
DHT dht(dht_dpin, DHT11);
LiquidCrystal_I2C lcd(0x27,16,2);
unsigned long previousMillis = 0;
const long reportInterval = 1000;
float temp, hum;
void setup()
{
dht.begin();
Serial.begin(9600);
lcd.init();
lcd.backlight();
delay(700);
}
void loop() {
hum = dht.readHumidity();
temp = dht.readTemperature();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= reportInterval) {
previousMillis = currentMillis;
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(hum);
}
Serial.print("Humidity = ");
Serial.print(hum);
Serial.print("% ");
Serial.print("Hemperature = ");
Serial.print(temp);
Serial.println("C ");
delay(2000);
}
First check if you're getting data on COM
Ok. Keep DHT11 (because that´s what the library says) and try raising up your "reportInterval" to 5000. DHT11 is a slow responsive sensor. Some places recommend at least 2s between measures.
anon45998427:
Still spat a nan at me.
I´m sorry to hear that. I run out of tips, since your wiring and your code look ok for me. Let´s see if someone more experienced can bring a light to the situation before condemning your sensor.
dlloyd
March 12, 2022, 4:37am
13
You probably need to install the Adafruit Unified Sensor Library, then you could test using this example .
Unfortunately all of the interfacing between the DHT11 and code is hidden in the DHT library so its hard o see what is going wrong.
You could try this approach which avoids using the DHT library
at the very least you would learn more about how it works!
1 Like
23:08:42.756 -> DHTxx Unified Sensor Example
23:08:42.756 -> ------------------------------------
23:08:42.756 -> Temperature Sensor
23:08:42.756 -> Sensor Type: DHT11
23:08:42.756 -> Driver Ver: 1
23:08:42.756 -> U⸮DHTxx Unified Sensor Example
23:08:44.234 -> ------------------------------------
23:08:44.267 -> Temperature Sensor
23:08:44.300 -> Sensor Type: DHT11
23:08:44.333 -> Driver Ver: 1
23:08:44.333 -> Unique ID: -1
23:08:44.366 -> Max Value: 50.00°C
23:08:44.366 -> Min Value: 0.00°C
23:08:44.400 -> Resolution: 2.00°C
23:08:44.433 -> ------------------------------------
23:08:44.466 -> Humidity Sensor
23:08:44.466 -> Sensor Type: DHT11
23:08:44.499 -> Driver Ver: 1
23:08:44.499 -> Unique ID: -1
23:08:44.532 -> Max Value: 80.00%
23:08:44.565 -> Min Value: 20.00%
23:08:44.565 -> Resolution: 5.00%
23:08:44.599 -> ------------------------------------
23:08:45.626 -> Error reading temperature!
23:08:45.660 -> Error reading humidity!
Nope. Still nothing.
@jhonerrington
Now that's interesting, I got a Timeout error.
dlloyd
March 12, 2022, 5:12pm
17
I would definitely add a 10K pullup resistor (seems to be missing on PCB) ...
system
Closed
September 8, 2022, 5:44pm
19
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.