ModularSensors > Modules > Supported Sensors > Maxim DS18

Maxim DS18 module

Classes for the Maxim DS18 one-wire temperature sensors.

Introduction

The Maxim temperature probes communicate using the OneWire library, which can be used on any digital pin on any of the supported boards. The same module should work with a DS18B20, DS18S20, DS1822, MAX31820, and the no-longer-sold DS1820 sensor. These sensors can be attached to a 3.0-5.5V power source or they can take "parasitic power" from the data line. When using the more typical setup with power, ground, and data lines, a 4.7k resistor must be attached as a pull-up between the data and power lines. The one-wire communication protocol is slow and interrupts are turned off during communication. Keep this in mind if using this sensor in combination with a rain gauge or other interrupt-driven sensor.

The resolution of the DS18B20, DS1822, and MAX31820 temperature sensors are user-configurable to 9, 10, 11, or 12 bits, corresponding to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit, unless it has previously been set to something else. The resolution of the DS18S20 is set at 9-bit

The OneWire hex address of the sensor, the Arduino pin controlling power on/off, and the Arduino pin sending and receiving data are required for the sensor constructor. The OneWire address is an array of 8 hex values, for example: {0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0}. To get the address of your sensor, plug a single sensor into your device and run the oneWireSearch example or the Single example provided within the Dallas Temperature library. The sensor address is programmed at the factory and cannot be changed.

Sensor Datasheet

Sensor Constructor

MaximDS18(DeviceAddress OneWireAddress, int8_t powerPin, int8_t dataPin, uint8_t measurementsToAverage = 1)

Construct a new Maxim DS18 with a known sensor address.

Parameters
OneWireAddress The unique address of the sensor. Should be an array of 8 values. To get the address of your sensor, plug a single sensor into your device and run the oneWireSearch example or the Single example provided within the Dallas Temperature library. The sensor address is programmed at the factory and cannot be changed.
powerPin

The pin on the mcu controlling power to the DS18, if using a separate power pin. Use -1 if the DS18 is continuously powered or you are using "parasitic" power.

  • Requires a 3.0 - 5.5V power source
dataPin The pin on the mcu of the OneWire bus.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Use this version for more than one sensor attached to the OneWire bus.



Example Code

The Maxim DS18 is used in the menu a la carte example.

#include <sensors/MaximDS18.h>

// OneWire Address [array of 8 hex characters]
// If only using a single sensor on the OneWire bus, you may omit the address
DeviceAddress OneWireAddress1 = {0x28, 0xFF, 0xBD, 0xBA,
                                 0x81, 0x16, 0x03, 0x0C};
// NOTE: Use -1 for any pins that don't apply or aren't being used.
const int8_t OneWirePower       = sensorPowerPin;  // Power pin
const int8_t OneWireBus         = A0;              // OneWire Bus Pin
const int8_t ds18NumberReadings = 3;

// Create a Maxim DS18 sensor objects (use this form for a known address)
MaximDS18 ds18(OneWireAddress1, OneWirePower, OneWireBus, ds18NumberReadings);

// Create a Maxim DS18 sensor object (use this form for a single sensor on bus
// with an unknown address)
// MaximDS18 ds18(OneWirePower, OneWireBus);

// Create a temperature variable pointer for the DS18
Variable* ds18Temp = new MaximDS18_Temp(&ds18,
                                        "12345678-abcd-1234-ef00-1234567890ab");

Classes

class MaximDS18
The Sensor sub-class for the DS18 one-wire temperature sensors.
class MaximDS18_Temp
The Variable sub-class used for the temperature output from a Maxim one-wire temperature sensor.

Defines

#define DS18_NUM_VARIABLES = 1
Sensor::_numReturnedValues; the DS18 can report 1 value.
#define DS18_INC_CALC_VARIABLES = 0
Sensor::_incCalcValues; we don't calculate any additional values.

Sensor Timing

The sensor timing for a Maxim DS18

#define DS18_WARM_UP_TIME_MS = 2
Sensor::_warmUpTime_ms; the DS18 warms up in 2ms (reset time is < 480 µs).
#define DS18_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; the DS18 is stable as soon as it warms up (0ms stabilization).
#define DS18_MEASUREMENT_TIME_MS = 750
Sensor::_measurementTime_ms; the DS18 takes 750ms to complete a measurement (at 12-bit: 750ms).

Temperature

The temperature variable from an Maxim DS18

  • Range is -55°C to 125°C
  • Accuracy:
    • ± 0.5°C from -10°C to +85°C for DS18S20 and DS18B20
    • ± 2°C for DS1822 and MAX31820
  • Resolution:
    • 0.0625°C for DS18B20, DS1822, and MAX31820 (12-bit)
    • 0.5°C for DS18S20 (9-bit)
    • DS18_TEMP_RESOLUTION = 4
  • Reported as degrees Celsius (°C)
  • Default variable code is DS18Temp

MaximDS18_Temp(MaximDS18* parentSense, const char* uuid = "", const char* varCode = DS18_TEMP_DEFAULT_CODE) explicit

Construct a new MaximDS18_Temp object.

Parameters
parentSense The parent MaximDS18 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "DS18Temp".

#define DS18_TEMP_RESOLUTION = 4
Decimals places in string representation; temperature should have 4.
#define DS18_TEMP_VAR_NUM = 0
Sensor variable number; temperature is stored in sensorValues[0].
#define DS18_TEMP_VAR_NAME = "temperature"
Variable name in ODM2 controlled vocabulary; "temperature".
#define DS18_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define DS18_TEMP_DEFAULT_CODE = "DS18Temp"
Default variable short code; "DS18Temp".