Arduino Nano - MCP9803 Temperature Sensor Tutorial

by Dcube Tech Ventures in Circuits > Electronics

53 Views, 0 Favorites, 0 Comments

Arduino Nano - MCP9803 Temperature Sensor Tutorial

Arduino Nano - MCP9803 Temperature Sensor Tutorial

MCP9803 is a 2-wire high accuracy temperature sensor. They are embodied with user- programmable registers that facilitate temperature sensing applications. This sensor is suited for highly sophisticated multi-zone temperature monitoring system. Here is its demonstration with arduino nano.

What You Need..!!

MCP9803_I2CS.png
nano.png

Connections:

MCP9803_I2CS.png
nano.png
sensor.jpg
arduino_connect.JPG

Take an I2C shield for Arduino Nano and gently push it over the pins of Nano.

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

Connections are shown in the picture above.

Code:

arduino_connect.JPG

The arduino code for MCP9803 can be downloaded from our github repository-Dcube Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/MCP9803/blob/master/Arduino/MCP9803.ino

We include library Wire.h to facilitate the I2c communication of the sensor with the Arduino board. 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.

// MCP9803

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

#include

// MCP9803 I2C address is 0x48(72)

#define Addr 0x48

void setup()

{

// 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(0x60);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[2];

// Starts I2C communication

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x00);

// 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();

}

// Convert the data to 12-bits

int temp = ((data[0] * 256) + data[1]) / 16.0;

if(temp > 2047)

{

temp -= 4096;

}

float cTemp = temp * 0.0625;

float fTemp = cTemp * 1.8 + 32;

// Output data to serial monitor

Serial.print("Temperature in Celsius : ");

Serial.print(cTemp);

Serial.println(" C");

Serial.print("Temperature in Fahrenheit : ");

Serial.print(fTemp);

Serial.println(" F");

delay(500);

}

Applications:

MCP9803 can be employed in a wide arena of devices which include personal computer and peripherals, hard disk drives, various entertainment systems, office systems and data communication systems. This sensor can be incorporated in various sophisticated systems.