Temperature Measurement Projects

DS1631 – Arduino Code and Temperature Validation

Basic information

The DS1631 is a low cost, I2C interface digital thermometer popular in the maker community. Capable of providing 12-bit temperature readings over a -55°C to +125°C range. I have need for a digital thermometer in many of my projects and thought it would be nice to do a simple validation against a standard thermocouple. I have also provided an Arduino Script for use with the Arduinos IDE. This code comes from the archived Arduino forums; I have updated it so it will work with a newer IDE (version 1.6.6) and Wire.h library.

Image- Arduino Code and Temperature Validation

The thermocouple is read using a NI 9214 thermocouple input module as shown below. The wiring schematic for the DS1631 as tested is also provided. All three address pins are pulled low, to give the chip an address of 0x90.

Schematic

Schematic- Arduino Code and Temperature Validation

Data

The figures below are a brief set of data collected during testing of the DS1631. Here the IC is tested against a type J thermocouple. Data in the first figure was collected using a heat gun to heat up both sensors. The heat gun was set to 100 C, and the data was collected at 500 Hz for both sensors. The difference in the recorded temperature may be a factor of how the DS1631 package holds heat, vs the bare tip of the thermocouple. The second set of data was collected over a few hours in my office. You can clearly see the temperature swing at the beginning when I leave my office.

The temperature is higher when I am in the office (lights on and door open) and cooler when I leave (lights off and door closed). This second set was recorded at 0.5 Hz. The DS1631 seems to track the thermocouple temperature when the sensors are only measuring the ambient temperature.

|500x374
|500x374

DS1631 code for I2C address set to 0x90

#include 

// PIN adresses are set to GND
#define DS1631_ADDR 0x90 >> 1

// SETUP
void setup(){
   
 // Setup Serial connection
 Serial.begin(9600); 
 Serial.println("");
 Serial.println("-----------------------------------");
 Serial.println("DS1631 test: Temp. sensor"); 
 Serial.println("-----------------------------------");
 Serial.println("");

 Wire.begin();             // join I2C bus

 // Stop conversion to be able to modify "Access Config" Register
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write((int)(0x22)); // Stop conversion
 Wire.endTransmission();  
   
 // Read "Access Config" regsiter
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write((int)(0xAC)); // @AC : Acces Config
 Wire.endTransmission();
 Wire.requestFrom(DS1631_ADDR,1); //Read 1 byte
 Wire.available();
 int AC = Wire.read(); // receive a byte

 Serial.print("Acces Config (Before): "); Serial.print(AC);  Serial.println("");
   
 // WRITE into "Access Config" Register
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write(0xAC); // @AC : Acces Config
 Wire.write(0x0C); // Continuous conversion & 12 bits resolution
 Wire.endTransmission();
   
 // READ "Access Config" register
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write((int)(0xAC)); // @AC : Acces Config
 Wire.endTransmission();
 Wire.requestFrom(DS1631_ADDR,1);
 Wire.available();
 AC = Wire.read();

 Serial.print("Acces Config (AFTER): "); Serial.print(AC);  Serial.println("");

 // START conversion to get T°
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write((int)(0x51)); // Start Conversion
 Wire.endTransmission();
}

// Main Loop
void loop(){

 //READ T°
 Wire.beginTransmission(DS1631_ADDR);
 Wire.write((int)(0xAA)); // @AA : Temperature
 Wire.endTransmission();
 Wire.requestFrom(DS1631_ADDR,2); // READ 2 bytes
 Wire.available(); // 1st byte
 int Th = Wire.read(); // receive a byte
 Wire.available(); // 2nd byte
 int Tl = Wire.read(); // receive a byte


 // T° processing
 if(Th>=0x80) //if sign bit is set, then temp is negative
 Th = Th - 256;
 int T_dec=(10*(100*(Tl/16)))/16; // decimal part of the T°

 // Display T° on "Serial Monitor"
 Serial.print("Temperature : ");
 Serial.print(Th);   Serial.print(".");
 if (T_dec<10)   Serial.print("0");
 if (T_dec<100)   Serial.print("0");
 Serial.print(T_dec);   Serial.print(" degC / ");
 Serial.print("Th register: "); Serial.print(Th);  Serial.print(" / ");
 Serial.print("Tl register: "); Serial.print(Tl);  Serial.println("");

 // Wait 1s before restart
 delay(1000);
}

A few more pictures can be found on my current website.

At http://adowney2.public.iastate.edu/projects/DS1631/DS1631.html#

For More Detail: Arduino Code and Temperature Validation

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close
Close