Pi Weather Station – Weather Sensor Node

The purpose of the Weather Sensor Node is to read the attached weather sensors and provide a JSON API for accessing these over a LAN.


The hardware for the Weather Sensor Node utilizes a Raspberry Pi Model A for the main unit which interfaces with the sensors, Arduino Pro Mini, real time clock and LED display over the I2C communications bus.

The Raspberry Pi lacks the analog inputs needed to interface with the rain drop sensor and wind direction sensor.  There are a few different methods to do this:

  • Use a resistor and capacitor to form a RC timing circuit to determine a change in resistance (Reading Analogue Sensors With One GPIO Pin (Raspberry Pi Spy), however, this only works for varying resistances so would not work for the rain drop sensor
  • Use an external analog to digital converter connect by either I2C or SPI
  • Use a 3.3v Arduino connected by I2C

I settled on using a 3.3v Arduino in the form of an Arduino Pro Mini clone (supplied by Hobby Components) as this also allowed me to interface with the anemometer (wind speed) and rain gauge sensors which generate a pulse for every half revolution/bucket tip.  By using the Arduino for the anemometer (wind speed) and rain gauge sensors I avoided the need for running a separate interrupt daemon on the Raspberry Pi (as is done by the Raspberry Pi Foundation’s Weather Station Hat code).

To allow for the status of the sensor node to be checked I am using a 4-character 14-segment LED display which is connected to the Raspberry Pi over the I2C bus.

To provide accurate time stamps for the data readings I am using a DS1307 real time clock (RTC) module.  This has been configured without the pull-up resistors so that the output is compatible with the Raspberry Pi’s 3.3v I2C pins as the RTC requires 5V power (see Adafruit’s guide on Adding a Real Time Clock to the Raspberry Pi).

To allow the sensor node to be safely turned on and off I am using the petrockblock.com PowerBlock with it’s driver that allows a switch to be used to turn on the Pi and safely turn it off.  When the switch is opened, the micro-controller (an Atmel ATtiny85) on the PowerBlock sends a signal to the driver starting the shutdown process.  Once the Pi has shutdown, the PowerBlock cuts power to the Pi.  It also provides a nice status LED output.

The Sensors

The Weather Sensor Node uses the following sensors:

A new sensor is now available, the BME280, which combines the capabilities of the BMP180 and HTU21D in one package.   The Maplin Replacement sensors are as far as I can tell are exactly the same as the Sparkfun Weather Meters.

The SI1145 UV Index sensor is manufactured by Silicon Labs and is capable of measuring the UV Index, IR and Visible Light levels.  It can also be used with an IR LED to form a proximity sensor.  I could use this to measure the IR and Visible light levels, however, the library I am using was ported from the Adafruit Arduino library and as such does not calculate accurate values.

The TSL2591 High Dynamic Range Digital Light Sensor is manufactured by ams AG and is capable of measuring Visible and IR light levels.  The sensor is able to approximate the response of the human eye from it’s extremely wide high dynamic range.

The BMP180 Pressure, Temperature and Altitude sensor is manufactured by Bosch Sensortech and is capable of measuring barometric pressure and temperature.  It can also be used to calculate the current altitude.

The HTU21D-F Temperature and Humidity sensor is manufactured by Measurement Specialties and is capable of measuring the temperature and relative humidity.

The Maplin replacement sensors appear to be exactly the same as those included in the Sparkfun Weather Sensors pack.  The data sheet for these can be found here, however, there is a typo on the voltages for the wind direction sensor.

The rain gauge has a see-saw with self-emptying buckets on each end that tip over every time they fill up, which equates to 0.011″ or 0.2794mm of rainfall.  On each tip a magnet on the bucket arm closes a reed-switch which can then be used to drive an interrupt on the Arduino.

The anemometer is a cup-type with three cups mounted to a central hub.  The hub contains a pair of magnets opposite each other towards the outside edge – these close a reed-switch which can then be used to drive an interrupt on the Arduino.  One pulse per second equates to a wind speed of 1.492mph (2.4 km/h).

The wind direction sensor is more complicated and has 8 read-switches which are connected to a resistor.  A wind vane is connected to a central hub with a magnet towards the pointer side of the vane. This magnet then closes up to two of read-switches allowing a total of 16 directions to be determined. The following table shows the relationship between the direction and resistance, and therefore voltage (when used with a 5V supply and 10kΩ pull-up resistor – see datasheet for diagram).

0 33000 3.84
22.5 6570 1.98
45 8200 2.25
67.5 891 0.41
90 1000 0.45
112.5 688 0.32
135 2200 0.9
157.5 1410 0.62
180 3900 1.4
202.5 3140 1.19
225 16000 3.08
247.5 14120 2.93
270 120000 4.62
292.5 42120 4.04
315 64900 4.33
337.5 21880 3.43

The YL-83 rain drop sensor is used to determine if it is raining (or if there is dew).  This sensor is a simple moisture detection circuit which is connected to a small module which contains an analog output and digital comparator to provide a simple wet/dry signal.  I am using the analog output to give a relative wetness of the sensor.  If it is raining I would expect a low resistance on the board and hence a low output voltage and if not the opposite.


At the moment I have the software largely working, that is, I can request data from the Raspberry Pi and I get back a JSON string with the data from the sensors.  There is still a bit of work to with error detection etc and some tidying up of the code on both the Raspberry Pi and the Arduino.

For the Raspberry Pi I have implemented a simple web-server running in Python using Flask based upon this excellent and succinct tutorial by Matt Richardson.

The Arduino is running a simple sketch that waits for I2C command before sending back the requested data.

Once the code for both of these has been tidied up I will post some snippets here with the full code on GitHub.

3D Printed Hardware

I am planning on 3D printing all the sensor housings, connection boxes and main node housing.  All the designs will be released on GitHub along with the code.  At present I have a basic design for the light sensor housing which can be seen below.  To prevent water ingress on the sensors, these will be mounted behind microscope slide cover slips – extremely thin pieces of glass which will be sandwiched between two layers of plastic.

Completed View:

Exploded View:

Comments are closed.