What Do You Need to Make a DIY Arduino Digital Thermometer?
An Arduino Board
You can use just about any Arduino with a 5V output for this project. We’re using an Arduino Pro Micro so that our finished thermometer is compact, but you can use a larger board like an Arduino Uno if you would like to avoid soldering for this project.
DS18B20 Temperature Probe
DS18B20 temperature sensors can be found as small stand-alone sensors, PCBs with sensors attached, or as waterproof probes on long wires. We chose the latter, as this enables us to use our thermometer inside a fish tank, but you can pick any variant of the DS18B20 temperature sensor. Unlike other types of temperature sensors, DS18B20s provide a direct-to-digital signal to your Arduino, rather than the analog signals that come from options like LM35 temperature sensors.
An OLED/LCD Screen
The display you choose for your thermometer will have a big impact on the finished product. We picked a 1.3-inch I2C-compatible monochrome white OLED display for our thermometer, but you can choose whatever you like as long as it supports I2C.
Additional Small Parts
4. 7K (kiloohm) resistor 28 to 22 AWG silicone/PVC insulated wire A breadboard (optional for those who do not wish to solder)
Wiring Your DIY Thermometer
The wiring for this project is far simpler than you might imagine. Using the circuit diagram above, you can create your own DIY digital thermometer with little effort, but we’ve also broken the diagram down below to make it easier to follow.
Wiring the DS18B20 Temperature Probe
Wiring your DS18B20 temperature probe correctly is vital to this project, and you need to make sure that you use the 4.7K resistor we mentioned earlier or your probe isn’t going to work properly. The probe comes with three wires: Ground (usually black), VCC (usually red), and Data.
VCC connects to a 5V pin on your Arduino Ground connects to a GND pin on your Arduino Data can connect to any digital pin on your Arduino (we picked digital pin 15) The Data and VCC wires also need to be connected to one another with a 4. 7K resistor
Wiring the I2C OLED Display
As we are using an I2C connection between our OLED display and our Arduino, we only have to connect four wires before we can start using our display: VCC, Ground, SDA, and SCL. Just about every modern Arduino has SDA and SCL pins built-in, providing the ability to connect up to 128 unique I2C components to a single board.
Our Arduino Pro Micro has SDA on digital pin 2 and SCL on digital pin 3, but you may need to look for a pinout diagram of the specific board you have chosen before you start.
VCC connects to a 5V pin on your Arduino Ground connects to a GND pin on your Arduino SDA connects to the SDA pin on your Arduino SCL connects to the SCL pin on your Arduino
Testing Your Circuit
It’s crucial that you test the circuit you have made before you start writing the final code for it, but you can use the example projects that come with the libraries discussed below to test the circuit you have made.
Coding Your Temperature Sensor & OLED Display
Coding your DIY digital thermometer is trickier than wiring it up, but the Arduino IDE can be used for this to make it easier.
Choosing the Correct Libraries
OLED Display Library: We are using the Adafruit_SH1106. h library for our display, as this is the library that it was designed to work with. Other OLED displays may use their own libraries, like the Adafruit_SSD1306. h library, and you can usually find out which one you need from the product page you got your display from. DS18B20 Temperature Probe: We need two libraries for our temperature probe. DallasTemperature. h is used to collect temperature data, and OneWire. h to make our single-wire connection possible.
Once these libraries have been installed and included in your project, your code should look something like the snippet below. Note that we have also included code to set the pins for our components.
Building the Functions
void setup: We are using the standard setup function to initialize both our display and our temperature probe. void loop: Our standard loop function will only be used to call our Display function. void Display: We have added a Display function that calls our Temp function and provides information to our display. int Temp: Our Temp function is used to get a temperature reading for our Display function.
Once complete, this should look like the snippet below.
Coding the OLED Display
Before we can add code to our Display function, we need to make sure the OLED panel is initialized in our void setup function. First, we use a display.begin command to get the display started, followed by a display.clearDisplay command to make sure the display is clear.
From here, we can add code to our Display function. This starts with another display.clearDisplay command, before declaring a new integer variable with a value that calls the Temp function (we will cover this later). We are then able to use this variable to display the temperature on the display using the following code.
Coding the DS18B20 Temperature Probe
Like our display, our temperature probe also needs setup code to initialize the component.
Next, it’s time to program the probe itself, and we need to add code to our Temp function. First, we will request the temperature from our probe, followed by recording the result as a float variable and converting it into an integer. If this process is successful, the temperature is returned to the Display function.
Finishing Up
Finally, we just need to tell our main loop function to call our Display function with each cycle of the code, leaving us with a project that looks like this.
Building a DIY Digital Thermometer
This project should be fun and informative, while also giving you the chance to make a practical item. We have designed this code to be as simple as possible, but you can use it as the foundation for a more complicated project as you learn.