Temperature sensor DS18B20

TTN version: TTNv3
Activation: ABP
Device Class: Class A
Last updated: October 7, 2023

This article provides instructions for making a temperature sensor using Adafruit Feather 32u4 RFM95 LoRa Radio and DS18B20. If you haven’t set up Adafruit Feather 32u4 yet, check out our Adafruit Feather 32u4 tutorial.

Adafruit Feather 32u4 and DS18B20

 

Prepare

  • Adafruit Feather 32u4 RFM95 LoRa Radio
  • DS18B20
  • 4x wire
  • 4.7k resistor
  • breadboard (optional)
  • PC + micro USB cable

 

DS18B20

To measure temperature, we will use the DS18B20 temperature sensor. The sensor measures temperatures in the range of -55 ºC to 125 ºC. In the range of -10 ºC to 85 ºC, the measurement accuracy is ± 0.5 ºC.

DS18B20 - sensor

 

Sensor assembly

Connect everything according to the schematics bellow.

Wire up the Adafruit Feather 32u4’s IO1 pin with pin 6. The sensor is connected using three wires. The red wire (Vcc) is connected to the supply voltage (3V pin on Adafruit Feather 32u4) and the black wire (GND) is connected to ground (GND pin on Feather). The yellow wire (DQ) is used for data transmission via the 1-Wire bus and is connected to Feather’s digital pin 12. Between red and yellow DS18B20 wires is connected 4,7k resistor. The sensor requires a stabilized supply voltage in the range of 3 V to 5.5 V for its function.

Adafruit Feather 32u4 and DS18B20

 

Arduino IDE setup

  1. Run Arduino IDE.
  2. In the Arduino IDE Library Manager search DallasTemperature by Miles Burton and  install it with all dependencies (library OneWire).
  3. In the Arduino IDE Library Manager search CayenneLPP by Electronic Cats and install it.
  4. Download as ZIP this Low-Power library by Rocketscream.
  5. In the Arduino IDE Sketch -> Include Library -> Add .ZIP Library… choose downloaded ZIP.

 

Printing measured values to Serial Monitor

  1. Copy and paste this program to your Arduino IDE.
  2. Connect Adafruit Feather 32u4 using micro USB cable to your computer.
  3. In Arduino IDE click on Upload button to upload program to your Adafruit Feather 32u4.
  4. In Arduino IDE click on Serial Monitor button and you should every 10 seconds see this:
DS18B20 Serial Monitor

 

Sending measured values to TTS

We have prepared four programs for measuring temperature. The first program sends the current measured values. The second program sends averages of measured values over a certain period of time. The other two programs extend the first two with a low power mode, which is great when you run this sensor on battery power.

Programs

 

Instructions

  1. Copy and paste one of this programs to your Arduino IDE.
  2. In program replace NWKSKEYAPPSKEY and DEVADDR with keys of your end device registred in TTS. Keys are in TTS -> Applications -> YourAppName -> YourEndDeviceName -> Overview -> Session information.
  3. In TTS -> Applications -> YourAppName -> YourEndDeviceName -> Payload formatters -> Uplink change Formatter type to CayenneLPP. For more information, check out our Cayenne LPP tutorial.
  4. Click on Save changes.
  5. Connect Adafruit Feather 32u4 using micro USB cable to your computer.
  6. In Arduino IDE click on Upload button to upload program to your Adafruit Feather 32u4.
  7. In TTS -> Applications -> YourAppName -> YourEndDeviceName -> Live data you should every 5 minutes (Low Power Mode – 10 minutes) see this:
DS18B20 - TTS console

Data visualization

If you want to visualize your measured data, continue with the following tutorial: