Introduction: Temperature Probe DS18B20 With OLED Display

This project involves the DS18B20, a waterproof temperature probe with a module kit that can be controlled by an Arduino microcontroller. An OLED display is used to show the temperature measured.

Supplies

Items you need to prepare:
a Arduino UNO microcontroller with USB cable

a DS18B20 digital temperature sensor (probe) module kit (waterproof version). See its specifications here.

a 0.96 inch 128X64 OLED display module

a 4.7 kΩ (used as pull-up resistor)

some jumper wires and a mini breadboard

a mini screwdriver (to connect the 3 wires from the temperature probe to the temperature sensor module)

Step 1: DS18B20 Circuit Diagram

The above diagram shows the circuit connections for the digital temperature probe to the module to the Arduino board.

To set up the digital temperature sensor, I learnt much from these references:

  1. https://randomnerdtutorials.com/guide-for-ds18b20...
  2. https://randomnerdtutorials.com/guide-for-ds18b20...

Step 2: Connecting the Temperature Probe to the Module

Use the mini screwdriver to connect the 3 wires from the digital temperature probe to the module. The above diagram shows the correct connections from the temperature probe to the module and from the module to the Arduino microcontroller using 3 jumper wires:

Temperature sensor -> DS18B20 module -> Arduino micro-controller

  • black wire -> GND --> GND
  • red wire -> VCC --> 5 V
  • yellow wire -> DAT --> digital pin 4 (with a 4.7 kΩ pull-up resistor)

Step 3: Install 2 Libraries Into Arduino IDE for DS18B20

Connect the Arduino microcontroller to the laptop and check for connectivity:

Select Tools -> check Board: “Arduino/Genuino Uno” and check Port: “COM#”.

Install two libraries into Arduino IDE (Integrated Development Environment).

From the menu, select Sketch -> Include Library -> Manage Libraries

  1. Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.
  2. Search for “Dallas” and install the Dallas Temperature library by Miles Burton.

Step 4: Copy, Verify and Upload Sketch for DS18B20

Copy, verify and upload the sketch below for DS18B20:

/*********<br>  Rui Santos
  Complete project details at <a href="http://randomnerdtutorials.com" rel="nofollow"> <a href="http://randomnerdtutorials.com"> http://randomnerdtutorials.com </a> </a>  
  Based on the Dallas Temperature Library example
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);   	// initialize the Serial Monitor at a baud rate of 9600
// Start up the library
sensors.begin();      	// initialize the DS18B20 temperature sensor:
}
void loop(void){ 
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures(); 
Serial.print("Celsius temperature: ");  
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));   	// get and print the temperature in degree Celsius
delay(1000);
}

Step 5: Use Serial Monitor to Check Temperature Readings From DS18B20

Activate the serial monitor to show temperature readings in degrees Celsius (as shown above).

If you can see the temperature readings, the digital temperature probe is working as expected. Well done :-)

For calibration or to check accuracy, you may compare these readings with those taken by a normal alcohol thermometer.

Step 6: OLED Display Circuit Diagram

To test the OLED display separately, set up the circuit as shown above.

Connect the OLED to the Arduino microcontroller using in the following way:

OLED display -> Arduino micro-controller

  • GND --> GND
  • VCC --> 5 V
  • SDA (data) --> A4 (analog pin 4)
  • SCL (clock) --> A5 (analog pin 5)

To set up the OLED display, I learnt much from these references:

  1. https://randomnerdtutorials.com/guide-for-oled-dis...
  2. https://www.instructables.com/id/OLED-I2C-DISPLAY-...

Refer to the above if there is a need to obtain the sketches:

  1. to use the Arduino I2C Address Locator
  2. to test the OLED display (ssd1306_128x64_i2c)

Step 7: Install 2 Libraries Into Arduino IDE for OLED Display

Connect the Arduino microcontroller to the laptop and check for connectivity:

Select Tools -> check Board: “Arduino/Genuino Uno” and check Port: “COM#”.

Install two libraries into Arduino IDE (Integrated Development Environment).

From the menu, install two libraries into Arduino IDE:

Select Sketch -> Include Library -> Manage Libraries

  1. Type “SSD1306” in the search box and install the SSD1306 library from Adafruit.
  2. Search for “GFX” in the search box and install the adafruit_GFX.h libraries.

Step 8: Copy, Verify and Upload Sketch for OLED Display

Copy, verify and upload the sketch below for OLED display to show a "Hello world!" message:

/* Starting with Arduino OLED coding<br> *  for " arduino oled i2c tutorial : 0.96" 128 X 32 for beginners"
 *  subscribe for more arduino Tuorials and Projects<a href="https://www.youtube.com/channel/UCM6rbuieQBBLFsxszWA85AQ?sub_confirmation=1">
https://www.youtube.com/channel/UCM6rbuieQBBLFsxs...</a>
 */
#include <SPI.h><br>#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4 
Adafruit_SSD1306 display(OLED_RESET);
void setup() 
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
}
void loop() 
{
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello world!");  // can replace with text or reading from sensor
          			// or value from math function
  display.display();
}

If you can see the "Hello world!" message on the OLED display, this part is done successfully. Good job :-)

Step 9: Finally to Combine the DS18B20 and OLED Display

Finally, you are ready to combine both the DS18B20 digital temperature probe with the OLED display.

For the combined circuit:

  • Connect the OLED display to the circuit for the DS18B20 digital temperature probe, taking note of the wire connections needed for OLED (GND and 5 V).

For the combined sketch:

  • Add the following sketch to the last section "void loop" of the original sketch for DS18B20.
  • The variable T is used to represent the temperature obtained from the temperature probe.
float T = sensors.getTempCByIndex(0);  // let T be temperature in degC from sensor
					// floating-point number, with a decimal point  
display.setTextSize(1);<br>display.setTextColor(WHITE); display.setCursor(0,0);
display.println("Temperature: ");   // display temperature in deg Celsius
display.print(T);
display.print(" ");
display.cp437(true);    	// code page 437
display.write(167);     	// character 167 is degree
display.println("C");
display.display();		// for the changes to make effect

Step 10: The Final Device

If all is ok, you would see the temperature reading of the probe shown on the OLED display.

Test your new digital thermometer with temperature changes such as water, ice or just hold the probe with your hand. Have fun!