Temperature Sensing with Particle

Updated 05 January 2017

If you’re looking for a platform to create your ideal data-logger, then look no further than Particle. Whether it be that you want to build a weather station, or a movement detection system, thanks to Particle’s 3G and Wi-Fi boards, you can monitor data in real time, from anywhere in the world using Particle cloud!

One of the most common things to measure is the temperature. Creating a temperature monitor is a great project for beginners and experts alike, and today we’re going to show you how to create an IoT temperature sensor and how you can monitor that data via the internet.

The DS18B20 is a digital temperature sensor which uses the one-wire communication protocol to communicate. We won’t be covering much on this protocol in this tutorial, but for more info, check out our temperature sensing with Raspberry Pi tutorial.

The Gear

To follow this tutorial, you’ll require the following:

  • Particle Photon or Electron. The code and wiring will work for both, it just depends on whether you want a Wi-Fi connection or 3G connection.
  • DS18B20 digital temperature sensor. We’ve used the waterproof probe version, however, you can get the same sensor chip in a standard 3 pin TO-92 package which is easier for bread-boarding.
  • 4.7K pull-up resistor (the Sparkfun Resistor Pack is a great choice).
  • OLED or LCD character display. This isn’t necessary if you only want to view the temperature value from the data log, however, if you want to see a real time update of the temperature, you’ll need a way to display it.
  • To connect up your sensor, you’ll also need a breadboard and some jumper wires. Alternatively, you can always solder your sensors to the board pins if you’re creating a permanent project.

Setting up IFTTT

IFTTT applet Particle and Google Drive

For this tutorial, we’ll use IFTTT to log the data in our Particle.variable ‘tempC’ to a sheet in Google Drive. Check out our Remote Sensing with Particle tutorial for more detailed info on how to set this up, but in the Particle channel trigger, select the variable trigger, and choose your board accordingly. The rest of the tutorial goes through the process of setting it up with Google Drive.

The Circuit

The circuit setup below is quite simple. The DS18B20 temperature sensor connects to power, ground, and the data pin to your board with a 4.7K pull-up resistor. Note that some DS18B20 probes may have 4 wires instead of three, in which case you’ll want to use the white wire as shown in the circuit diagram.

Particle DS18B20 OLED character display breadboard diagram

The Code

For this application, we’ll be using two libraries on the Particle cloud; the one-wire library, and the Dallas-temperature library. Whilst it’s possible to get away with just the one-wire library, using the Dallas-temperature library takes care of the address handling, and makes getting the temperature a simple, one-function process.

The variable tempC is exposed as a Particle.variable which will allow us to read it using IFTTT and log it in a Google Sheet.

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_CharacterOLED_Particle/Adafruit_CharacterOLED_Particle.h"
// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"
// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"
OneWire oneWire(A1);
Adafruit_CharacterOLED lcd(OLED_V2, 6, 5, 4, 3, 2, 1, 0);
DallasTemperature ds(&oneWire);
double tempC;
void setup()
    lcd.begin(16, 2);
void loop()
    //read the sensor value
    //store sensor value in degrees celcius
    tempC = ds.getTempCByIndex(0);
    //print value to display
    //delay of 1000ms is required by the DS18B20, however we don't want to flood the Particle cloud

And that’s all there is to it. You now have a fully functional temperature station which is capable of running on a Wi-Fi or 3G board, and displays the current temperature, as well as logging it to the cloud!

What Now?

Be sure to check out some of our other Particle tutorials. There’s no limit to what you can do with them, and you can record all kinds of sensor data to log using this same method.

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.



Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.