Creating a weather station – DS18B20 (Part 1)

Greetings world!

This will be my first attempt at writing a technical blog. I have a lot of ideas lying around, and hope this blog can inspire both myself and someone else to get creative and do stuff.

So my first post is part 1 of creating a weather station. I already have a bought one in my kitchen, but this project I think is perfect for learning more about the Arduino Uno and C programming, and further on Raspberry Pi with Python programming, as well as some databases and other cool stuff I have planned. So without further ado; Creating a weather station (Part 1):

Getting the temperature

The core function of any weather station is reading the temperature. Luckily we have come a bit further than reading the data off an old school mercury filled glass tube. Today we got electronics! After roaming the internet for a while I found that the DS18B20 is a well supported, well documented and fairly cheap component, perfect for the cause.

Connecting the DS18B20

Due to the vast amount of information about this component on the internet, connecting it to the Arduino was a breeze.

Connecting the DS18B20 to the Arduino requires 4 cables, a 4.7k resistor, the Arduino board and of course the DS18B20 itself.
Connecting the DS18B20 to the Arduino requires 4 wires, a 4.7k resistor, the Arduino board and off course the DS18B20 itself.

Red wire is power (5V), black wire is ground and white wire is the data wire.

Programming the Arduino to read from the DS18B20

The programming required to read any data of the DS18B20 is pretty ugly, at least for a rookie like my self. Luckily there is a heap of programmers better suited than me to write these kinds of programs, and since programmers are cool people they often share they work. Reading data of the One-wire protocol is easy thanks to two libraries:

The OneWire library is for reading the raw data itself. Its mentioned on the Arduino web site, and can be found here. This library can be used for any device that uses the One-wire protocol.

The data from the OneWire library is of no use in its current form for the end user. Hex data tells me very little about the weather or the temperature. The Arduino library database has a library called DallasTemperature, which is perfect for making the data nice and pretty.

Having installed these two libraries, I used the sample sketch to produce a readable temperature output.

This code outputs the current temperature. I have not dug into the library code to see what it actually does, thus I do not know how often it updates the temperature. It does seem to check about once every second, and for my use that is more than enough.

Requesting temperatures…DONE
Temperature for Device 1 is: 20.12

So there it is, 20.12°C on my workbench at the moment. The accuracy is ±0.5°C, but I can actually see the temperature change by breathing in the sensors direction.

The circuit setup for the DS18B20 temperature sensor.
The circuit setup for the DS18B20 temperature sensor.

 

4 thoughts on “Creating a weather station – DS18B20 (Part 1)”

  1. Alt for teknisk for meg å henge med på koden ;P men det hadde vært interessant å lese hva sluttmålet er. Hva vil du kunne gjøre med den, jeg antar at du har større planer enn å kun lese av temperatur i nåtid.

  2. Koden er egentlig ganske enkel, da ferdige bibliotek tar seg av hele den avanserte biten. sensors.requestTemperatures(); og sensors.getTempCByIndex(0) er det som skal til for å hente temperatur i Celsius fra sensoren.

    Videre planer er å utvide med sensor for sensor og til slutt stå med en fullverdig værstasjon. Ikke for at den jeg allerede har ikke duger, men fordi det er litt morsomt å lage noe selv =) Jeg har dessuten tenkt å koble alt sammen til en database, slik at jeg kan ha en nettside på hjemmenettverket hvor jeg kan se all slags data som er logget!

    Læringsutbyttet er jo selvfølgelig viktig, her er både elektronikk og koding, videre planer åpner jo for å lære mer om databaser og både back end og front end webutvikling.

    En plass måtte jeg begynne, og da er denne lille temperatur-måleren fin å ha =)

    1. Et lite «ax till limpa»-prosjekt som vi sier i Sverige.

      Har du tenkt presenterte det i tabell/siffer-form på intranettet eller går en mer visuell approach i en d3js-stil?

  3. Nå har jeg ingen erfaring med d3.js, men det ser jo unektelig bedre ut med et pai-diagram enn en tabell med tall! Jeg får forske litt på det og se hvordan man kan presentere de data jeg får.

Leave a Reply

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