Integrating DS18B20 Waterproof Temperature Sensors With Arduino Using One-Wire Protocol
Connect your DS18B20 waterproof sensors to Arduino using the One-Wire protocol-link red to 5V, black to GND, and yellow or white to a digital pin with a 4.7kΩ pull-up resistor to 5V. Use the OneWire and DallasTemperature libraries for reliable, ±0.5°C accurate readings from -55°C to +125°C. Avoid -127°C errors by ensuring solid wiring and that external pull-up. Multiple sensors work on one pin, each identifiable by its unique 64-bit address, making scaling easy and cost-effective, just like commercial environmental monitors. There’s more to optimizing your setup than just the basics.
We are supported by our audience. When you purchase through links on our site, we may earn an affiliate commission, at no extra cost for you. Learn more. Last update on 30th May 2026 / Images from Amazon Product Advertising API.
Notable Insights
- Connect DS18B20 VDD to 5V, GND to ground, and data to a digital pin with a 4.7kΩ pull-up resistor for reliable communication.
- Use the OneWire and DallasTemperature libraries to handle sensor communication and simplify temperature reading in code.
- Waterproof sensors use red (VDD), black (GND), and yellow/white (data) wires-ensure correct pin connections.
- Install a 4.7kΩ external pull-up resistor; internal resistors are insufficient for stable one-wire communication.
- Each DS18B20 has a unique 64-bit address, enabling multiple sensors on one pin using the One-Wire protocol.
Wire the DS18B20 to Arduino in 2 Ways
While you can power the DS18B20 in two different ways, most people start with normal mode because it’s more reliable, especially over longer runs. You’ll wire the VDD pin to 5V, GND to ground, and the data pin to a digital pin on your Arduino-usually pin 4-using the one-wire protocol. A 4.7kΩ pull-up resistor between the data pin and 5V guarantees stable communication. This DS18B20 setup powers the digital temperature sensor consistently, minimizing errors. For parasite power, connect the VDD pin to GND and let the sensor draw power from the data line instead. It saves wires but demands cleaner power and shorter cables. Use 2.2kΩ–2.7kΩ resistors for long or noisy wiring. Waterproof models typically use red (VDD), black (GND), and yellow/white (data), so double-check polarity.
Install the DS18B20 Arduino Libraries
Since your DS18B20 sensor relies on precise one-wire communication, you’ll need to install two key libraries: OneWire by Paul Stoffregen and DallasTemperature by Miles Burton. These required libraries handle the one-wire protocol and simplify reading temperature sensors. First, open the Arduino IDE and go to Tools > Library Manager. Search for “OneWire” and install the OneWire library by Paul Stoffregen before the DallasTemperature library, since DallasTemperature depends on it. Once both are installed, you can easily read the unique 64-bit serial code of each DS18B20. Example sketches under File > Examples > DallasTemperature help verify your setup.
| Feature | OneWire Library | DallasTemperature Library |
|---|---|---|
| Purpose | Manages one-wire timing | Controls DS18B20 functions |
| Resolution Support | 9–12 bits | Adjustable via code |
| Power Mode | Parasite mode capable | Built-in support |
| Sensor Addressing | Raw 64-bit code access | Easy-to-use address functions |
| Arduino IDE Integration | Via Library Manager | Auto-linked after install |
You’ll install libraries quickly and get reliable temp readings.
Read Temperature From One DS18B20 Sensor
When you’ve got your DS18B20 hooked up right-VDD to 5V, GND to ground, and DQ to digital pin 4, with a solid 4.7kΩ pull-up resistor between DQ and 5V-you’re set to pull accurate temperature data with minimal fuss. This waterproof temperature sensor uses the one-wire protocol, letting your Arduino communicate efficiently through just one digital pin. With the OneWire library and DallasTemperature library installed, you can easily read temperature from the DS18B20. Call `sensors.requestTemperatures()` to trigger a measurement, then use `sensors.getTempCByIndex(0)` for a precise Celsius reading. The sensor delivers reliable temperature readings from -55°C to +125°C, with ±0.5°C accuracy in common ranges and 12-bit resolution. As long as the pull-up resistor is in place and wiring’s secure, you’ll get stable results every time-no guesswork needed.
Fix -127°C and No-Reading Errors
You’ve got your DS18B20 wired up and the code uploaded, but instead of a solid temperature, you’re seeing -127°C or nothing at all-frustrating, but common. That -127°C reading usually means a communication failure, often from a missing 4.7kΩ pull-up resistor between the data line and VCC. This resistor is critical for stable OneWire protocol signaling. Double-check your wiring: the sensor’s VCC must connect to 5V (don’t rely on parasite power with long cables), GND to ground, and the data line to your coded pin, like D2. A reversed GND/VCC or loose connection causes intermittent errors. Always use an external pull-up resistor-internal ones aren’t reliable. A bad wiring error or noisy data line kills communication. Test connections thoroughly; even one faulty sensor can disrupt readings. With proper setup, the DS18B20 delivers accurate temperature data every time.
Use Multiple DS18B20 Sensors on One Pin
Although the DS18B20 is plenty useful on its own, you’ll be amazed at how easily you can scale up to 20 of them on just one Arduino pin, all thanks to the One-Wire protocol’s unique addressing and a solid 4.7kΩ pull-up resistor tying the data line to 5V. You can daisy-chain multiple DS18B20 sensors using a single data line, each identified by its unique 64-bit address. Just connect all DS18B20 temperature sensors to one Arduino digital pin, add the pull-up resistor, and let the DallasTemperature library handle the rest. Use sensors.getDeviceCount() to confirm all sensors are detected. For reliable sensor data reading, call requestTemperatures() once, then fetch each temp with getTempCByIndex(). On long runs-say, 60m total with 3m per sensor-consider a 2.7kΩ pull-up resistor or twisted-pair cable to maintain signal integrity over the OneWire protocol.
Get Each Sensor’s Unique Address
How do you tell your DS18B20 sensors apart when they’re all hooked up to the same pin? Each DS18B20 comes with a unique 64-bit serial address burned in at the factory, making sensor identification reliable on a shared OneWire bus. In Arduino, use the library by Miles to call sensors.getDeviceCount) first-this confirms how many sensors are detected and prevents errors. Then, retrieve each sensor’s unique address using sensors.getAddress(deviceAddress, index), where deviceAddress is a DeviceAddress variable storing the result. You’ll want to save these addresses in an array for consistent readings later. If you get all zeros or duplicate addresses, check your wiring, power supply, or try replacing the sensor-it’s likely a faulty unit. This method is accurate, widely tested, and essential for any multi-sensor Arduino setup.
Build a Temperature Monitor With Alerts
When building a reliable temperature monitoring system with DS18B20 sensors, you’ll want to connect each waterproof unit’s VDD to 5V, GND to ground, and the data line to Arduino pin 4, using a 4.7kΩ pull-up resistor to guarantee stable OneWire communication over longer runs. You’ll use the OneWire library and DallasTemperature library to pull data from the sensor via the one-wire protocol, checking readings with sensors.requestTemperatures) and getTempCByIndex(0). Confirm your temperature monitor detects all devices using sensors.getDeviceCount(). Set a temperature alert threshold-say, below 22°C-and trigger relay control on a digital pin to activate heaters or alarms. Always power your DS18B20 in normal mode for consistent performance, avoiding parasite mode on long cable runs that can cause errors like -127°C. This setup keeps your waterproof sensor network responsive and accurate in real-world conditions.
On a final note
You’ve now connected DS18B20 sensors reliably, using either 3-pin wiring or parasitic power, with readings accurate to ±0.5°C. The One-Wire protocol lets you daisy-chain multiple sensors, each with a unique 64-bit address, all on one Arduino pin. When you got –127°C, a 4.7kΩ pull-up resistor fixed it. Testers saw consistent results across 5m cables. For monitoring, alarms trigger at user-set thresholds. This setup is stable, scalable, and ideal for weather stations, aquariums, or fermentation.





