Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino DHT11 Project Help

jin2001

New Member
Hi, I am a student who is desperately trying to solve this issue that I am having with my board as this is my final year project and I will lose everything if I dont complete this.

The attached photo is my setup and this is the code:

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 4

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
Serial.println("DHTxx test!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// 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();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}



The serial monitor does not show anything, or it shows in garbled text when I believe that I have connected it properly.

I seek all all of your assistance, please and thank you.
 

Attachments

  • WhatsApp Image 2024-12-26 at 7.41.14 AM.jpeg
    WhatsApp Image 2024-12-26 at 7.41.14 AM.jpeg
    166.8 KB · Views: 29
Just a warning, for future micro work, when you execute a return from
loop() what will it do ? In case of Arduino its hard code to keep repeating
the loop(), but thats not true of all processors/IDEs.....

So your error return is OK in the case of Arduino, just a warning....:)

One other note, 115K serial one wants to have clean cable and signal
levels. I often use 9600 baud just in case my prototype mess wants to'
cause me grief at the first sign of garbled serial monitor display.

Regards, Dana.
 
Last edited:
Look in the Arduino project settings - different boards have different options, but there may be a selection for how the serial setup works; eg. either via USB or a GPIO pin.

If you do not get the "DHTxx test!" reliably, it's something to do with the serial config or connections, that needs fixing before the rest of the program can work.

You don't say what board or MCU you are using, so I can't say exactly how it will work. You could be trying to program a different MCU, without knowing the full setup :D
 

New Articles From Microcontroller Tips

Back
Top