The weather station project will be bringing together a number of sensors, light, ultraviolet light, air pressure, humidity, wind speed, wind direction and rain fall. This collection of sensors falls into three groups:
- Electronic sensors on an I2C bus
- Mechanical sensors using switches
- Analog sensors
The current plan is for the weather station to use the Oak as the microcontroller running the show. The data from the sensors can then be uploaded to the cloud, destination to be determined, but let's start with Sparkfun's">https://data.sparkfun.com/">Sparkfun's data service.
The I2C sensors will require the least amount of work to get up and running so let's start with those. The two sensors operating on the I2C bus are:
- TSL2561">https://www.sparkfun.com/products/12055">TSL2561 - Luminosity sensor
- BME280">https://www.adafruit.com/products/2652">BME280 - Air pressure, temperature and humidity sensor
One of the great things about working with these two sensors is the fact that there are prebuilt drivers and example code for both breakout boards available from Github. What could be simpler, well head over to the Sketch - Include Library - Board Manager... menu in the Arduino IDE and you can download the library and have the IDE install it for you.
TSL2561 - Luminosity Sensor
This sensor allows the radiance of the light to be calculated in a way that approximates the response of the human eye. It does this by combining the input from two photodiodes, one infra-red only and one visible light and infra-red light combined. The output from the two sensors can be used to luminous emittance in lux (lumens per square metre).
The following table gives an idea of the lux values for typical scenarios:
|0.0001||Moonless, overcast night|
|0.002||Moonless, clear sky|
|0.27 - 1.0||Full moon on a clear night|
|80||Office building hallway|
|10,000 - 25,000||Daylight|
As you can see from the table above, the lux values for a "normal" human day can vary dramatically. The sensor copes with this by allowing the use of a variable time window and sensitivity when taking a reading. Effectively the sensor accumulates the readings over the time window (integration interval) into a single 16-bit number which can then be used to calculate the lux reading.
BME280 - Air Pressure, Temperature and Humidity Sensor
This sensor is produced by Bosch and is packaged in both I2C and SPI configuration on the same board. The accuracy of the sensor appears good, pressure and temperature both to 1% and humidity to 3%.
Both Sparkfun and Adafruit have provided libraries and example code for the boards. These were easy to add to the development environment.
One caveat, the BME280 requires the addition of the Adafruit sensor library as well as the BME280 library.
Once added it was a simple case of wiring up the sensor to 3.3V and the I2C bus and running the example code.
They both worked first time.
Some Code Modifications (for later)
The light sensor has been show to work in low light conditions but not to any degree of precision. A possible modification to the example code is to look at the sensitivity and integration window settings to see if the precision can be adjusted to make the sensor return better readings in low light.
Some of the values when calculated use the fractional part of a floating-point number, temperature and humidity spring to mind. This meant adding a method to convert a double into it's string representation for debugging purposes. Trivially solved but an annoying omission from the implementation of sprintf.
Next up, the analog sensors.