i am doing an greenhouse project with esp8266 and i compiled the code but only the soil moisture was working and the temp and humidity was staying the same.what might be the problem
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
// Replace with your network credentials
const char* ssid = "Vaibhav";
const char* password = "11111111";
// Initialize components
DHT dht(13, DHT11);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 cols, 2 rows
const int soilMoisturePin = A0;
// Create an instance of the
ESP8266WebServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
lcd.init();
lcd.backlight();
// Connect to Wi-Fi
Serial.println();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Routes for the server
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
void handleRoot() {
int h = dht.readHumidity();
int t = dht.readTemperature();
int soilMoisture = analogRead(soilMoisturePin);
// Display data on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(h);
lcd.print("%");
// Create HTML response
String html = "<html><body>";
html += "<h1>Greenhouse Control System</h1>";
html += "<p>Temperature: " + String(t) + " °C</p>";
html += "<p>Humidity: " + String(h) + " %</p>";
html += "<p>Soil Moisture: " + String(soilMoisture) + "</p>";
html += "</body></html>";
server.send(200, "text/html", html);
}
in the web page it says
Greenhouse Control System
Temperature: 2147483647 °C
Humidity: 2147483647 %
Soil Moisture: 990
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
asking for maximum help by demanding "fix my code" in combination with almost zero own effort
(at least not witnessing your own effort)
My suggestion is:
add a sentence that tells all users in the first posting to scroll down to post number XY where you did a new start
then
to reduce your code to something much simpler and to test this simpler code if it is working.
Just the DHT-sensor printing to the serial monitor
if this works
adding the LCD and printing DHT-values to the LCD
very important: witnessing your own effort by posting the demo-codes as a code-sections
using a demo-code for Ubidot testing if the Ubidot-connection itself is working.
Do you understand a demo-code that is well known for working.
adding the DHT-LCD-Code to the Ubidot-Demo-code testing if this works
If this is too much work for you: go buying a ready to use product off the shelf.
Hello guys i am new to arduino and i was testing me DHT11 sensor with esp8266 but it is giving me "failed to read from dht sensor" .when i change the code it gives me other errors like nan or it gives me some random value which doesnt change
From a comment on the linked page (maybe the drawing has changed):
"This circuit schematics still has a mistake. 4.7 K should be a pull up resistor, whereas your sketch shows it as a pull down to GND. It does not work like this, I tried it."
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
If you have a DHT11 you want to uncomment the DHT11. Most DHT11 and DHT22 modules as you posted an image of also have a pullup resistor on the board. Anyway try changing your code for a DHT11 verse the DHT22 you have uncommented in your code. Make it look like this.
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
i am trying a lot of different arduino codes but my sensor gives differnet errors like
"nan" or "failed to read from dht sensor" or "0 humidity and 0 temp".i am using arduino uno board
this is my sensor and i think its working bc the red light is on