Arduino Weather Station Project - DS18B20 Temp Sensor

Hooking Up the DS18B20 Temperature Sensor (Part 2)

The first sensor we connect up is the Dallas DS18B20 temperature sensor. We need to use a waterproof version as the sensor will be mounted outside the weather station shelter but protected by the wind temperature cover.

We need to connect a 4k7 resistor between the power wire and the data wire as per the manufacturers recommendations. This is shown in the diagram below.

The DS18B20 is connected to digital I/O pin 9 on the Arduino board. We will need to define this in the sketch so that DS18B20 library uses the correct pin to communicate with. This is a different pin that is used in the Arduino to DS18B20 Hookup Guide.

Hookup Arduino to DS18B20

Code

We are going to build up the weather station code as we proceed through the project. As we add each sensor we will expand the code. As we connect up each sensor we will test it's functionality. For this we will use the console to display the data from each sensor. Once we have all of the sensors connected we will add the web server code so that we can upload data to the cloud. We will remove the console code from the sketch once we complete testing.

Library

To communicate with the DS18B20 sensor we are using the cactus_io_DS18B20 library.

Software Sketch

Basic Weather Station DS18B20 Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "cactus_io_DS18B20.h"

int DS18B20_Pin = 9; //DS18S20 Signal pin on digital 9

// Create DS18B20 object
DS18B20 ds(DS18B20_Pin);

void setup() {
ds.readSensor();

Serial.begin(9600);
Serial.println("cactus.io | Weather Station DS18B20 Sensor Test");
Serial.println("Temp (C)\tTemp (F)");
}

void loop() {
ds.readSensor();

Serial.print(ds.getTemperature_C()); Serial.print(" *C\t");
Serial.print(ds.getTemperature_F()); Serial.println(" *F");

// Add a 2 second delay.
delay(2000);
}

Sketch Console Output

In the sample sketch we just output the temperature in degrees celsius and fahrenheit. In the next parts of this project we are only going to us celsius. If you wish to use fahrenheit then call getTemperature_F() instead of getTemperature_C().

Connect Arduino to Maxim DS18B20 Temperature Sensor

Next Step

In part 3 of the project we hookup the Bosch BME280 sensor.