跳到主要内容

One Wire Temperature Sensor DS18B20

This 2m long One Wire Temperature Sensor has a waterproof probe and long wire shape, suitable for immersive temperature detection. The chip inside this sensor is DS18B20 which is widely adopted.The original one includes three wires inside, you need to add an extra resistance to get it working. For this sensor, we adjusted it into a Grove port and had a resistance pre-assembled inside so that you can use it as a regular Grove sensor. This article is going to illustrate the usage of the sensor on Raspberry Pi and have a fun!

Upgradable to Industrial Sensors

With the SenseCAP S2110 controller and S2100 data logger, you can easily turn the Grove into a LoRaWAN® sensor. Seeed not only helps you with prototyping but also offers you the possibility to expand your project with the SenseCAP series of robust industrial sensors.

SenseCAP S210x series industrial sensors provide an out-of-box experience for environmental sensing. Please refer to the S2101 Wireless Temperature and Humidity Sensor with higher performance and robustness for air quality monitoring. The series includes sensors for soil moisture, air temperature and humidity, light intensity, CO2, EC, and an 8-in-1 weather station. Try the latest SenseCAP S210x for your next successful industrial project.

SenseCAP Industrial Sensor
S2101 Air Temp & Humidity

Features


  • Requires only one wire for data interface
  • Waterproof
  • Grove compatible
  • Accepts 3.0V to 5.5V power supply
  • Wide temperature range: -55°C to +125°C
  • High accuracy: ±0.5°C( -10°C to +85°C)
警告

The cable part cannot be put under temperature higher than 70°C for a long time.

Specification

Operating Voltage3.0-5.5V
ChipDS18B20
Length2m
Operating Temperature-55°C to +125°C

Platform Supported

ArduinoRaspberry Pi

Getting Started


After this section, you can make One Wire Temperature Sensor run with only few steps.

Play with Arduino

Materials Required

Seeeduino Lotus V1.1One Wire Temperature Sensor
Get ONE NowGet ONE Now

Hardware Connection

提示

Please plug the USB cable,One Wire Temperature Sensor Interface into Seeeduino Lotus V1.1 Interface gently, otherwise you may damage the port.

  • Step 1. Plug One Wire Temperature Sensor into D2 interface of Seeeduino Lotus V1.1 with a Grove Cable.

  • Step 2. Connect Seeeduino Lotus V1.1 to PC via a USB cable.

  • Step 3. Download the code, please refer to the software part.

  • Step 4. Run the code and the outcome will display on the screen of Serial Monitor in your Arduino IDE .

Software

警告

If this is the first time you work with Arduino, we strongly recommend you to see Getting Started with Arduino before the start.

Software Code

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2


// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*
* The setup function. We only start the sensors here
*/
void setup(void)
{
// start serial port
Serial.begin(115200);
Serial.println("Dallas Temperature IC Control Library Demo");

// Start up the library
sensors.begin();
}

/*
* Main function, get and show the temperature
*/
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
float tempC = sensors.getTempCByIndex(0);

// Check if reading was successful
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
}
success

If everything goes well, you can go to Serial Monitor to see an outcome as following:

1-wire'' OUTCOME

Play with Raspberry Pi

Materials required

Raspberry Pi 4 Model BGrove - Base Hat for Raspberry PiOne Wire Temperature Sensor
Get One NowGet One NowGet One Now

Connecting hardware

Step 1. Connect One Wire Temperature Sensor to port D5 of Grove - Base Hat for Raspberry Pi, Plugged into Raspberry Pi 4 Model B. And then connect the Raspberry Pi 4 Model B with a PC.

Step 2. After accessing the system of Raspberry Pi, git clone Seeed_Python_DS18B20 and install grove.py by inserting the following command:

pip3 install Seeed-grove.py

Or on supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI:

pip3 install seeed-python-Ds18b20

Step 3. To install system-wide (this may be required in some cases):

sudo pip3 install seeed-python-Ds18b20

And you can insert the following command to upgrade the driver locally from PyPI:

pip3 install --upgrade seeed-python-Ds18b20

Software

import seeed_ds18b20
import time

def main():
DS18B20 = seeed_ds18b20.grove_ds18b20()
print("Please use Ctrl C to quit")
while True:
temp_c,temp_f = DS18B20.read_temp
print('temp_c %.2f C temp_f %.2f F' % (temp_c,temp_f),end=" ")
print('\r', end='')
time.sleep(0.5)

if __name__ == "__main__":
main()
警告

When running the demo code on Raspberry Pi, you MIGHT be reminded to enable the 1-Wire interface. Then you should use the command sudo raspi-config and reboot to enable the 1-Wire device:

Step 4. Run the demo by the following command:

cd Seeed_Python_DS18B20
python3 examples/BasicRead.py 
success
      The outcome will display as following if everything goes well:

Resource

[PDF] DS18B20-Datasheet.

Tech Support

Please submit any technical issue into our forum.


Loading Comments...