GitHub - milesburton/Arduino-Temperature-Control-Library: 🌡️ Arduino library for interfacing with Maxim temperature sensors like DS18B20, DS18S20, and MAX31850. 🔌 Supports multiple sensors, ⚡ asynchronous operation, and 🎯 configurable resolution for precise temperature monitoring. (original) (raw)
🌡️ Arduino Temperature Control Library
A robust and feature-complete Arduino library for Maxim Temperature Integrated Circuits.
📌 Supported Devices
- DS18B20
- DS18S20 (⚠️ Known issues with this series)
- DS1822
- DS1820
- MAX31820
- MAX31850
🚀 Installation
Using Arduino IDE Library Manager (Recommended)
- Open Arduino IDE
- Go to Tools > Manage Libraries...
- Search for "DallasTemperature"
- Click Install
- Also install the required "OneWire" library by Paul Stoffregen using the same method
Manual Installation
- Download the latest release from GitHub releases
- In Arduino IDE, go to Sketch > Include Library > Add .ZIP Library...
- Select the downloaded ZIP file
- Repeat steps 1-3 for the required "OneWire" library
📝 Basic Usage
- Hardware Setup
- Connect a 4k7 kΩ pull-up resistor between the 1-Wire data line and 5V power. Note this applies to the Arduino platform, for ESP32 and 8266 you'll need to adjust the resistor value accordingly.
- For DS18B20: Ground pins 1 and 3 (the centre pin is the data line)
- For reliable readings, see pull-up requirements in the DS18B20 datasheet (page 7)
- Code Example
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to GPIO 4
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void) {
Serial.begin(9600);
sensors.begin();
}
void loop(void) {
sensors.requestTemperatures();
delay(750);
float tempC = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println("°C");
delay(1000);
}
🛠️ Advanced Features
- Multiple sensors on the same bus
- Temperature conversion by address (
getTempC(address)
andgetTempF(address)
) - Asynchronous mode (added in v3.7.0)
- Configurable resolution
Configuration Options
You can slim down the code by defining the following at the top of DallasTemperature.h:
#define REQUIRESNEW // Use if you want to minimise code size #define REQUIRESALARMS // Use if you need alarm functionality
📚 Additional Documentation
Visit our Wiki for detailed documentation.
🔧 Library Development
If you want to contribute to the library development:
Using Dev Container
The project includes a development container configuration for VS Code that provides a consistent development environment.
- Prerequisites
- Visual Studio Code
- Docker
- VS Code Remote - Containers extension
- Development CommandsWithin the dev container, use:
arduino-build
- Compile the library and examplesarduino-test
- Run the test suitearduino-build-test
- Complete build and test processNote: Currently compiling against arduino:avr:uno environment
✨ Credits
- Original development by Miles Burton mail@milesburton.com
- Multiple sensor support by Tim Newsome nuisance@casualhacker.net
- Address-based temperature reading by Guil Barros [gfbarros@bappos.com]
- Async mode by Rob Tillaart [rob.tillaart@gmail.com]
📄 License
MIT License | Copyright (c) 2025 Miles Burton
Full license text available in LICENSE file.