Arduino Nano 33 IoT - Temperature Sensor - OLED
This guide teaches you how to get the temperature reading from a DS18B20 sensor that uses one wire and display it on an OLED screen.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Many DS18B20 sensors available in the market are unreliable. We strongly recommend buying the sensor from the DIYables brand using the link provided above. We tested it, and it worked reliably.
Overview of OLED and DS18B20 Temperature Sensor
If you're new to using the OLED, DS18B20 Temperature Sensor, and Arduino Nano 33 IoT, please check out these tutorials:
These tutorials explain how OLED and DS18B20 Temperature Sensor work, their pinouts, how to connect them to the Arduino Nano 33 IoT, and how to program Arduino Nano 33 IoT to work with the OLED and DS18B20 Temperature Sensor.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
We recommend buying a DS18B20 sensor with a wiring adapter for a simple connection. The adapter already has a built-in resistor, so you don't have to add one separately.
Arduino Nano 33 IoT Code - Temperature from DS18B20 Temperature Sensor and display it on OLED
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Click on the Libraries icon on the left side of the Arduino IDE.
- Type SSD1306 in the search box and look for the SSD1306 library by Adafruit.
- Click the Install button to add the library.

- You may be asked to install some extra libraries.
- Click the Install All button to install all the libraries.

- Type DallasTemperature in the search box, then find the library named DallasTemperature by Miles Burton.
- Click the Install button to add the DallasTemperature library.

- You might be asked to add a needed tool. Click the Install All button to add the OneWire library.

- Copy the code above and open it using the Arduino IDE.
- Click the Upload button in the Arduino IDE to transfer the code to the Arduino Nano 33 IoT.
- Place the sensor in hot and cold water, or hold the sensor in your hand.
- Check the results on the OLED screen.
※ NOTE THAT:
This code automatically centers the text on the OLED display from side to side and from top to bottom.