I've tried multiple iterations of code, changed different signal pins, attempted to use example sketches for testing purposes and even went out and bought a second DHT11 sensor to try and get this thing to work but cannot, for the life of me, figure out why I'm not getting any readings.
I'm using an Arduino Nano 33 IoT with either DHT11 sensors and everytime there is a failed reading.
Here's the code that I am attempting to get running, note that the 'example' sections are filled out with relative information on my behalf (blocked for obvious reasons in this example)
#include <SPI.h>
#include <WiFiNINA.h>
#include <DHT.h>
#include <ThingSpeak.h>
// WiFi credentials
char ssid[] = "Example";
char password[] = "Example";
// ThingSpeak credentials
unsigned long myChannelNumber = Example; // Replace with your ThingSpeak channel number
const char* myWriteAPIKey = "Example"; // Replace with your ThingSpeak API Key
WiFiClient client;
#define DHTPIN 2 // Pin connected to DHT11 data pin
#define DHTTYPE DHT11 // Sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
while (!Serial);
// Initialize DHT sensor
dht.begin();
// Connect to WiFi
Serial.print("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println("\nConnected to WiFi!");
// Initialize ThingSpeak
ThingSpeak.begin(client);
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(); // Celsius
// Check if reading is valid
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
delay(5000);
return;
}
// Print data
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("°C Humidity: ");
Serial.print(humidity);
Serial.println("%");
// Upload data to ThingSpeak
ThingSpeak.setField(1, temperature);
ThingSpeak.setField(2, humidity);
int response = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (response == 200) {
Serial.println("Data sent to ThingSpeak successfully.");
} else {
Serial.print("Failed to send data. Error code: ");
Serial.println(response);
}
// Wait 15 seconds before next update (ThingSpeak limit)
delay(15000);
}

