Introduction: Particle Photon - STS21 Temperature Sensor Tutorial

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

STS21 Digital Temperature Sensor offers superior performance and a space saving footprint. It provides calibrated, linearized signals in digital, I2C format. Fabrication of this sensor is based on CMOSens technology, which attributes to the superior performance and reliability of STS21. The resolution of STS21 can be changed by command, low battery can be detected and a checksum helps to improve communication reliability. Here is its demonstration of interfacing it with Particle Photon.

Step 1: What You Need..!!

Step 2: Connection:

Take an I2C shield for particle photon and gently push it over the pins of particle photon.

Then connect the one end of I2C cable to STS21 sensor and the other end to the I2C shield.

Connections are shown in the picture above.

Step 3: Code:

The particle code for STS21 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

We have used two libraries for particle code, which are application.h and spark_wiring_i2c.h. Spark_wiring_i2c library is required to facilitate the I2C communication with the sensor.

You can also copy the code from here, it is given as follows:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// STS21

// This code is designed to work with the STS21_I2CS I2C Mini Module available in Dcube Store.



// STS21 I2C address is 0x4A(74)

#define addr 0x4A

float cTemp = 0.0;

void setup()


// Set variable

Particle.variable("i2cdevice", "STS21");

Particle.variable("cTemp", cTemp);

// Initialise I2C communication as MASTER


// Start serial communication, set baud rate = 9600



void loop()


unsigned int data[2];

// Start I2C Transmission


// Select no hold master


// End I2C Transmission



// Request 2 bytes of data

Wire.requestFrom(addr, 2);

// Read 2 bytes of data

if (Wire.available() == 2)


data[0] =;

data[1] =;


// Convert the data

int rawtmp = data[0] * 256 + data[1];

int value = rawtmp & 0xFFFC;

cTemp = -46.85 + (175.72 * (value / 65536.0));

float fTemp = cTemp * 1.8 + 32;

// Output data to dashboard

Particle.publish("Temperature in Celsius : ", String(cTemp));

Particle.publish("Temperature in Fahrenheit: ", String(fTemp));



Step 4: Applications:

STS21 Digital Temperature Sensor can be employed in systems which require high accuracy temperature monitoring. It can be incorporated in various computer equipments, medical equipments and industrial control systems with the requisite of temperature measurement with proficient accuracy.