In this article we will discover the temperature  OneWire DS18B20 temperature sensor, available also in a waterproof version.

The DS18B20 is a so called 1-wire digital temperature sensor. “1-wire” make this sensor really cool and you can connect multiple devices together, utilizing only one pin on your ESP8266 or Arduino.

The waterproof version can be used for outside temperature or for the fridge temperature, where the medium is not so friendly with the electronic circuits.

To get the ESP8266/Arduino and the sensor to work we need the one wire library.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <SimpleTimer.h>

SimpleTimer timer;

#define ONE_WIRE_BUS D3 // DS18B20 pin

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

void setup() {
    Serial.begin(115200);
    // Setup a function to be called 20 seconds
    timer.setInterval(20000, read_temperature);
}

void loop() {
    // put your main code here, to run repeatedly:
    timer.run();
    delay(50);
}

void read_temperature() {
    float temp;
    do {
       DS18B20.requestTemperatures();
       temp = DS18B20.getTempCByIndex(0);
       Serial.print("Temperature: ");
       Serial.println(temp);
    } while (temp == 85.0 || temp == (-127.0));
}

 

DS18B20 Technical specs:

  • Usable temperature range: -55 to 125°C
  • 9 to 12 bit selectable resolution
  • Unique 64 bit ID burned into chip
  • Multiple sensors can share one pin
  • ±0.5°C Accuracy from -10°C to +85°C
  • Query time is less than 750ms
  • Usable with 3.0V to 5.5V power/data

Datasheet is available here or DS18B20.

Sources:

Tweaking4All.com

Adafruit

OneWire library


Get one or many from here

Mine is from here

 

OneWire DS18B20 temperature sensor
Tagged on:                             

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.