problem with connecting thing speak

Hi friends i got a thing speak code from arduino forum and i created channel and try to upload with that code it is updating but its showing zero even if my sensor value changes

and the code is as follows

#include <SPI.h>
#include <Ethernet.h>

// Local Network Settings
byte mac = { 0x90, 0xA2, 0xDA, 0x0D, 0xAA, 0xE2 }; // Must be unique on local network
byte ip ={192,168, 12, 32};
// ThingSpeak Settings
byte server = { 184, 106, 153, 149 }; // IP Address for the ThingSpeak API
String writeAPIKey = “ST1P2E6BTKGI4KQN”; // Write API Key for a ThingSpeak Channel
const int updateInterval = 30000; // Time interval in milliseconds to update ThingSpeak
EthernetClient client;

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int resetCounter = 0;

// All the weather variables from weather station to send to ThingSpeak

float hum = 0; // " " #1
float tempF = 0; // " " #2

char humidity;
char temperature;

void setup()
// Serial1.begin(9600);
// delay(1000);

void loop()
String analogPin0 = String(analogRead(A0), DEC);
// String analogPin1 = String(analogRead(A1), DEC);
while(Serial.available() > 0){
int inByte =;

if (Serial.find("*")){
hum = Serial.parseFloat();
//tempF = Serial.parseFloat();

char hum_buffer[7];
String humidity=dtostrf(hum,0,2,hum_buffer);
//String humidity = “1”;

// char tempF_buffer[7];
// String temperature=dtostrf(tempF,0,2,tempF_buffer);
//String temperature = “2”;
// Print Update Response to Serial Monitor
if (client.available())
char c =;

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)


// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateInterval))
//updateThingSpeak(“field1=” + String(humidity) + “&field2=” + String(temperature));
updateThingSpeak(“field1=” + String(humidity));

lastConnected = client.connected();

void updateThingSpeak(String tsData)
Serial.println(“Connected to ThingSpeak…”);

client.print(“POST /update HTTP/1.1\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: “+writeAPIKey+”\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);


lastConnectionTime = millis();

resetCounter = 0;


You have two different variables named humidity

char humidity;

declared at global level, and

 String humidity=dtostrf(hum,0,2,hum_buffer);

declared in the loop() function.

Later on in loop() you have

updateThingSpeak("field1=" + String(humidity));

Which of the two variables it uses I don't know but from the symptoms that you describe I would guess that it uses the global one which is never updated from its original value of zero. Delete the global one and see what happens.

You might also look at the examples associated with the ThingSpeak Communication Library:

chaitraacharya376: byte server[] = { 184, 106, 153, 149 }; // IP Address for the ThingSpeak API

That is NOT the server.

Please be aware: IP addresses on the Internet may change quickly. So íf you want to connect to a server that is present on the internet, connect to the NAME OF THE SERVER and NOT THE IP ADDRESS OF THE SERVER.

Perhaps use:

char server[]  = "";

Generally, I agree with jurs -- you shouldn't hardcode IP addresses. In this case, however, it's correct. That is the published, fixed IP address of the ThingSpeak server (load balancer). Ideally, is a better choice.


Thingspeak is connected only if i use byte server[] = { 184, 106, 153, 149 }; // IP Address for the ThingSpeak API If i use: char server[] = ""; the com port shows only values like 288 282 215 and so on but no updation in thingspeak. Even now I get a flat red line at 0 with red dots denoting the updation.

chaitraacharya376: Even now I get a flat red line at 0 with red dots denoting the updation.

If you send the data to "" instead of "", it is perfectly normal, that there are no data available at "", other than a zero-line.

You don't do the slightest HTTP error handling, so you never will know, if the (wrong) server respnds to the request with something like perhaps: Error 500 (Internal Server Error when sending your data to the wrong server.

No error handling ==> no error message ==> you never will know whats going wrong

Which is the original sketch you tried to adapt? Is it possibly: Or what?

And which changes do you want to make to the working example sketch? Your code looks like you want to send fields like "humidity" and "temperature". Where do they come from? analogRead? Reading sensors and doing calculations? Float or int?

If you're getting zeros on the chart at ThingSpeak, then you're sending data -- but it's all zeros. Check your sketch to see if the string your passing to updateThingSpeak -- try sending the string to the serial port to see what's in it.