Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The DS18B20 is a digital temperature sensor popular for its accuracy and simplicity. It communicates over a 1-Wire bus, making it easy to interface with microcontrollers like Arduino. This article will guide you through setting up the DS18B20 sensor with an Arduino to measure temperature. Understanding how to use this sensor is crucial for projects involving environmental monitoring, home automation, and other applications requiring precise temperature readings.
Project: In this project, we will create a simple temperature monitoring system using the DS18B20 sensor and an Arduino. The system will read the temperature from the DS18B20 sensor and display it on the Serial Monitor of the Arduino IDE. This project aims to familiarize you with interfacing the DS18B20 sensor with Arduino, reading temperature data, and displaying it.
Components List:
Examples:
// Include the necessary libraries
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void) {
// Start serial communication for debugging
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void) {
// Request temperature readings from all devices on the bus
sensors.requestTemperatures();
// Fetch and print the temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Wait 1 second before repeating the loop
delay(1000);
}
Explanation:
OneWire
and DallasTemperature
libraries to handle communication with the DS18B20 sensor.Common Challenges:
OneWire
and DallasTemperature
libraries are installed in the Arduino IDE.