Particle Photon - MCP9808 Temperature Sensor Tutorial

by Dcube Tech Ventures in Circuits > Electronics

11 Views, 0 Favorites, 0 Comments

Particle Photon - MCP9808 Temperature Sensor Tutorial

Particle Photon - MCP9808 Temperature Sensor Tutorial

MCP9808 is a highly accurate digital temperature sensor ±0.5°C I2C mini module. They are embodied with user- programmable registers that facilitate temperature sensing applications. The MCP9808 high-accuracy temperature sensor has become an industry standard in terms of form factor and intelligence, providing calibrated, linearised sensor signals in digital, I2C format. Here is the demonstration with Particle Photon.

What You Need..!!

IMG_2733.JPG
Particle-26_large.jpg

Connection :

IMG_2733.JPG
Particle-26_large.jpg
sensor.jpg
IMG_2808.JPG

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 MCP9808 sensor and the other end to the I2C shield.

Connections are shown in the picture above.

Code:

IMG_2808.JPG

The particle code for MCP9808 can be downloaded from our GitHub repository- DCUBE Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/MCP9808/blob/master/Particle/MCP9808.ino

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.

// MCP9808

// This code is designed to work with the MCP9808_I2CS I2C Mini Module

#include

#include

// MCP9808 I2C address is 0x18(24)

#define Addr 0x18

float cTemp = 0, fTemp = 0;

void setup()

{

// Set variable

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

Particle.variable("cTemp", cTemp);

// Initialise I2C communication as MASTER

Wire.begin();

// Initialise Serial Communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select configuration register

Wire.write(0x01);

// Continuous conversion mode, Power-up default

Wire.write(0x00);

Wire.write(0x00);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select resolution register

Wire.write(0x08);

// Resolution = +0.0625 / C

Wire.write(0x03);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[2];

// Starts I2C communication

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x05);

// Stop I2C transmission

Wire.endTransmission();

// Request 2 bytes of data

Wire.requestFrom(Addr, 2);

// Read 2 bytes of data

// temp msb, temp lsb

if(Wire.available() == 2)

{

data[0] = Wire.read();

data[1] = Wire.read();

}

delay(300);

// Convert the data to 13-bits

int temp = ((data[0] & 0x1F) * 256 + data[1]);

if(temp > 4095)

{

temp -= 8192;

}

cTemp = temp * 0.0625;

fTemp = cTemp * 1.8 + 32;

// Output data to dashboard

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

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

delay(500);

}

Applications:

MCP9808 Digital Temperature Sensor has several industry level applications which incorporate industrial freezers and refrigerators along with various food processors. This sensor can be employed for various personal computers, servers as well as other PC peripherals.