Dcube Tech Ventures
Published

Temperature Monitoring Using MCP9808 and Arduino Nano

MCP9808 is a highly accurate digital temperature sensor ±0.5°C I2C mini module.

IntermediateProtip4 hours5,139
Temperature Monitoring Using MCP9808 and Arduino Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
MCP9808 Maximum Accuracy Digital Temperature Sensor
×1
I²C Cable
×1
ControlEverything.com I2C Shield for Arduino Nano
×1

Story

Read more

Schematics

MCP9808 Schematic

Code

Full Code

Arduino
#include
// MCP9808 I2C address is 0x18(24)
#define Addr 0x18
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(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();
}
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();  
}    
// Convert the data to 13-bits  
int temp = ((data[0] & 0x1F) * 256 + data[1]);  
if(temp > 4095)  
{    
temp -= 8192;  
}  
float cTemp = temp * 0.0625;  
float fTemp = cTemp * 1.8 + 32;    
// Output data to screen  
Serial.print("Temperature in Celsius : ");  
Serial.println(cTemp);  
Serial.println(" C");  
Serial.print("Temperature in Fahrenheit : ");  
Serial.println(fTemp);  
Serial.println(" F");  
delay(500);
}

Github file

Credits

Dcube Tech Ventures
34 projects • 16 followers
Dcube Tech Ventures Pvt Limited is collaboration of Hardware, Embedded and Software endeavour's to create the Internet of things. www.dcubestore.com
Contact

Comments

Please log in or sign up to comment.