-->
Notification texts go here Contact Us pelacakan

DS18B20 Temperature Sensor with Arduino


The DS18B20 temperature sensor is a digital sensor commonly used with Arduino microcontrollers to measure temperature accurately. With a one-wire interface, it simplifies wiring and allows multiple sensors to be connected in a series. By interfacing the DS18B20 with Arduino, enthusiasts can easily integrate temperature sensing into their projects. The sensor's precision, ease of use, and compatibility make it a popular choice for applications such as home automation, weather monitoring, and industrial control when coupled with Arduino-based projects.


The DS18B20 is a popular digital temperature sensor that communicates over the One-Wire protocol. Here's a simple guide to connect and use the DS18B20 temperature sensor with an Arduino:

Components Needed:

1. Arduino board (e.g., Arduino Uno)

2. DS18B20 temperature sensor

3. 4.7kΩ resistor (for parasite power mode, optional)

4. Breadboard and jumper wires

Wiring:


1. DS18B20 to Arduino:

   - Connect the VCC pin of the DS18B20 to 5V on Arduino.

   - Connect the GND pin of the DS18B20 to GND on Arduino.

   - Connect the data pin (DQ or DIO) of the DS18B20 to a digital pin on Arduino (e.g., D2).


2. Parasite Power Mode (Optional):

   - If using parasite power mode, connect a 4.7kΩ resistor between the VCC and data pins of the DS18B20.

Arduino Code:

Here's a basic example using the OneWire and DallasTemperature libraries. Make sure to install these libraries via Arduino IDE Library Manager if not already installed:


#include <OneWire.h>

#include <DallasTemperature.h>

// Data wire is connected to pin 4 on Arduino

#define ONE_WIRE_BUS 2

// Create a OneWire instance to communicate with any OneWire devices

OneWire oneWire(ONE_WIRE_BUS);

// Pass OneWire reference to DallasTemperature library

DallasTemperature sensors(&oneWire);

void setup() {

  Serial.begin(9600);

  // Start the DS18B20 sensor

  sensors.begin();

}

void loop() {

  // Request temperature from all devices on the bus

  sensors.requestTemperatures();

  // Get temperature in Celsius for the first connected device

  float temperatureC = sensors.getTempCByIndex(0);

  // Check if temperature reading is valid

  if (temperatureC != DEVICE_DISCONNECTED_C) {

    // Print the temperature to the serial monitor

    Serial.print("Temperature: ");

    Serial.print(temperatureC);

    Serial.println(" °C");

  } else {

    Serial.println("Error reading temperature. Check connections.");

  }

  delay(1000); // Wait for 1 second before the next reading

}

Upload and Monitor:

1. Connect your Arduino to your computer.

2. Open the Arduino IDE, paste the code, and upload it to your Arduino board.

3. Open the Serial Monitor (Tools -> Serial Monitor) to see the temperature readings.

This basic example provides a starting point. Depending on your project requirements, you might want to customize the code, add more sensors, or integrate the temperature readings into a larger project. Adjust the pin numbers in the code to match your actual wiring configuration.

arduino,ds18b20 temperature sensor,temperature sensor,ds18b20 temperature sensor arduino,arduino temperature sensor,temperature sensor with arduino,temperature sensor arduino,how to use ds18b20 temperature sensor with arduino,arduino ds18b20,arduino ds18b20 temperature sensor tutorial,temperature,ds18b20 arduino,arduino tutorial,ds18b20 digital temperature sensor,ds18b20 temperature sensor arduino code,ds18b20 temperature sensor with esp32

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.