Hand tools and fabrication machines
Some of you might know the color changing little statues that are sold as souvenirs in many European cities. These white statues are painted with a specific chemical substance that reacts to air humidity and change the color from light blue to pink, going through other hues in a continuous change. They are supposed to forecast the local weather in the short term. They actually show the current situation but the forecasting powers are very limited and inaccurate.
Starting from that we decided to make a Weather Forecasting Gnome, based on the new Arduino Nano Every and the BME280 sensor. The task that that at the beginning seemed easy turned out to be quite a challenge. The plain barometer is something that allows to have a short term forecast as it tells you if the pressure is raising or lowering and according to the relative pressure calculated as the sea level pressure offset by the local altitude it can also give you some “High” and“Low” reading.
To get to a more accurate forecast, also relative humidity and winds are taken in account and the classic barometer is replaced by a more complex forecast device, the “Zambretti Forecaster”.
This forecaster has been documented by the authors Zambra end Negretti back in 1920 and it has become the solution for a local weather forecast in many microcontroller based projects. You can find the full details on the forecaster here (http://drkfs.net/zambretti.htm) and we also found the work of Fandonov (https://github.com/fandonov/weatherstation) very useful for his implementation of the Zambretti forecaster in his e-Ink display weather forecaster.
We are running this project on our Arduino Nano Every plus to which we added the BME280 sensor from Bosch, a real time clock DS3231 and a tiny strip of eight WS2812B smart LEDs.
The BME280 is capable of measuring temperature, pressure, humidity and give also some clues about absolute humidity and altitude, but as we will see further down, the altitude and pressure are bound together and for our purposes we need to find the real altitude of our Gnome Weather Forecaster.
The DS3231 real time clock module is needed because part of the Zambretti calculation is bound to the season and the only way for this device to know about the season is through a real time clock module properly set. It might look as a waste of resources, but you can improve the code we are supplying with features like a brightness control according to the time of the day and other amenities and use more the RTC in the sketch.
The last component, the strip of LEDs is the equivalent of the colored paint of the little statues that change its color. Here we are taking advantage of the RGB colors to represent the weather forecast with a little more detail, even if the representation of the full 26 different conditions of the Zambretti forecast are too much for a simple color display.
We decided to simplify it and it is a work in progress you can easily change to a different color coding.
The two main modules are both based on I2C and therefore the wiring is really simple.The RTC module we are using has even a pass through for the four connections and this makes our wiring a 10 minutes work. VCC and GND are taken from Arduino Nano Every 3V3 (Red) and GND (Black) pins on the header and soldered to the corresponding pins on one side of the DS3231 module, then the I2C interface is as usual on A4 and A5 of the Arduino. A4 is SDA (blue wire in the pictures) and A5 is SCL (yellow wire in the picture). We take the same four connections from the other side of the RTC module and wire them to the BME280 module just taking care of the order. There is no standard for the VCC / GND / SDL / SCA sequence and each module might have a different order that needs care.
The LED strip has the usual three labels VDC, DIN and GND. This time the power supply will comes from the 5V pin. One reason is that we have the pad free for soldering, the other is that we are feeding the board from USB and 5V is from USB directly, with no stress for the power regulator of the Nano.
The data is fed to the strip on D7 pin, but could be any other one you may find suitable.Just edit the sketch with the pin you chose in the #define LED_PIN 7 line close to the top.
This is it for the wiring. We will power the circuit via USB because it needs to be continuously on to monitor the environmental parameters and make a forecast. A power bank for a mobile phone might power the circuit for quite some hours, but It would inevitably run out of energy.
To get this project working we need several libraries and you find them in the first lines of the sketch as #INCLUDEs.
Wire is necessary for the I2C communication, the Adafruit_Sensors and Adafruit_BME280 allow us to read the data from the pressure, humidity and temperature sensor. The LED strip is managed by the Adafruit_NeoPixel lib that gives us a quick and effective control over each pixel color. Last, but not least important is RTCLib that allows us to read all the information from the DS3231 Real Time Clock.
The constants we use are those for the average sea level pressure and for the Led strip. The value we are using for the average sea level pressure is 1013,25 mbar, equivalent to 101,325 kPa and it is the value recognised internationally.
After the initialisation of the various devices, we define some variables that will be used for the forecast and also for some textual output on the Serial Monitor. If you want to see what’s going on with the weather in depth, you can connect the pc and read the data supplied, otherwise, you might simplify a lot the sketch just avoiding all the string formatting and printing.
We decided to keep these debug information available to keep also some educational value in the project.
The array starts empty and the code is filling it every 10 minutes with a new value so that the last cell of the array contains the newest pressure reading. The value that contains the pressure is seapressure and it is calculated to compensate the height at which the device is placed.
A very important variable is the altitude of the device. We know the sea level pressure and we need to adjust the reading from the sensor so that we can feed into the Zambretti formula the pressure we would read at sea level starting from what we read from the sensor. There is a formula that does this calculation knowing a series of parameters and if you have at hand a GPS (even your smartphone could have one) to read the altitude, you can put that value in the altitude variable. With that information, the formula is
P0 is the relative sea-level pressure;
P is the station pressure in hPa;
h is the altitude in meters and
T is the temperature in Celsius.
With the output of this formula we have the pressure brought at the sea level, so that we can feed it into our array. The array is like a shift register and any time a new value is added, all the former values are shifted one position left (the oldest value is at 0 and the newest is at 9).
With this array of 10 values, spaced in time by 10 minutes, the Zambretti formula finds out the pressure variation tendency (falling, stable or rising) and values on a sliding window of values collected in the last 100 minutes. In the formula alsothe month is taken in account because Zambra and Negretti found it was relevant to get a more accurate forecast.
For the first 100 minutes however, the device is collecting the first complete set of pressure readings, therefore the forecast will be completely wrong. At the completion of this set, the forecast will be adjusted every 10 minutes.
The following lines replicate the physical object to find out the letter corresponding to the forecast using the three windows (falling / steady / rising) and the pressure reading. This means that for the same pressure reading, it is the short term change that makes the difference as well as summer/winter seasons. It is done in the function calc_zambretti that gets as input the oldest three values of pressure averaged, the last three values averaged and finally the month to spot the season.
The long list of if… then… else finally pics the Zambretti output and rearranges the 26 messages in simpler groups that are Sunny, Sunny Cloudy, Worsening, Cloudy, Rainy, telling us if the pressure is raising, stable or falling as well. We kept the original algorithm of Fandonov because it allows you to understand very well how the forecast works, then we had simplified the output coding the five possible situations into five different LED colors. The usage of a strip allows the slow change from one color into the other, scrolling up one LED at each new forecast; this is also a solution to give you the trend of the forecast.
We implement the scrolling of the led bar with a simple routine that copies the content of each led to the next one starting from the top, so that it shifts everything up, then the new value is defined by the Zambretti algorithm and it is written in the first LED position.
We are hosting the circuit in our “standard” 3D-printed Gnome. This time the BME280 is partially out of the back of the Gnome, from his heels, while the USB is accessible at mid height. You can modify the STL files we already shared in our former project Gnome Traveller to let the sensor and the USB port be accessible from the outside.
The wiring is really simple and therefore putting everything in the 3D-printed Gnome should be very easy. In our setup the strip is in the upper part of the Gnome so that the head and hat light up with the color of the forecast. Keeping the sensor outside the Gnome is best as it allows it to get air from the environment. The best results require the sensor to be in the open air and not your apartment where humidity and temperature are kept under control.
A solution could be to keep the gnome close to a window and keep the sensor outside with a 4 wires cable link; I2C can tolerate up to one meter and that is more than you need to put the sensor out of the window.
When all the hardware is set up, you can proceed with the sketch. Copy it from here and also check with Library Manager that you have all the needed libraries:
The Arduino Nano Every uses the MegaAVR core and you should have that properly installed as well: if you have the board in the list of the available ones it is installed, otherwise you need to use the Board Manager to install it.
Launch the verify of the sketch just to be sure everything is correct and then upload. Open the Serial Monitor and look at the data that slowly will be printed. Every minute you get a pressure reading, every ten minutes the reading is stored.
Take a break and let the array fill up with the real data. Come back after a couple of hours and what you see and read should be meaningful.
Yellow is sunny, azure is cloudy and then it goes to purple and red when the weather worsens up to the rain.
We kept the text in the sketch so that you can easily change the color for each of the managed weather conditions. The syntax is strip.setPixelColor(LED, R, G, B); with LED that should always be the first in the strip (0) and RGB values from 0 to 255. There is an overall brightness setting that you can use to get a different intensity of the LED throughout the day; look for the strip.setBrightness(100); line and turn it into something related to night and day reading the RTC.