Build a Simple Digital Thermometer with Display

Difficulty Level: Beginner to Intermediate

This project demonstrates how to build a simple digital thermometer using a DS18B20 temperature sensor and a 16x2 LCD display with Arduino.

Components Required

Wiring Diagram

Follow these steps for wiring the components:

For the DS18B20 Sensor

For the LCD Display (I2C version)

Code Explanation

In this project, the DS18B20 sensor measures the temperature and sends the data to the Arduino, which displays the temperature in Celsius on the 16x2 LCD display.

Libraries Used

Key Functions

Arduino Code

Below is the code to run the digital thermometer:


#include 
#include 
#include 
#include 

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

// Initialize the LCD with I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  // Start the LCD and set it up to display text
  lcd.begin();
  lcd.backlight();
  
  // Start the serial communication for debugging (optional)
  Serial.begin(9600);

  // Start up the temperature sensor library
  sensors.begin();
}

void loop() {
  // Request temperatures from DS18B20
  sensors.requestTemperatures();
  
  // Get temperature in Celsius
  float temperatureC = sensors.getTempCByIndex(0);
  
  // Display temperature on the LCD
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperatureC);
  lcd.print(" C");

  // Debugging output to Serial Monitor (optional)
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" C");

  // Delay between updates
  delay(1000);
}
            

Upload and Test

  1. Connect your Arduino to your PC using a USB cable.
  2. Open the Arduino IDE, copy and paste the code above.
  3. Install the required libraries: OneWire.h, DallasTemperature.h, and LiquidCrystal_I2C.h from the Library Manager.
  4. Select your Arduino board and port from the Tools menu.
  5. Upload the code to your Arduino.
  6. The temperature should now be displayed on the 16x2 LCD in real-time.

Conclusion

This project allows you to create a simple digital thermometer using the DS18B20 temperature sensor and display the temperature on an LCD screen. You also learned about I2C communication with an LCD, using temperature sensor libraries, and basic Arduino coding techniques.