Power supply pin (typically 3.3V or 5V)
Power supply pin (typically 3.3V or 5V)
Ground pin
1-Wire data pin
Operating Conditions
-55C to 125C
-65C to 150C
3.0V to 5.5V
1.5mA (active), 1A (standby)
Applications
The DS18B20 Digital Temperature Sensor Module is suitable for a wide range of IoT applications, including |
Environmental monitoring
Industrial automation
Medical devices
HVAC systems
Automotive systems
Consumer electronics
Conclusion
The DS18B20 Digital Temperature Sensor Module is a reliable and accurate temperature sensing component suitable for a variety of IoT applications. Its high accuracy, wide temperature range, and low power consumption make it an ideal choice for systems requiring precise temperature measurement.
DS18B20 Digital Temperature Sensor Module Documentation
Overview
The DS18B20 is a digital temperature sensor module that provides a high-accuracy and high-reliability temperature measurement solution. It is a popular choice for IoT projects that require temperature monitoring, such as weather stations, industrial automation, and smart home systems.
Technical Specifications
Operating temperature range: -55C to +125C
Accuracy: 0.5C (between -10C to +85C)
Resolution: 9-bit to 12-bit (configurable)
Communication protocol: 1-Wire ( Dallas Semiconductor protocol)
Power supply: 3.0V to 5.5V
Hardware Connection
The DS18B20 module typically has three pins:
VCC: Connect to a power supply (3.0V to 5.5V)
GND: Connect to ground
DQ (Data): Connect to a digital input pin on the microcontroller
Software Examples
Here are three code examples demonstrating how to use the DS18B20 digital temperature sensor module in various contexts:
### Example 1: Arduino Temperature Monitoring
This example uses an Arduino Uno board to read the temperature from the DS18B20 module and display it on the serial monitor.
```c++
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Pin 2 for data communication
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
delay(1000);
}
```
### Example 2: Raspberry Pi Python Script for Temperature Logging
This example uses a Raspberry Pi to read the temperature from the DS18B20 module and log it to a CSV file using Python.
```python
import os
import glob
import time
import csv
# Define the DS18B20 device file
device_folder = '/sys/bus/w1/devices/'
device_file = glob.glob(device_folder + '28')[0] + '/w1_slave'
def read_temperature():
with open(device_file, 'r') as f:
lines = f.readlines()
if lines[0].strip()[-3:] == 'YES':
temperature = lines[1].find('t=')
if temperature != -1:
temp_string = lines[1][temperature + 2:]
temp_c = float(temp_string) / 1000.0
return temp_c
return None
while True:
temperature = read_temperature()
if temperature is not None:
with open('temperature_log.csv', 'a', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([time.strftime('%Y-%m-%d %H:%M:%S'), temperature])
time.sleep(60) # Log temperature every minute
```
### Example 3: MicroPython on ESP32 for Wi-Fi Temperature Monitoring
This example uses an ESP32 board running MicroPython to read the temperature from the DS18B20 module and send it to a remote server using Wi-Fi.
```python
import machine
import onewire
import ujson
import urequests
# Define the DS18B20 pin and Wi-Fi details
ds_pin = machine.Pin(4)
wifi_ssid = 'your_wifi_ssid'
wifi_password = 'your_wifi_password'
server_url = 'http://your-server.com/temperature'
# Initialize the DS18B20 and Wi-Fi
ds = onewire.OneWire(ds_pin)
dsDevices = ds.scan()
while True:
# Read temperature from DS18B20
temp = ds Devices[0].temperature
print(f'Temperature: {temp} C')
# Connect to Wi-Fi
wlan = machine.WLAN(machine.WLAN.STA_IF)
wlan.active(True)
wlan.connect(wifi_ssid, wifi_password)
# Send temperature to remote server
data = {'temperature': temp}
headers = {'Content-Type': 'application/json'}
response = urequests.post(server_url, json=data, headers=headers)
response.close()
# Wait for 1 minute before taking the next reading
machine.sleep(60)
```
These examples demonstrate the basic usage of the DS18B20 digital temperature sensor module with various microcontrollers and programming languages. The code can be modified and expanded to suit specific project requirements.