Hello Everyone ! I started my project with Arduino and Temperature/Humidity sensor DHT11. I want values from sens to display on ThingSpeak Charts.
Project Components:
Arduino Uno Rev3
Ethernet Shield
DHT 11
There is my code:
#include "ThingSpeak.h"
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xFJ, 0x3C, 0xDA, 0xB7, 0xC1, 0x05}; //not importatnt for you
EthernetClient client;
#include <DHT.h>
#include "DHT.h"
#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
unsigned long myChannelNumber = MyChanellNumber; //not importatnt for you
const char * myWriteAPIKey = "MyApiKey"; //not importatnt for you
void setup() {
Serial.begin(9600);
dht.begin();
Ethernet.begin(mac);
ThingSpeak.begin(client);
}
void loop() {
float t = dht.readTemperature();
float h = dht.readHumidity();
Serial.println("======================================");
Serial.println("Weather condictions");
Serial.print("Temperature= ");
Serial.print(t);
Serial.println(" C");
Serial.print("Humidity= ");
Serial.print(h);
Serial.println(" %");
Serial.println();
ThingSpeak.writeField(myChannelNumber, 1, t, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2, h, myWriteAPIKey);
delay(20000);
}
Problem is with values. Serial Monitor and ThingSpeaks Field 1 Chart show me NaN (Not a Number) value. Ethernet connection was good and ThingSpeak will show any other value but not humidity and Temperature.
I tried everything:
-
I checked out my connection. Countless times ! No problem.
-
Try this code without Ethernet & ThingSpeak functions, only with DHT11 and Serial Monitor ,it worked without problem (showing values)!
-
I tried ->float t = dht.readTemperature();
String temp = String(t);
ThingSpeak.writeField(myChannelNumber, 1, temp, myWriteAPIKey);
String doesn´t worked ! -
I was reading forums with similar issues. And nothing for me.
I will be grateful for any answer. Thanks.