Go Down

Topic: 2 LM35´s with a ethernet shield posting to pachube (Read 3798 times) previous topic - next topic


Apr 21, 2009, 08:59 pm Last Edit: Apr 21, 2009, 09:36 pm by designer2k2 Reason: 1

the Temperature in my "Workroom": (its in °C, over the last 24h)

or combined: http://www.designer2k2.at/pachube.php

the Hardware:

its a Arduino Duemilanove + a Ethernet shield + small Breadboard + 80mm PC Fan (running at only 5V) + Lego

the Fan is running at 5V, so very slow, but enough to get the LM35´s very precise  :)

i calibratet the LM35´s with a thermocouple (about 1,4°C error on both)

here both sensors can be seen idividual: http://www.pachube.com/feeds/1761/

on the Arduino im running the "Pachube code" nothing special there...

the Charts are drawn with the Google Chart Api, nice stuff  ;)

im Powering this thing with a USB MP3 Charger, couldnt finde a cheaper and easier powersource  ::)

maybe later i will replace the breadboard with a small print, but thats so much work, compared to the breadboard  :P



Apr 23, 2009, 10:26 pm Last Edit: Apr 24, 2009, 10:09 am by designer2k2 Reason: 1


(Thats the current Temperature in Innsbruck/Austria  :D)

About the code on the Arduino:

im running this code on the Arduino: http://community.pachube.com/node/112

only modification is here:

in the void setup():

Code: [Select]
 analogReference(INTERNAL);                      //gets nicer precision for the the LM35´s

and the "pachube_update"

Code: [Select]
char data[128];
boolean found_status_200 = false;
boolean found_content_length = false;
boolean found_CSV = false;
char *found;
unsigned int successes = 0;
unsigned int failures = 0;
boolean ready_to_update = true;
boolean reading_pachube = false;

boolean request_pause = false;
boolean found_content = false;

int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;

unsigned long last_connect;

void pachube_in_out(){
 if (request_pause){
   if ((millis() - last_connect) > interval){
     ready_to_update = true;
     reading_pachube = false;
     request_pause = false;
     found_status_200 = false;
     found_content_length = false;
     found_CSV = false;

     Serial.print("Ready to connect: ");
     Serial.print(" - ");
     Serial.print(" - ");

 if (ready_to_update){
   if (localClient.connect()) {
     // here we assign comma-separated values to 'data', which will update Pachube datastreams
     // we use all the analog-in values, but could of course use anything else (millis(), digital
     // inputs, etc. . i also like to keep track of successful and failed connection
     // attempts, sometimes useful for determining whether there are major problems.
     //sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",analogRead(0),analogRead(1),analogRead(2),analogRead(3),analogRead(4),analogRead(5), successes + 1, failures);
           val1 = 0;
           val2 = 0;
           val4 = 0;
           for (int i2 = 0; i2 < 10; i2++) {
             val1 = val1 + analogRead(0);
             val2 = val2 + analogRead(1);
             val4 = val4 + analogRead(2);
           val1 = val1 / 10.0;
           val2 = val2 / 10.0;
           val4 = val4 / 10.0;
     val1 = ((val1*110.0/1023.0)-1.55)*1000.0;
     val2 = ((val2*110.0/1023.0)-1.45)*1000.0;
     val4 = ((val4*110.0/1023.0)-4.60)*1000.0;
     val3 = val1/2+val2/2;
     Serial.print("Temp0: ");
     Serial.print(" C Temp1: ");
     Serial.print(" C Temp2: ");
     Serial.println(" C");
     sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",val1,val2,val4,val2/1000,val3,val3/1000, successes + 1, failures);

     Serial.println("GET request to retrieve");

     localClient.print("GET /api/");
     localClient.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");

     Serial.println("finished GET now PUT, to update");

     localClient.print("PUT /api/");
     localClient.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
     localClient.print("\nContent-Type: text/csv\nContent-Length: ");
     localClient.print("\nConnection: close\n\n");

     ready_to_update = false;
     reading_pachube = true;
     request_pause = false;
     interval = UPDATE_INTERVAL;

     Serial.print("finished PUT: ");

   else {
     Serial.print("connection failed! ");
     found_status_200 = false;
     found_content_length = false;
     found_CSV = false;
     ready_to_update = false;
     reading_pachube = false;
     request_pause = true;
     last_connect = millis();
     interval = RESET_INTERVAL;

 while (reading_pachube){
   while (localClient.available()) {

   if (!localClient.connected()) {

void disconnect_pachube(){
 ready_to_update = false;
 reading_pachube = false;
 request_pause = true;
 last_connect = millis();
 found_content = false;

void checkForResponse(){  
 char c = localClient.read();
 buff[pointer] = c;
 if (pointer < 64) pointer++;
 if (c == '\n') {
   found = strstr(buff, "200 OK");
   if (found != 0){
     found_status_200 = true;
     Serial.println("Status 200");
   found_content = true;

 if ((found_content_length) && (!found_CSV)){
   found = strstr(buff, "HTTP/1.1");
   if (found != 0){
     char csvLine[strlen(buff)-9];
     strncpy (csvLine,buff,strlen(buff)-9);

     //Serial.println("This is the retrieved CSV:");    
     //Serial.println("\n--- updated: ");
     //Serial.println("\n--- retrieved: ");
     char delims[] = ",";
     char *result = NULL;
     char * ptr;
     result = strtok_r( buff, delims, &ptr );
     int counter = 0;
     while( result != NULL ) {
       remoteSensor[counter++] = atof(result);
       result = strtok_r( NULL, delims, &ptr );
     for (int i = 0; i < REMOTE_FEED_DATASTREAMS; i++){
       Serial.print( (int)remoteSensor[i]); // because we can't print floats

     found_CSV = true;

     Serial.println(" ");
     Serial.print("successful updates=");


 if (found_status_200){
   found = strstr(buff, "Content-Length: ");
   if (found != 0){
     found_content_length = true;

this outputs the analog0,1 and 2 to Pachube, and makes a mean of 10 measurements before sending...



Hi designer2k2, your project is very nice! I'm trying to use pachube too, but have some troubles understanding the code of the example you used. Where did you read in the Arduino code your sensors...?
Should be around here:

Code: [Select]
void loop()
 // call 'pachube_in_out' at the beginning of the loop, handles timing, requesting
 // and reading. use serial monitor to view debug messages
 // then put your code here, you can access remote sensor values
 // by using the remoteSensor float array, e.g.:
 analogWrite(3, (int)remoteSensor[3] * 10); // remoteSensor is a float
 analogWrite(5, (int)remoteSensor[1]);

 // you can have code that is time sensitive (e.g. using 'delay'), but
 // be aware that it will be affected by a short pause during connecting
 // to and reading from ethernet (approx. 0.5 to 1 sec).
 // e.g. this code should carry on flashing regularly, with brief pauses
 // every few seconds during Pachube update.
 digitalWrite(6, HIGH);
 digitalWrite(6, LOW);

And what's the "remote sensor", I actually don't need to read other's pachube sensors feed.
Hope you have clearer ideas than mine...  :-/




you should go with the new lib from pachube: http://community.pachube.com/arduino/ethernet

my code is based on the old one and works not so stable...


Great job ! I'm trying to do the same thing but I don't understand how to upload floating data . In your code you upload decimal data
Code: [Select]
sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",val1,val2,val4,val2/1000,val3,val3/1000, successes + 1, failures);

but on the pachube I see you have floating numbers . HOW can I do the same ???


1.22C indoors and 17.79 outdoors? I'd open a door, I think.


Here is my data .


please see my feed: http://www.pachube.com/feeds/1761/

the inputs have changed, so my old first post is wrong  ;)

but the output sensor ist not right, currently we have around -5°C at night but the sensor never goes below 3°C as the LM35 in basic circuit cannot show negative numbers...




Use LM34's
They have better resolution and can go negative °C
You need to convert from °F to °C within your code

Nice job


Dec 07, 2009, 10:26 am Last Edit: Dec 07, 2009, 11:04 am by Yan78 Reason: 1
I still have some questions !

I don't understand how to upload floating data . In my arduino temp is 26.52 C . But i have to uplod 26 C because of the sprintf .

One way is to upload 26.52 * 100 = 2652 and in pachube to divide the value by 100 . Is it possible ?


finally ! I did it ! Now I do  upload data with floating point .

see it here !



Ran Talbott

I'd open a door, I think.

Or call the SETI hotline,  and ask if there's a reward for directing them to a visitor from a really cold planet...

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131