Hello everyone!
I am working on an Arduino project that integrates with ThingSpeak to read sensor data (temperature and humidity) and control an LED. However, when trying to read data from ThingSpeak, my Arduino always returns 0
, even though the data is updated on ThingSpeak.
Code Snippet
void readLED() {
int ledStatus = ThingSpeak.readIntField(myChannelNumber,3,myReadAPIKey); // Read field 3 value
Serial.println(ledStatus);
// Update LED state based on the read value
if (ledStatus == 1) {
digitalWrite(LED_PIN, HIGH); // Turn LED on
Serial.println("LED turned ON");
} else {
digitalWrite(LED_PIN, LOW); // Turn LED off
Serial.println("LED turned OFF");
}
}
What I've Tried:
- Verified the API key and channel ID.
- Confirmed that the data is updating correctly on ThingSpeak.
- Ensured my Arduino Uno R4 WiFi is connected to the internet.
- Added delays between requests to avoid rate-limiting.
Problem :
When I am printing the LED Status on the serial monitor it always prints 0 regardless of the state of the ThingSpeak field values.
Repository Link:
You can view the code and project setup here: GitHub Repository Link