Arduino MKR WiFi 1010 - Temperature Sensor

by DIYables in Circuits > Arduino

23 Views, 0 Favorites, 0 Comments

Arduino MKR WiFi 1010 - Temperature Sensor

This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-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 perfec

Supplies

What It Is

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.

Wiring

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

Code

arduino-mkr-wifi-1010-temperature-sensor.ino - the sketch from the tutorial, unchanged.

/*
* 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 // Arduino MKR WiFi 1010 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);
}

Full Tutorial

The complete tutorial, wiring diagram and code explanation: https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-temperature-sensor