A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Basic Environment Monitoring using Arduino and Pachube

When looking at a number of temperature sensors to monitor the conditions inside and outside of my home office I was looking for a simple method of producing trend graphs. I was originally thinking RRD and PHP scrips on my own webhost but the PHP didn’t have the right libraries included. I then came across which looked it could be useful. Pachube provides an API in a number of formats so that a feed can be created and its data streams updated automatically. The APIs provided allow for simple CSV data or more complex XML data to be submitted. This in turn is shown in a 24 hour trend graph for each data stream.

I have now built a simple ethernet connected Arduino that collects temperature inside and out, inside relative humidity, dew point and light level indication. The five data streams are sent to pachube .com and displayed on the feed

Parts used

Main features

  • Post regular updates to, currently very 30 seconds
  • Post updates to your account on
  • Act as a simple web server so local clients can query the sensor values
  • Standalone operation, does not require a computer to be powered on, although it is currently being powered by USB from a Linux server!

Sensor connections

  • SHT11 – Data – Digital pin 5, Clock – Digital pin 6. Ground and power to same on proto shield
  • DS18B20 – Data – Digital pin 3. Power and ground to same on sockets on top of ethershield.
  • Solar Cell – Data – Analogue pin 0 and ground. Use a multimeter to determine which is + and which is ground.

Software Details

The biggest piece of software is the ethernet tcp/ip stack. This is a modified version of my previous updated library. The difference here is that I have added a parameter to the EtherShield::ES_client_http_post function in order to pass in the method to use in the request to The default POST causes invalid method errors to be returned. I therefore use PUT to send the updates to The configuraton to allow optional tweeting is enabled by conditional compilation. See sketch for details.

The software is divided into 4 files to make re-use in other projects simpler.

  • etherShield_pachubeclient.pde – main application
  • lightSensor.pde – handles reading of light sensor solar cell
  • oneWire.pde – handles reading of the temperature form the DS18B20, taken from nuelectronics sample.
  • sht11.pde – handles reading of temperature and humidity from SHT11, also calculate dew point, taken from nuelectronics sample.

The temperature and humidity functions return integer values multiplied by 100 that I then divide and modulus to get the whole and decimal values. This was just done for a quick hack to get this working and needs a better way to do this. One issue is that I don’t believe it would show negative values and that the atoi function may not correctly handle conversion of values with a leading zero. Again, needs updating.

The light sensor is pretty basic, just measure the voltage from the solar cell then map the range to 0-100 to give an approximate percentage of light level indication. I don’t think the max value is quite correct as I occasionally see values greater than 100%. It may also be non-linear. But as an indication that its day or night it can show if the temperatures are for the day or night.

The software as it is just fits into available flash space. If I wanted to add more sensors then the one thing that can be dropped or reduced is the web page that provides local output. This could simply be just the CSV data that was last sent to The code has this in at present, but commented out.

Hardware Setup

The proto shield sits on top of the Arduino with the SHT11 mounted out to the side keeping it away from any local sources of heat. The etherShield then sits on top with the remote DS18B20 and solar cell plugged into the top by means of header pins.


Some photographs of the solar cell, its modification and the final setup.

Top of the cheap garden solar powered lamp Casing removed, solar cell wires cut. Protecting the underside – epoxy glue to protect solar cell tails All wired up to Arduino and temperature sensors


Please note the code has been written and tested on the Arduino Diecimila with ATmega168, Duemilanove with ATmega328 and IDE version 0016.

What’s next?

I’ve been looking at more Arduino boards, I already have another Duemilanove, or even the cheaper clones that are available along with more ethernet shields so that a small network of remote sensors can be configured around the house and office. I am already using powerline ethernet adapters so I don’t see why a remote sensor can be plugged into one of these adapters providing the ring mains is all on the same circuit, although the likelyhood is that the upstairs and downstairs circuits are separate.

Sensors to monitor electricity and gas usage should be possible, especially with the Currentcost monitor. I have seen other projects doing this already.

Bookmark this post: bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

26 comments to Basic Environment Monitoring using Arduino and Pachube

  • mildlymad


    I’m just starting to look into the Arduino boards.

    Can you please confirm your code work with the newer Duemilanove board.



  • Administrator

    Hi Martin,

    No problem with the later boards as they have a microcontroller with twice the flash and twice the ram. I’ve just done an update to add regular twitter updates as well as pachube updates. This was on te limits of the memory originally but worked a treat on the newer board.

    Just about to tidy up the combined pachube/twitter code and stick it up here.



  • mildlymad

    Sorry another basic question, will this project work with the Wiznet W5100 based Ethernet Shield from Cool Components, nuelectronics have sold out and are not responding to queries.



  • Administrator

    Hi Martin,

    You refer to the official ethernet shield, this is covered in if you are interested. Although it is easier to use and the library is smaller, it is a lot more expensive. I’ve not go one of these, maybee one day. So at present my code is designed for the ENC28J60 based ethernet shields.

    Know what you mean about nuelectronics, took a few days for them to get back to me this week regarding availability of their boards as I’m after a few more. Bu didnt say when the ethernet shields would be in.



  • joachim

    Brilliant work with the EtherShield library! The examples were a bit hard to understand until you came along. I was trying to find a way to get my energy monitoring online. I have made a monitor based on openenergymonitor, and it displays fine on the lcd, but when I add ethershield and some posting, it all goes haywire. Maybe this is too much for the 328 to handle? Should I go for a different ethernet shield, or split the processing on two uC’s? Has anyone done this?


  • Administrator


    There are a number of ways to put energy monitors on line. I have an arduino processing the output from my currentcost meter. This sends xml every 6 seconds with the latest readings. To process all this and handle network requests is going to tax the little arduinos. However one way to get round this is to use the arduino to process the xml and return the results in a much simplified form on request, for example over the TWI connection. Another alternative and one that I am now using is for the arduino with the ethershield to broadcast a simple UDP packet once the xml has been processed. This is then picked and processed by a simple perl script. The script then extracts the UDP payload, updates a local mysql database, rrd file and sends regular updates to my feeds.

    With the UDP message being broadcast, other machines on the local lan can also receive the messages. It would then be possible to create a windows/linux/max desktop gadget/widget that displays the current usage as a graph or meter.

    Hope this helps


  • mcbain


    I have been looking at your code and i was wondering if you could help me, in oneWire.pde section i want to use more than one sensor maybe 2 or sensor on wire, do you have any idea how to inplement that to your code?

  • mcbain

    sorry i ment 2 or 3 sensors….

  • mcbain

    I have already found out, i rewrote the sketch from the beginning

  • benhowdle


    I’ve played around with this and got it working brilliantly for what i need, so thanks alot for that, but i seem to have hit a strange problem, i just have a simple analog read value coming in and getting posted to webserver/twitter/pachube, this works great but for some reason the value only updates if i download the program again, it doesnt seem to update the webserver on a refresh or anything like that, is it that the data is being written to the webserver once and not anymore times after that?


  • benhowdle

    Big apologies,

    was a stupid error on my side!

    Working perfectly now…thanks

  • Administrator

    Glad you figured it out.



  • benhowdle


    I do apologise for pestering you for answers but you seem to be the only person who has done anything with the nuelectronics ethernet shield that i can understand (documentation wise)!

    I have your code in my arduino monitoring one analog input, sending the value upto pachube and then i have another php script using the pachube-php library to retrieve the csv from pachube then i can either put this in a database or make a webpage etc..this works great however for this to work, i have to have 2 browser windows running, one is the arduino’s webserver and one is this php page which i have set to refresh itself every 10 seconds to retrieve latest value from pachube.

    Is there a way i can do this easier or cleaner and avoid having to have browsers running, ie. services or ajax, i’m on windows btw!

    Thanks for any help!

  • kenboak


    I’ve used your updated (NuElectronics) ethernet shield code to allow sensor data to be sent to Pachube.

    The yellow “activity” LED flashes on my ethernet shield about every 30 seconds, but I don’t seem to be getting an update on my Pachube feed – unless I do a manual refresh.

    I can see the CSV data if I browse the IP either locally or remotely – so I know the data is there.

    Any ideas?

    Thanks in advance


  • Administrator

    Hi Ken,

    I’ve had a look at your feeds, there appears to be data there and you have graphs until you stopped sending (or Pachube stopped receiving) updates. Normally pachube shows the latest numeric value, but the graphs don’t appear to get updated for about 15 minutes, I seem to remember. I think I really need to refresh my memory on the pachube documentation and API as things are changing all the time so original assumptions and code may not be the best way of doing things now.

    My first feed is at and was using the hardware and code as described in the post, although this has now been upgraded to a wireless Jeenode. One thing I do need to update is one of my sensors was moved from a 5V Arduino to a 3.3V Jeenode and now the analogue readings are slightly out, but as this is only a light sensor its not too important.

    The way I check it to look at the Data Updated details:

    Data updated: Sat Jul 10 15:57:39 UTC 2010, currently: live.

    The time shown is GMT so currently 1 hour behind BST.

    I sometimes see broken graphs so not sure if this is missing data due to communication failures.

    Hope this helps


  • kenboak


    Thanks for your prompt reply.

    I noticed that the Pachube feed went from Live to Frozen despite my efforts to restart it.

    I can see the CSV OK if I browse Port 80 of my router

    I’ve edited your sprintf statement so that it just prints the 6 integer readings read directly from the analogue inputs. I’ve noticed that it will only print 5 variables correctly and the 6th is garbage. Is there some sort of time out when using the sprintf statement?

    Any insight appreciated – Ken

    Here’s the relevant lines of code:

    temp0 = analogRead(0);
    temp1 = analogRead(1);
    temp2 = analogRead(2);
    temp3 = analogRead(3);
    temp4 = analogRead(4);
    temp5 = analogRead(5);

    // sprintf( statusstr, “%d,%d,%d,%d,%d,%d”, temp0, temp1, temp2, temp3, temp4, temp5 ); // This makes temp5 garbage

    sprintf( statusstr, “%d,%d,%d,%d,%d”, temp0, temp1, temp2, temp3, temp4 ); // This works OK

  • Administrator

    Using a simple sketch show below I can see that using sprintf with 6 integers shouldn’t be a problem. If you are using the sample code from the post then check the size of the statusstr array. From the example, 50 should be plenty. Also check the size of the packet buffer, if you’ve changed it to preserve memory then one could be overwriting the other. In the demo below, all is good until I change STATUS_BUFFER_SIZE to 22. At this point the last value becomes corrupt because the string terminator has been overwritten by some other variable.

    #define STATUS_BUFFER_SIZE 50

    // global string buffer for twitter message:
    static char statusstr[STATUS_BUFFER_SIZE];

    void setup() {

    void loop() {
    int temp0,temp1,temp2,temp3,temp4,temp5;

    temp0 = analogRead(0);
    temp1 = analogRead(1);
    temp2 = analogRead(2);
    temp3 = analogRead(3);
    temp4 = analogRead(4);
    temp5 = analogRead(5);
    sprintf( statusstr, “%d,%d,%d,%d,%d,%d”, temp0, temp1, temp2, temp3, temp4, temp5 ); // This makes temp5 garbage



    Normal output:


    Corrupt Output:


    Hope this helps.


  • kenboak

    Hi Andy,

    Thanks for that.

    Because I was not using the TWEET code, STATUS_BUFFER_SIZE was being set to 20 !!

    #ifdef TWEET
    #define STATUS_BUFFER_SIZE 200
    int updatesSinceTweet = UPDATES_TO_TWEET;
    #define STATUS_BUFFER_SIZE 20

    Much appreciated,


  • ill_switch

    Hello Andy,

    I’m attempting to use your nice Ethernet library with a homebrew Arduino/Ethernet device that’s basically a carbon copy of the nuelectronics shield you’re using in this project. I’m having trouble getting the device to work, and I was hoping I could steal a few minutes of your time to look at the following thread on the Arduino forum:

  • Administrator

    Just seen your updates, sounds like you’ve got it sorted. Always best to check, check again and check a 3rd time to make sure nothing has been missed.


  • Soneca-II


    I’m strugling to connect my arduino mega using a ENC28j60 “board” to pachube but with no success.

    I already have looked on your demo but can’t really puy it yo work. I already changed the pins used in the library to be compatible with arduino mega and i can run well the DHCP / ping / webserver demo.

    Could you please advise if possibly now the communication with pachube is different due to some update?

    Thanks for your time and best regards


  • Greg

    I’ve just started looking at this code (etherShield_pachubeclient.pde) and am trying to get it working with the updated EtherShield library (

    I’ve changed #includes to EtherShield.h

    When compiling I get ‘initOneWire’ was not declared in this scope
    Its complaining about “initOneWire();”

    Where have I gone wrong?

  • fr33styler

    What would be needed to be done if I would like to use two DS18B20 sensors? Does the oneWire.pde work out of the box with two sensors or do I have to modify something?

  • baltras

    Hi Andy,

    nice library realy appreciate your efforts.
    i was able to use DHCP client example but getting errors when compiling patchube example.

    i’m using latest ethershield library thiseldo-EtherShield-3793b4c together with Arduino 0023.
    when i’m compiling patchubeRGB example i’m receiving this error:

    EtherShield_PachubeRGB:391: error: invalid conversion from ‘void (*)(uint8_t, uint16_t)’ to ‘void (*)(uint8_t, uint16_t, uint16_t)’
    EtherShield_PachubeRGB:391: error: initializing argument 4 of ‘void EtherShield::ES_client_browse_url(prog_char*, char*, prog_char*, void (*)(uint8_t, uint16_t, uint16_t))’

    can you help with that problem?

  • jmaxado

    Hello Andy
    I am trying to use your program.
    I disabled the tweeter and fullweb otions.
    I am able to compile the program and using serial monitor I am able to view my sensor reading.
    But I am not able to upload data to pachube, I can see the data string ready in my browser but no data in pachube.
    My feed 44454 is “frozen”.
    shouldn’t there be in your program somewhere to define the datastream ID ?
    Thank you in advance for your help.


    Ps. If someone could help me on this please contact me josemaxado(at)gmail(dot)com

  • tor_martini

    Hello Andy.

    I have successfully managed to program my self-built Arduino / tuxgraphics clone. ie Arduino running at 3.3 V with enc28j60.
    Everything works as it should, after rewriting it for, but as you mentioned in the building description,the temperature sensors can not provide negative values. Do you have any examples of how I can get the sensors to deliver a negative number, when I use this in a place that can go down to -40 degrees C?

    Thank you.