Arduino Nano - Temperature Sensor - OLED
This tutorial instructs you how to use Arduino Nano to acquire the temperature from a DS18B20 one wire sensor and show it on an OLED display.
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 are unfamiliar with OLED and DS18B20 Temperature Sensor (pinout, how it works, how to program ...), the following tutorials can provide you with more information:
Wiring Diagram
- Wiring diagram using a breadboard.
This image is created using Fritzing. Click to enlarge image
- Wiring diagram using a terminal adapter (recommended).
This image is created using Fritzing. Click to enlarge image
We recommend buying a DS18B20 sensor along with its accompanying wiring adapter for a seamless setup. This adapter includes an integrated resistor, removing the need for an additional resistor in the wiring.
Arduino Nano Code - Temperature from DS18B20 Temperature Sensor and display it on OLED
Detailed Instructions
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “SSD1306” and locate the SSD1306 library by Adafruit.
- Then, press the Install button to complete the installation.
- You will be prompted to install some additional library dependencies.
- To install all of them, click the Install All button.
- Search for “Dallas”, and then locate the DallasTemperature library created by Miles Burton.
- Press the Install button to install the DallasTemperature library.
- You will be asked to install the dependency. Click Install All button to install OneWire library.
- Copy the code and open it with the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the Arduino Nano.
- Place the sensor in hot and cold water, or hold it in your hand.
- Check out the result on the OLED display.
※ NOTE THAT:
The code in question will center the text both horizontally and vertically on the OLED display.