BeginnerSensors

DS18B20 Digital Thermometer

Read a digital one-wire temperature sensor and print the result to the serial monitor.

Estimated time: 45–60 minutes · Skills: Digital buses, pull-up resistors, Arduino libraries

Parts from the database

Other supplies

Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.

Connections

  1. With the flat face and leads toward you, confirm the exact sensor package pinout in its datasheet before wiring.
  2. For the common TO-92 DS18B20, connect GND to ground, VDD to 5 V and DQ to D2.
  3. Add a 4.7 kΩ pull-up from DQ to VDD. Do not rely on the MCU's internal pull-up for this bus.

Build steps

  1. Install OneWire and DallasTemperature libraries.
  2. Wire the sensor and pull-up resistor with power disconnected.
  3. Upload the sketch and view output at 9600 baud.
  4. Warm the sensor gently between fingers and verify that readings rise gradually.

Software and firmware setup

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(2); DallasTemperature sensors(&oneWire);
void setup(){ Serial.begin(9600); sensors.begin(); }
void loop(){ sensors.requestTemperatures(); float c=sensors.getTempCByIndex(0);
  if(c==DEVICE_DISCONNECTED_C) Serial.println("Sensor not found");
  else Serial.printf("%.2f C\n",c); delay(1000); }

Review the pin assignments in the sketch against the wiring table before uploading.

Test your build

A detected sensor should return a plausible room temperature. Give it time to reach equilibrium; touching it changes its temperature slowly.

Troubleshooting

  • If the library reports -127 °C, check the pin order and 4.7 kΩ pull-up.
  • Long leads may need a stronger bus layout and careful grounding.
  • For a waterproof probe, verify its cable colors with the seller's wiring diagram; colors are not universal.

Safety and limitations

Use only low voltage. A waterproof probe is not automatically food-safe or rated for immersion in every liquid.

Manufacturer and platform documentation

Community Notes for This Project

These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.

Set up the comments service to load community notes.

Share a tip or question about this build

← Browse all projects