Categories

Arduino and DS1624 temperature sensor

The DS1624 consists of two separate functional units: a 256-byte nonvolatile E2 memory and a direct-to-digital temperature sensor.

The nonvolatile memory is made up of 256 bytes of E2 memory. This memory can be used to store any type of information the user wishes. These memory locations are accessed through the 2-wire serial bus.

The direct-to-digital temperature sensor allows the DS1624 to measure the ambient temperature and report the temperature in a 12-bit word with 0.0625°C resolution. The temperature sensor and its related registers are accessed through the 2-wire serial interface. Figure 1 in the full data sheet shows a block diagram of the DS1624.

Features

Reduces Component Count with Integrated Temperature Sensor and Nonvolatile E2 Memory
Measures Temperatures from -55°C to +125°C in 0.0625°C Increments
±0.5°C Accuracy from 0°C to 70°C
256 Bytes of E2 Memory for Storing Information Such as Frequency Compensation Coefficients
No External Components
Easy-to-Use 2-Wire Serial Interface
Temperature is Read as a 12-Bit Value (2-Byte Transfer)
Available in 8-Pin SO and DIP Packages

 

Connection

Module Arduino
VDD 5v
Gnd Gnd
SDA SDA – A4
SCL SCL – A5

 

Code

I downloaded and imported the following library – https://github.com/bluemurder/DS1624

This is the example so some of the hard graft has already been done for you

#include <DS1624.h>
 
// Sensor presents all address pins connected to ground
DS1624 ds1624(0x00);
 
void setup()
{ 
// Begin serial connection at 9600 baud
Serial.begin(9600);
}
 
void loop()
{
float temperature;
bool valid;
 
// Get current temperature
ds1624.GetTemperature(temperature, valid);
 
// Print it
Serial.println(temperature);
 
// Wait a while
delay(1000);
}

Testing

Open the serial monitor and you should see the following

24.31
24.31
24.87
25.94
26.44
27.06
27.37
27.81
27.81
27.69

 

Link

https://datasheets.maximintegrated.com/en/ds/DS1624.pdf

Share

MCP9808 digital temperature sensor example

MCP9808 digital temperature sensor example

The MCP9808 digital temperature sensor converts temperatures between -20°C and +100°C to a digital word with ±0.5°C (max.) accuracy. The MCP9808 comes with user-programmable registers that provide flexibility for temperature sensing applications. The registers allow user-selectable settings such as Shutdown or low-power modes and the specification of temperature Event and Critical output boundaries. When the temperature changes beyond the specified boundary limits, the MCP9808 outputs an Event signal. The user has the option of setting the event output signal polarity as an active-low or active-high comparator output for thermostat operation, or as temperature event interrupt output for microprocessor-based systems. The event output can also be configured as a Critical temperature output. This sensor has an industry standard 2-wire, SMBus and Standard I2C™Compatible compatible (100kHz/400kHz bus clock) serial interface, allowing up to eight sensors to be controlled in a single serial bus.
Features

Accuracy:
±0.25°C (typical) from -40°C to +125°C
±0.5°C (maximum) from -20°C to +100°C

User Selectable Measurement Resolution:
0.5°C, 0.25°C, 0.125°C, 0.0625°C

User Programmable Temperature Limits:
Temperature Window Limit
Critical Temperature Limit

User Programmable Temperature Alert Output
Operating Voltage Range: 2.7V to 5.5V

More details about the sensor at http://www.microchip.com/wwwproducts/en/MCP9808

This typically comes in a breakout such as the one in the breakout below

Code

You will need the adafruit MCP9808 library which is available at https://github.com/adafruit/Adafruit_MCP9808_Library/archive/master.zip

#include <Wire.h>
#include "Adafruit_MCP9808.h"
 
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
 
void setup() {
  Serial.begin(9600);
 
  if (!tempsensor.begin()) 
  {
    Serial.println("Couldn't find MCP9808!");
    while (1);
  }
}
 
void loop() {
  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); 
  Serial.print(c); 
  Serial.print(" C\t"); 
  Serial.print(f); 
  Serial.println(" F");
  delay(250);
 
  tempsensor.shutdown_wake(1);
  delay(2000);
  tempsensor.shutdown_wake(0);
 
 
}

 

Results

Open the serial monitor and you should see something like this

Temp: 21.69 C 71.04 F
Temp: 21.62 C 70.93 F
Temp: 24.50 C 76.10 F
Temp: 25.06 C 77.11 F
Temp: 25.37 C 77.68 F
Temp: 25.56 C 78.01 F
Temp: 24.25 C 75.65 F
Temp: 23.87 C 74.97 F

 

Links
Adafruit MCP9808 High Accuracy I2C Temperature Sensor Breakout Board [ADA1782]

Share

LM35 temperature sensor

In this example we will connect an LM35 temperature sensor to our Arduino

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1/4°C at room temperature and ±3/4°C over a full -55 to +150°C  temperature range

Here is a picture of the pins, its important to get these correct or you can damage the sensor

LM35 temperature sensor pinout

LM35 temperature sensor pinout

I purchased a small module, which looks like this. This was clearly labelled and helps avoid any mistakes with wiring, I also prefer using cables to modules rather than breadboards

lm35 module

lm35 module

Schematics and Parts

You will need

Arduino Uno
LM35 sensor or module
Hook up wire (dupont cables)

Very simple to connect Vcc is 5v, Gnd is any Gnd and out goes to Arduino A0, you can see this below

Arduino and lm35 schematic

Arduino and lm35 schematic

Code

//initializes/defines the output pin of the LM35 temperature sensor
int outputpin= 0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
}
 
//main loop
void loop()
{
int rawvoltage= analogRead(outputpin);
float millivolts= (rawvoltage/1024.0) * 5000;
float celsius= millivolts/10;
Serial.print(celsius);
Serial.print(" degrees Celsius, ");
 
Serial.print((celsius * 9)/5 + 32);
Serial.println(" degrees Fahrenheit");
delay(1000);
 
}

Results

Here are the results via the serial monitor

arduino and lm35 serial output

arduino and lm35 serial output

 

Links

LM35 datasheet

 
5PCS LM35D Temperature Sensor TO92 Packing

Share

SHT21 humidity and temperature sensor example

The SHT21 is a low cost humidity and temperature sensor. Its an I2C device so again is very simple to connect to any arduino

This is the breakout for the sensor that I bought.

SHT21

SHT21

Here is a simple schematic, again be careful as Vcc is 3.3v with this device

Schematic

UNO and SHT21

UNO and SHT21

Lets look at the required libraries and a basic code example, there is not much to this to be honest most of the work is done in the library

Code

There are a couple of libraries to help you out

https://github.com/misenso/SHT2x-Arduino-Library
https://github.com/elechouse/SHT21_Arduino

I used the latter one

 

#include <Wire.h>
#include <SHT2x.h>
 
 
void setup()
{
  Wire.begin();
  Serial.begin(9600);
}
 
void loop()
{
  Serial.print("Humidity: ");
  Serial.println(SHT2x.GetHumidity());
  Serial.print("Temperature(C): ");
  Serial.println(SHT2x.GetTemperature());
  Serial.println();
  delay(1000);
}

Links

these come in at about $7 for a useful breakout board with this sensor

Humidity Sensor – SHT21 Breakout Board

Share