Arduino - Temperature Sensor - LED Matrix

In this tutorial, we are going to learn how to program Arduino to read the temperature from DS18B20 one wire sensor and display it on an LED Matrix.

Hardware Required

1×Arduino Uno
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×FC-16 LED Matrix 32x8
1×FC-16 LED Matrix 8x8
1×DS18B20 Temperature Sensor (WITH Adapter)
1×Breadboard
1×Jumper Wires
1×(Optional) DC Power Jack
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Recommended) Breadboard Shield For Arduino Uno
1×(Recommended) Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

Buy Note: Many DS18B20 sensors on the market are low-quality. We highly recommend buying the sensor from the DIYables brand using the link above. We tested it, and it worked well.

About LED Matrix and DS18B20 Temperature Sensor

If you do not know about LED Matrix and DS18B20 Temperature Sensor (pinout, how it works, how to program ...), learn about them in the following tutorials:

Wiring Diagram

Arduino DS18B20 Temperature Sensor LED Matrix Wiring Diagram

This image is created using Fritzing. Click to enlarge image

We suggest purchasing a DS18B20 sensor that comes with a wiring adapter for easy connection. The adapter has a built-in resistor, eliminating the need for a separate one in the wiring.

Arduino Code - Temperature from DS18B20 Temperature Sensor and display it on LED Matrix

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-temperature-sensor-led-matrix */ #include <OneWire.h> #include <DallasTemperature.h> #include <DIYables_LED_Matrix.h> #define SENSOR_PIN 2 // DS18B20 data pin OneWire oneWire(SENSOR_PIN); DallasTemperature tempSensor(&oneWire); float tempCelsius; float tempFahrenheit; #define CS_PIN 9 // Chip Select pin for MAX7219 #define NUM_MATRICES 4 // Number of cascaded MAX7219 modules #define SPACING 2 // Spacing between characters DIYables_Max7219 display(CS_PIN, NUM_MATRICES); void setup() { Serial.begin(9600); delay(500); // Initialize temperature sensor tempSensor.begin(); // Initialize the LED matrix display display.setBrightness(1); // Brightness level: 0 to 15 display.clear(); display.show(); } void loop() { // Request and read the temperature tempSensor.requestTemperatures(); tempCelsius = tempSensor.getTempCByIndex(0); tempFahrenheit = (tempCelsius * 9.0 / 5.0) + 32.0; // Print temperature to Serial Monitor Serial.print("Temperature: "); Serial.print(tempCelsius); Serial.print("°C ~ "); Serial.print(tempFahrenheit); Serial.println("°F"); // Clear the display, then print temperature (Celsius) display.clear(); // Convert to C-style string before passing to the print() function String tempStr = String(tempCelsius, 1) + "°C"; // 1 decimal place display.print(tempStr.c_str(), SPACING, 0); display.show(); delay(2000); // Wait 2 seconds before taking the next reading }

Quick Steps

  • Open Arduino IDE on your PC.
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search “DIYables-LED-Matrix”, then find the LED Matrix library by DIYables
  • Click Install button to install the library.
Arduino LED Matrix library
  • Search “DallasTemperature”, then find the DallasTemperature library by Miles Burton.
  • Click Install button to install DallasTemperature library.
Arduino Dallas Temperature library
  • You will be asked to install the library dependency
  • Click Install All button to install OneWire library.
Arduino onewire library
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Put the sensor on hot and cold water, or grasp the sensor by your hand
  • See the result on LED Matrix

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES