Arduino feeding with temperature from DS18B20

Picture of Arduino feeding with temperature from DS18B20
This instructable will explain how to:
* connect a DS18B20 temperature sensor to an arduino
* read from the sensor using the 1-wire interface
* send that data to directly from the arduino
* view the resulting graph on the internet is an Internet of Things host that generates graphs based on data you provide. In this example I am going to use it to monitor the temperature in my room. It's not a hackerspace, my wife keeps it far too tidy for that.
Remove these adsRemove these ads by Signing Up

Step 1: Parts list

Picture of Parts list
* Arduino with ethernet shield
I have an arduino Uno clone and a wiznet 5100 shield.
* Power supply (it can be powered via the USB port)
I was fortunate that my router has USB ports that provide the 5v output meaning the arduino  is powered whenever the router is and saves a plug, electricity, the environment and the  future of the world.
* DS18B20 temperature sensor
* RJ45 network cable connected between the arduino and your router

Step 2: Schematic

Picture of Schematic
* Arduino gnd to DS18B20 both outer legs
* Arduino 5v to 4.7k resistor leg 1
* 4.7k resistor leg 2 to DS18B20 middle leg
* Arduino digital pin 2 to DS18B20 middle leg
* RJ45 cable from Arduino to router
* Power to Arduino (via USB or barrel jack, I use USB from my router)

Step 3: Prerequisites

Picture of Prerequisites
Three libraries are required for the arduino:
onewire library from (specifically
httpclient library from (
Xively library from (
install these libraries in your arduino/library directory.

An account with (formerly and
Sign up for a free developer account at
Pick a username, password, set your address and timezone etc. You will receive a confirmation email, click the activation link to avtivate your account.
You can choose to take the test drive to learn about xively or skip it, this is completely up to you.
Doing the test drive? I'll wait
- \ | / - \ | /
Done? Let's continue
silver1112 months ago

Hi. is there a way to give their own names sensors (data streams)? Eg. Kitchen, living room, etc. I have 6 sensors.

gregoryfenton (author)  silver1112 months ago

The lines to change are
<code>// Define the strings for our datastream IDs

char sensorId[] = "temp";</code>
specifically, change "temp" to each of your device names eg "garage temp"

I have been thinking about this for sensor 1 = kitchen, sensor 2 = living room and so on. Where to enter the name of the second third and subsequent sensors? Everyone must have a different name.

şerafettink4 months ago

I want to make circuit b using 4 sensors and 4 single resistor sensor connections print.4 sensor enough for my seven-inch screen. Is there another Arduino, or need

silver11110 months ago

Hi. if someone was able to run it with multiple sensors (5)?

erojs silver1116 months ago

for multiple sensors in the end of the code after Serial.println("Uploading it to Xively");


datastreams[0] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),


XivelyDatastream datastreams[0] = XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT);

Worked for me, hope that helps.

slightly corrected and in my code runs on multiple sensors.

I just have a problem with the naming of streams. What I mean is that the individual data struienia zwoimi call names and not the serial numbers of sensors.


May I ask what you did to get multiple sensors working? I'd like to add additional temp probes but haven't been having much luck.

sidbin1 year ago


Serial.println("Uploading it to Xively");
datastreams[0] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),

  • ------------------------
sketch_feb13d.ino: In function 'void loop()':

sketch_feb13d:178: error: expected primary-expression before '{' token
sketch_feb13d:178: error: expected `;' before '{' token

silver111 sidbin10 months ago

Hi. if you were able to run the project with multiple sensors?

gregoryfenton (author)  sidbin1 year ago
There is a missing after the , in that line. I will have a look shortly and get b back to you.
chetan041211 months ago


Please give solution...

IP address:

Chip = DS18B20

Current temperature: 33.13 celsius

Uploading it to Xively

xivelyclient.put returned -3

chetan041211 months ago

Connection and setup done but not working...

denisr11 months ago

Greg; Hi. As with rparkera and sidbin below, I have the same problem with the multiple sources sketch that they have.

I get the following errors:

Multiple_Xively.ino: In function 'void loop()':

Multiple_Xively:179: error: expected primary-expression before '{' token

Multiple_Xively:179: error: expected `;' before '{' token

Multiple_Xively:188: error: expected `}' at end of input

You were going to get back to sidbin, but don't seem to have done so.

And for the record, I have only just started using Arduino as it's the most practical solution (I think) to a long running temperature monitoring problem I have.


rparkera1 year ago

Hi there - great instructable. Many thanks

Did you ever get back on sidbin's query? I have exactly the same problem. The single datastream works fine - but I can't get the multiple sources working. Help!

agavrin1 year ago

Some other example to use for xively reporting - use it to track URL performance..

fiolin1 year ago

Works for me thank you to share it

la3bna1 year ago

here is my feed:

But I don't think it's public yet. Can you help me with that?

gregoryfenton (author)  la3bna1 year ago

It works for me :)

la3bna1 year ago
(removed by author or community request)
gregoryfenton (author)  la3bna1 year ago

Check step 5 and look at the picture. At the top it says "public".

If yours is set to private, click on the button (it looks like a pencil) to edit the settings.

Change it from "Private Device" to "Public Device", click "save and continue".

All done :)

Feel free to post a link to your public feed :)

Thanks! I didn't see that until you pointed it out for me


boernic1 year ago
hi i have followed your instructable and it works great!

im am thinking of adding some xtra ds18b20 sensors and wonder how to adress them any hints?


gregoryfenton (author)  boernic1 year ago
Just plug them in in parallel. The code will read them in order.
To update more than one datastream, look at the dataStreams[] parts of the code.

Thanks for the tutorial. I tried it and its working great with 1 sensor, but i cant see how to get a second or more sensors working. Any chance you could elaborate on the above a little more? Thanks in advance...

Hi guys I need your help,

I've followed all the steps in this great tutorial but it doesn't work for me.

I keep on getting "No more addresses" in the serial monitor and xively is not receiving any datapoints.

What does this mean and how could it be solved?

It would be really great if one of you could help me
speedy251 year ago
Hey guys I have a problem.
I would like to add more sensors (DS18B20) and it fails.

Could you help me i am a beginner.

Thank you in advance for your help

zenius1 year ago
Thanks for your intructable ! :-)
It worked perfectly for 9 minutes, but now it's not sending anything…
What is the problem ?
gregoryfenton (author)  zenius1 year ago
Hi Zenius :)

Are you powering the Arduino from a steady power supply?
Have you tried resetting the Arduino?
Mine has been running pretty much continuously since it was set up with no issues apart from when the network cable became loose a couple of times. I think it has also only been turned off a couple of times too when I was sorting out round the router.

Get back to me :)
theohegg1 year ago
Hi there! Im trying to use your xively code but Im getting an "i" was not declared in this scope error. Would you know why this might be ? Im a bit new to arduino
gregoryfenton (author)  theohegg1 year ago
Fixed in the code.

I missed the line
int i;
float celcius;

I apologise for the oversight.
Thx a lot. Now it works perfect
gregoryfenton (author)  theohegg1 year ago
Glad I could help :)

What's your xively link so I can see it working? :)
This is my link. Tried to get a second temp read working but luck so far
cpoplawski1 year ago
I have everything wired up the same way as in your sketch except I don't seem to be getting any data from the sensor. When i use the example one wire sketch specific to the sensor it has no problems. any ideas?
gregoryfenton (author)  cpoplawski1 year ago
I apologise, I forgot to do the actual reading of the chip in the above code :P

You need to add the following

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] =;


ds.write(0xBE); // Read Scratchpad

josephyong1 year ago
Please help, everything is fine just unable to get data from 18B20 Sensor it show IP address:
Chip = DS18B20
Current temperature: 0.00 celsius
Uploading it to Xively
xivelyclient.put returned 200
i have double check the connection is correct.
gregoryfenton (author)  josephyong1 year ago
I apologise, I forgot to do the actual reading of the chip in the above code :P

You need to add the following

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] =;


ds.write(0xBE); // Read Scratchpad

gregoryfenton (author) 1 year ago
I apologise, I forgot to do the actual reading of the chip in the above code :P

You need to add the following

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] =;


ds.write(0xBE); // Read Scratchpad