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.
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 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.
// Data wire is plugged into pin 5 on the Arduino
#define ONE_WIRE_BUS 5
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
// Pass our oneWire reference to Dallas Temperature.
// start serial port
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
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.
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.