Arduino MKR WiFi 1010 - Temperature Sensor

Arduino MKR WiFi 1010 DS18B20 Temperature Sensor

Welcome to your complete guide on using a temperature sensor with the Arduino MKR WiFi 1010! Temperature monitoring is one of the most practical skills in electronics and IoT projects. In this comprehensive tutorial, you'll learn how to connect a DS18B20 temperature sensor to your Arduino MKR WiFi 1010 board and read accurate temperature measurements in both Celsius and Fahrenheit. The Arduino MKR WiFi 1010 is perfect for temperature sensing projects because of its compact size, built-in WiFi connectivity, and reliable analog/digital input capabilities. Whether you're creating a weather station, smart home automation, greenhouse monitor, or industrial temperature logger, the Arduino MKR WiFi 1010 with DS18B20 sensor provides accurate and dependable temperature readings. This tutorial will guide you through wiring the temperature sensor to your Arduino MKR WiFi 1010, installing the required libraries, programming your board step-by-step, and understanding how one-wire digital temperature sensors work. By the end of this tutorial, you'll have a fully functional temperature monitoring system using the Arduino MKR WiFi 1010 and DS18B20 sensor, displaying real-time temperature readings on the Serial Monitor, with skills you can apply to countless temperature-sensing projects.

What You'll Learn

Real-World Applications

Ready to start measuring temperature with your Arduino MKR WiFi 1010? Let's begin building your temperature sensing project!

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×DS18B20 Temperature Sensor (WITH Adapter)
1×DS18B20 Temperature Sensor (WITHOUT Adapter)
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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 DS18B20 Temperature Sensor

The DS18B20 is a digital temperature sensor that measures temperature accurately from -55°C to +125°C. It uses a special communication method called the 1-Wire protocol, which means it can send digital temperature data using just one wire! This makes wiring simple and allows you to connect multiple sensors to the same pin if needed.

DS18B20 Temperature Sensor Pinout

The DS18B20 has three pins:

  • GND pin: Connect to ground (0V)
  • VCC pin: Connect to power (5V or 3.3V)
  • DATA pin: Connect to any digital pin on your Arduino MKR WiFi 1010 for sending temperature data
DS18B20 temperature sensor Pinout

The DS18B20 comes in two versions:

  • TO-92 package: Looks like a small transistor with three legs
  • Waterproof probe: Sealed in a stainless steel tube (recommended for this tutorial)

Important Note: The DS18B20 requires a 4.7kΩ pull-up resistor between the DATA and VCC pins. To make your life easier, we recommend buying a DS18B20 sensor with a wiring adapter that already includes this resistor built-in. This eliminates the need for additional components and simplifies your wiring!

Wiring Diagram

Connect your DS18B20 temperature sensor to the Arduino MKR WiFi 1010 as shown below:

Option 1: Using a breadboard

The wiring diagram between Arduino MKR WiFi 1010 Temperature Sensor

This image is created using Fritzing. Click to enlarge image

Option 2: Using a sensor with adapter (Recommended!)

The wiring diagram between Arduino MKR WiFi 1010 DS18B20

This image is created using Fritzing. Click to enlarge image

Pro Tip: Save yourself time and hassle by getting a DS18B20 sensor with a wiring adapter. The adapter includes the required pull-up resistor, making your wiring much simpler and more reliable!

Arduino MKR WiFi 1010 Code

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-temperature-sensor */ #include <OneWire.h> #include <DallasTemperature.h> #define SENSOR_PIN 2 // The Arduino Nano 33 IoT pin D2 connected to DS18B20 sensor's DATA pin OneWire oneWire(SENSOR_PIN); DallasTemperature DS18B20(&oneWire); float temperature_C; // temperature in Celsius float temperature_F; // temperature in Fahrenheit void setup() { Serial.begin(9600); // Initialize the Serial to communicate with the Serial Monitor. DS18B20.begin(); // initialize the DS18B20 sensor } void loop() { DS18B20.requestTemperatures(); // send the command to get temperatures temperature_C = DS18B20.getTempCByIndex(0); // read temperature in °C temperature_F = temperature_C * 9 / 5 + 32; // convert °C to °F Serial.print("Temperature: "); Serial.print(temperature_C); // print the temperature in °C Serial.print("°C"); Serial.print(" ~ "); // separator between °C and °F Serial.print(temperature_F); // print the temperature in °F Serial.println("°F"); delay(500); }

Detailed Instructions

New to Arduino MKR WiFi 1010? Complete our Getting Started with Arduino MKR WiFi 1010 tutorial first to set up your development environment.

  • Wire the components according to the diagram above
  • Connect the Arduino MKR WiFi 1010 to your computer via USB cable
  • Open Arduino IDE on your computer
  • Select the correct board and COM port
  • Click the Library Manager icon, search for DallasTemperature, and install it
Arduino MKR WiFi 1010 Dallas Temperature library
  • When prompted, click Install All to add the OneWire library dependency
Arduino MKR WiFi 1010 onewire library
  • Copy the code and upload it to your board
  • Touch the sensor with your hand or place it in hot/cold water to change temperature
  • Open the Serial Monitor to view temperature readings:
COM6
Send
Temperature: 26.31°C ~ 79.36°F Temperature: 26.44°C ~ 79.59°F Temperature: 26.50°C ~ 79.70°F Temperature: 26.56°C ~ 79.81°F Temperature: 27.06°C ~ 80.71°F Temperature: 27.75°C ~ 81.95°F Temperature: 28.37°C ~ 83.07°F Temperature: 29.00°C ~ 84.20°F Temperature: 29.56°C ~ 85.21°F Temperature: 30.00°C ~ 86.00°F Temperature: 30.31°C ~ 86.56°F Temperature: 30.62°C ~ 87.12°F Temperature: 30.87°C ~ 87.57°F
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Challenge Yourself

Ready to take your temperature sensing skills further? Try these exciting projects:

  • Temperature Logger: Save temperature readings to an SD card and create temperature graphs over time
  • WiFi Temperature Monitor: Send temperature data to your phone or computer using the MKR WiFi 1010's wireless capability
  • Multi-Sensor Network: Connect multiple DS18B20 sensors to one pin and monitor temperatures in different rooms
  • Temperature Alarm: Make an LED flash and a buzzer sound when temperature goes above or below set thresholds
  • Thermostat Controller: Build a smart thermostat that automatically controls a heater or fan based on temperature
  • Aquarium Temperature Guardian: Create an automatic temperature control system for fish tanks with alert notifications
  • Temperature vs. Time Plotter: Display real-time temperature graphs on a TFT screen or send data to a plotting application

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!