Greetings, I hope someone can help me with this. Let me explain the problem from the start. I uploaded this code on my arduino Uno board:
#include <SimpleDHT.h>
#define DHT11_PIN 2 // DHT11 sensor pin
#define PUMP_PIN 3 // Relay module pin
#define SOIL_SENSOR_PIN A0 // Soil moisture sensor pin
#define LDR_PIN A5 // LDR sensor pin
SimpleDHT11 dht11;
void setup() {
Serial.begin(9600);
pinMode(PUMP_PIN, OUTPUT); // Set the relay pin as output
digitalWrite(PUMP_PIN, LOW); // Ensure the relay is off at startup
}
void loop() {
byte temperature = 0;
byte humidity = 0;
// Read data from DHT11 sensor
if (dht11.read(DHT11_PIN, &temperature, &humidity, NULL)) {
Serial.println("Error reading DHT11");
delay(2000); // Wait before retrying
return;
}
// Read soil moisture and light levels
int soilMoisture = map(analogRead(SOIL_SENSOR_PIN), 0, 1023, 100, 0);
int lightLevel = map(analogRead(LDR_PIN), 1023, 0, 100, 0);
// Display the values on the Serial Monitor
Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C");
Serial.print("Soil moisture: "); Serial.print(soilMoisture); Serial.println(" %");
Serial.print("Light level: "); Serial.print(lightLevel); Serial.println(" %");
// Logic to activate the pump
if (soilMoisture <= 50 && lightLevel < 30 && temperature < 30) {
digitalWrite(PUMP_PIN, HIGH); // Turn on the relay (pump on)
Serial.println("Watering...");
} else {
digitalWrite(PUMP_PIN, LOW); // Turn off the relay (pump off)
Serial.println("No watering needed.");
}
Serial.println("-------------------------");
delay(2000); // Wait 2 seconds before the next reading
}
And it works, but then when I wanted to upload a change of this code on the light level map, I couldn't do it because I got these error lines:
I tried again and again and the same issue happens, then i change the code for other one different and tried to uploaded but the same problem. I check the ports in the device manager and of course in the Arduino IDE, change the computer, even the IDE version but nothing changes.
The message "Error reading DHT11" is always displayed on the serial monitor but I don't understand how it is possible that the arduino always waits for the sensor.
I will be very grateful for your help.
To solve the upload problem, start by disconnecting everything (except the PC) from the Uno and try again to upload the blink example.
Did you select the correct port? Does the port disappear from the IDE if you disconnect the board?
Which operating system are you using? Which version of the IDE?
How are you powering the pump? Please provide a schematic / wiring diagram so we can see how everything is connected.
If your Uno does not use the CH340 serial-to-usb converter (chip closest to the USB connector), you can run the loop back test. This test will not work / be non-conclusive if your board uses the CH340 (common on clones).
Please do not post images of errors; copy from the output window (or use the convenient button) and paste in a post using code tags.
Hi thanks for the advices and comments, I tried before disconnecting everything and have only Arduino on my pc and as I said I tried with the blink program. About the pump, powerade by a battery of 9v volts at this moment I dont have the schematic of the circuit. But about the problem, My arduino board is original and I tried to burn the bootloader but the problem persist. And the error that show me is this
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x66
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x86
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xf8
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x86
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xf8
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe6
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x9e
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x18
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x06
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x98
Borrado del chip fallida: uploading error: exit status 1
With an original Arduino Uno, what is the result of the loop-back test? If the loop-back test failed, the 16U2 on your board is faulty and trying to burn the boot loader is a futile exercise. You can try to burn the firmware on the 16U2 using Atmel Flip; the following two articles can help with that:
- https://support.arduino.cc/hc/en-us/articles/4408887452434-Flash-the-USB-to-serial-firmware-for-UNO-Rev3-and-earlier-and-Mega-boards
- https://support.arduino.cc/hc/en-us/articles/4410804625682-Set-the-Atmega16U2-8U2-chip-on-UNO-Rev3-or-earlier-and-Mega-boards-to-DFU-mode
If the loop-back test passes and burning the boot loader is successful but does not solve the problem, I'm not sure what is wrong.