Hello, I am working with an ESP32 and I need it to be able to receive information from a DHT11 sensor and send it to the Arduino Cloud. However, I have been having issues connecting it to the cloud. I have already tested it in the Arduino IDE to connect to Wi-Fi and the DHT11, and it worked without any problems. I made sure that the network information and device ID were correct. This is the code I am using:
/*
Sketch modificado para leer temperatura y humedad del DHT11 y enviarlas a la nube de Arduino IoT
*/
#include "thingProperties.h"
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
delay(1500);
// Inicializar sensor DHT
dht.begin();
// Inicializar variables de Arduino IoT Cloud
initProperties();
// Conectar a Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Leer valores del sensor
float temp = dht.readTemperature(); // En grados Celsius
float hum = dht.readHumidity();
// Verificar si la lectura es válida
if (!isnan(temp) && !isnan(hum)) {
temperatura = temp;
humedad = hum;
Serial.print("Temperatura: "); Serial.print(temperatura);
Serial.print(" °C - Humedad: "); Serial.print(humedad);
Serial.println(" %");
} else {
Serial.println("Error al leer el sensor DHT11");
}
delay(2000); // Esperar 2 segundos entre lecturas
}
I have also noticed that the Arduino Cloud IDE does not tell me if the ESP32 is correctly connected via USB. I suspect it is not even able to upload because even though I tried uploading a couple of programs and Arduino Cloud said they were uploaded successfully, when using the Arduino IDE, I could see that it was still running the previous program. If anyone has any suggestions, I would appreciate it.