Hello friends! Today we will connect a DS18B20 temperature sensor to an Arduino Uno and display its reading in the Serial Monitor and on a 20 x 4 LCD. This is a useful first project when you want a digital temperature measurement without building an analog amplifier or calculating an ADC reference voltage.

The original project used the Dallas 18B20 name and demonstrated the result on real hardware. We will retain those photographs and the demonstration video while making the wiring, library installation and measurement handling clearer. In particular, we need to distinguish a sensor's resolution from its accuracy and explain why its power connection matters.

We will begin with one externally powered sensor on Arduino pin D2. Once that works reliably, the same data line can support several individually addressed sensors. If you are following the simulation series, you can also read How to Use 18B20 in Proteus ISIS.

Figure: DS18B20 temperature sensor and Arduino project overview.

Understand the DS18B20 Before Connecting It

The DS18B20 measures its own temperature and returns a digital result through a 1-Wire interface. The name describes the communication signal, not the total number of connections in every circuit. Our arrangement uses a data conductor, ground and a separate supply conductor.

The manufacturer's DS18B20 datasheet specifies a measurement range of -55 to +125 degrees Celsius, with an accuracy specification of ±0.5 degrees Celsius over -10 to +85 degrees Celsius. Its programmable resolution is 9 to 12 bits. These are different specifications: small numerical steps do not prove that the indicated temperature is equally close to the true temperature.

Resolution and maximum conversion time
SettingTemperature stepConversion time
9 bits0.5 degrees Celsius93.75 ms
10 bits0.25 degrees Celsius187.5 ms
11 bits0.125 degrees Celsius375 ms
12 bits0.0625 degrees Celsius750 ms

For example, 23.5625 degrees Celsius is a valid 12-bit step. Printing it with four decimal places reveals the numerical representation, but does not make this a thermometer accurate to 0.0001 degrees. We will display two decimal places because they are readable and still show changes smaller than one degree.

Parts and Libraries Required

  • Arduino Uno and a suitable USB cable.
  • One DS18B20 with an identified package pinout.
  • A 4.7 kilohm pull-up resistor for the short demonstration bus.
  • A compatible 20 x 4 parallel character LCD.
  • A contrast potentiometer and any backlight current limiting required by the LCD module.
  • Breadboard, short connecting wires and the Arduino IDE.

We use OneWire for bus communication, DallasTemperature for temperature-specific operations, and LiquidCrystal for the parallel LCD. The temperature library builds on OneWire; installing only one of these two libraries will leave the sketch incomplete.

The original downloadable library archives remain below for readers reproducing the historical project. Their contents may be older than the maintained packages. Keep track of which copy you install so that duplicate libraries do not silently select a different version during compilation.

Download One Wire Library Download Dallas Temperature Library

  1. Open the Arduino IDE's Library Manager and locate OneWire and DallasTemperature.
  2. Check the package identity and install both, including required dependencies offered by the IDE.
  3. For a manually downloaded archive, extract it if necessary and place the actual library folder in your sketchbook's libraries directory. An outer download folder is not the library itself.
  4. Restart the IDE if the manually installed examples are not listed.
  5. Open a DallasTemperature example to confirm that its include files are available before adding the LCD.

The DallasTemperature project documents the maintained implementation. Our sketch uses its established requestTemperatures, getTempCByIndex and setResolution interfaces. The error constant DEVICE_DISCONNECTED_C lets us distinguish a failed reading from a legitimate negative temperature.

Connect the Sensor in Three-Wire Mode

Identify GND, DQ and VDD from the documentation for your exact sensor. The common TO-92 DS18B20 assigns pins 1, 2 and 3 to those functions respectively, but the drawing's viewing direction matters. A packaged waterproof probe may use different wire colors, so colors alone are not a reliable pinout.

Externally powered sensor wiring for this Uno example
Sensor connectionDestinationPurpose
GNDArduino GNDShared electrical reference
DQArduino D21-Wire communication
VDDArduino 5 VSensor supply
4.7 kilohm resistorBetween DQ and 5 VData-line pull-up

The resistor holds the bus high when neither device is pulling it low. It is not a series resistor in the D2 signal wire. With a 5 V supply, its approximate low-state current is 5 / 4700 = 1.06 mA. That calculation describes the pull-up path, not the total current taken by the Arduino and LCD.

Figure: Historical DS18B20 parasite-power wiring reference.

Why the older drawing grounds VDD

The original instructions grounded both sensor pin 1 and pin 3. That selects parasite-power operation, where the sensor obtains energy from the data line. It is a supported operating arrangement, but conversion power requires more care than merely adding a weak pull-up resistor.

The datasheet explains the strong pull-up required during conversion in parasite mode. A weak resistor can communicate successfully yet fail to provide sufficient conversion current. For this revised beginner example, follow the three-wire table above and connect VDD to the supply. Do not combine its supply connection with the older drawing's grounded VDD.

Keep the first circuit short and simple. Longer cables add capacitance and alter the bus waveform. A resistor value that works on a breadboard is not a universal guarantee for a distributed installation with branches, connectors and several sensors.

Connect the 20 x 4 LCD

The original hardware uses a parallel character display. The constructor LiquidCrystal lcd(12, 11, 7, 6, 5, 4) lists RS, Enable, D4, D5, D6 and D7 in that order. These are the LCD's signal names; LCD D4 connects to Arduino D7 in this example.

LCD connections used by the sketch
LCD signalArduino connection
RSD12
EnableD11
Data D4D7
Data D5D6
Data D6D5
Data D7D4
R/WGND for write-only operation

Connect the display's supply and contrast terminals according to its module documentation. Adjusting the contrast is often necessary before any characters become visible. The backlight terminals are separate from the logic interface, and their current limiting depends on the module.

Figure: Parallel 20x4 LCD used in the temperature project.

If LCD wiring is new to you, review Circuit Designing of LCD with Arduino in Proteus ISIS. An LCD with an I2C backpack needs a different interface library and wiring; it cannot use the parallel constructor unchanged.

Figure: DS18B20 sensor in the original hardware setup.

Arduino Code for Temperature and Error Display

Upload the following sketch after selecting the correct board and port. It assumes one sensor, a parallel 20 x 4 LCD, and the wiring above. The conversion request waits for completion, which keeps the first example easy to follow.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

const byte ONE_WIRE_BUS = 2;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void clearRow(byte row) {
  lcd.setCursor(0, row);
  lcd.print("                    ");
  lcd.setCursor(0, row);
}

void setup() {
  Serial.begin(9600);
  sensors.begin();
  sensors.setResolution(12);
  sensors.setWaitForConversion(true);
  lcd.begin(20, 4);
  lcd.print("DS18B20 temperature");
  Serial.println("DS18B20 temperature monitor");
}

void loop() {
  sensors.requestTemperatures();
  const float temperatureC = sensors.getTempCByIndex(0);
  clearRow(1);
  clearRow(2);

  if (temperatureC == DEVICE_DISCONNECTED_C) {
    lcd.setCursor(0, 1);
    lcd.print("Sensor read error");
    lcd.setCursor(0, 2);
    lcd.print("Check power and DQ");
    Serial.println("ERROR: no valid temperature");
  } else {
    lcd.setCursor(0, 1);
    lcd.print("Temperature:");
    lcd.setCursor(0, 2);
    lcd.print(temperatureC, 2);
    lcd.print(" C");
    Serial.print("Temperature: ");
    Serial.print(temperatureC, 2);
    Serial.println(" C");
  }
  delay(1000);
}

We read the temperature once and reuse that value for both outputs. This keeps the LCD and Serial Monitor tied to the same acquisition. The row-clearing function removes old characters before printing a shorter value or error message.

For example, replacing 100.00 C with 9.00 C without clearing or padding can leave trailing characters on a character LCD. Clearing only the changing rows avoids repeatedly resetting the entire display and its heading.

The code is a revised instructional example. The preserved photographs and video document the original project; they are not evidence that this revised sketch has been freshly run on the pictured hardware.

Run the Project and Interpret the Reading

  1. Check the power rails and sensor orientation before applying power.
  2. Upload the sketch and open the Serial Monitor at 9600 baud.
  3. Allow the first conversion to finish before expecting a temperature.
  4. Confirm that the LCD and serial output show the same numerical reading.
  5. Warm the sensor gently with a finger and watch the value change gradually.
  6. Disconnect the sensor's data connection temporarily and confirm that the application reports an error rather than treating it as a useful temperature.

Figure: Complete Arduino temperature display hardware.

The historical LCD photograph below displays approximately 23.56 degrees Celsius. That is an example reading from the original setup, not a target value for every room. Your surroundings, sensor placement and time allowed for thermal equilibrium determine your result.

Figure: Original LCD temperature reading of 23.56 degrees Celsius.

Sensor response is not instantaneous. A waterproof metal probe usually has a different thermal response from a bare plastic package. Touching the leads, placing the sensor near a regulator, or exposing it to a draft can change what it measures.

Useful Calculations and Timing

Convert Celsius to Fahrenheit

The conversion is TF = 1.8 × TC + 32. For the photographed 23.56 degrees Celsius, this gives 74.408 degrees Fahrenheit, or 74.41 when displayed to two decimal places. Converting units does not improve the original measurement's accuracy.

Calculate the actual update interval

At 12-bit resolution, allow up to 750 ms for conversion. The sketch then waits another 1000 ms, so its update interval can approach 1.75 seconds plus communication and display overhead. The delay call alone does not define the complete sample period.

If you need approximately one-second updates, schedule conversions and display work with explicit elapsed-time checks. For a responsive interface, the library also supports separating conversion requests from later reads. You must still wait for conversion completion; removing the delay without replacing the timing logic does not make the sensor faster.

Interpret a temperature difference

Suppose two sensors report 24.00 and 24.50 degrees Celsius. Their difference is 0.50 degrees, but individual measurement uncertainty and placement both contribute. Compare them side by side under stable conditions before assuming that a small difference represents a real gradient.

Add More Sensors on the Same Data Line

Each DS18B20 has a unique ROM identifier. Multiple devices can share DQ and ground while the controller selects the intended address. With external power, connect their VDD terminals to an appropriate supply and consider the total wiring and current requirements.

The example uses index zero because there is only one sensor. In a multi-sensor project, do not assume that enumeration order permanently identifies the tank, room or outdoor probe. Record each device address and associate that address with a physical label.

Requesting a conversion for the bus and then reading each addressed sensor can be more efficient than waiting through a separate full conversion for every device. Keep a validity flag and last-successful timestamp for each sensor, because one disconnected probe should not make another probe's stale value appear current.

Troubleshooting and Project Review

Common symptoms and useful checks
SymptomWhat to check
Sensor error or -127 in older codePower, common ground, DQ pin, pull-up and library error handling
Repeated 85 degrees immediately after startupWhether a real conversion completed and the supply remained stable
LCD backlight but no charactersContrast, RS and Enable wiring, data order and initialization
Extra characters after a valueOverwrite the complete field or clear the changing row
Readings fail when cable length increasesBus capacitance, topology, connectors, supply drop and signal quality
Unexpectedly slow updatesConversion time plus every deliberate delay and display operation

The temperature register's power-on value is 85 degrees Celsius, so repeated startup readings deserve investigation. However, 85 degrees is also a legitimate physical temperature. Do not reject every occurrence unconditionally; establish whether the reading follows a completed conversion.

For a thermostat, handle a failed or stale measurement explicitly before deciding whether to drive a heater. Use separate switch-on and switch-off thresholds to avoid rapid output chatter. A display demonstration alone is not a complete temperature-control system.

When documenting a comparison against another thermometer, record both readings, their positions and the settling time. Comparing a probe inside a warm enclosure with a reference outside it measures placement differences as well as sensor error. Consistent test conditions make your observations useful to another reader.

Make the Measurement Useful in a Larger Project

A number becomes useful when we also know where it came from and when it was acquired. For a simple log, store the sensor address or location name, the temperature, a timestamp and the result status. Keep missing measurements distinguishable from zero degrees Celsius.

Suppose a sensor normally updates every 1.75 seconds. If its last valid reading is ten seconds old, showing that number without a stale-data indication can mislead the reader. Choose an acceptable age from the needs of the application, then compare the current time with the last successful acquisition.

Separate communication tests from temperature tests

  1. First establish that the software can discover the sensor and repeatedly read it on short wires.
  2. Next check a stable room-temperature reading with the sensor away from the Arduino's warm components.
  3. Then introduce a gentle temperature change and observe the response over several samples.
  4. Finally add the intended cable, enclosure and mounting method, repeating the same observations.

This sequence gives each change an explanation. If communication becomes unreliable only after adding a cable, rewriting the LCD formatting is unlikely to address the cause. If communication stays reliable but the sensor responds slowly inside a metal tube, the thermal construction deserves attention.

Use filtering with a defined purpose

A moving average can make a displayed temperature steadier. For example, four valid readings of 23.50, 23.56, 23.56 and 23.62 degrees average to 23.56 degrees. However, collecting four readings at roughly 1.75-second intervals spans about 5.25 seconds between the first and last sample.

That history delays the display's response to a genuine change. A filter does not remove an unknown calibration offset, and a failed reading must not enter the average as -127. Keep the unfiltered value available while debugging so that smoothing does not hide intermittent faults.

Document any calibration correction

If a reliable reference shows a repeatable offset under controlled conditions, record the comparison before applying a correction. A one-point adjustment only aligns one operating point; it does not establish accuracy across the complete temperature range.

For example, adding 0.30 degrees to every reading changes 23.56 to 23.86. The arithmetic is straightforward, but the justification belongs in the measurement record: reference instrument, temperature, mounting, settling time and observed repeatability. Avoid choosing an offset simply because two unrelated room displays disagree.

Frequently Asked Questions

Does 1-Wire mean that the sensor needs only one connection?

No. It refers to the data interface. A common ground is still necessary, and this tutorial also provides a separate VDD connection.

Can I use a waterproof DS18B20 probe?

Yes, provided its actual sensor, supply requirements and conductor assignments match the circuit. Check the supplier's wiring information instead of guessing from insulation colors.

Why does the displayed temperature differ from a room thermometer?

Consider placement, settling time, airflow, heating from nearby electronics and both instruments' accuracy. Additional decimal places do not resolve those differences.

Can I use a 16 x 2 LCD instead?

The parallel interface can be similar, but change lcd.begin to the actual dimensions and rewrite the row positions and text lengths. Our code writes row two, which does not exist on a two-row display.

Should every negative temperature be treated as a failure?

No. Negative Celsius temperatures are valid within the sensor's specified range. Compare against the library's explicit error indication rather than rejecting values below zero.