---
# System prepended metadata

title: 'Weatherwax G '
tags: [3d-printing, Weather station, solar power]

---

This project will explain how i've made a potentially self sustaining weather station that uploads data to the cloud. The name is from Granny Weatherwax whom is a person in the Discworld series written by Sir Terry Pratchet. She's a witch and a practitioner of Headology. 

My name is Dennis Engelmark and LNU username is de222mb.

I will present the project in a series of pictures. I knew from the start what i wanted to make. I've also fiddled with arduino earlier so i have some minor experience. I've got some coding experience in python from the course deep learning on UMU which is about AI, ML & DL.

I wanted to use as many sensor as possible but some were impossible for me for some reason. I am looking at you ds18b20. DHT11 works fine and so does my rain and earth humidity sensor. I also wanted to power the device with a battery and possibly a solar panel. 

To assemble the project i guess you could make it in 2 hours if it's the first time. If you can just copy the code as well it maybe 2 hours 15 min. With 3d-printing the shell i guess it depends on your machine, the one i loaned printed the lid in 2 hours so if you wanted to print a whole box i guess we're looking at 5 hrs.


![](https://hackmd.io/_uploads/H1jjQjZK2.jpg)



At first i wanted to place my weather station near a dam and have it communicate through TTN however it seems i am out of range from the single gateway in my town of Norrköping. I even tried going nearby the gateway in a car and it still didn't connect. I will buy another pico w and try it again sometime in the future. So i wanted to measure temperature and humidity near the dam. I also wanted to measure the water temperature but i had problems with the ds18b20 sensors which were in the water temperature sensor i bought. TBH it's mostly for fun. The purpose it serves would be temperature measurements ofcourse.

Insights the project would be, is it hot enough to swim today. Is the soil moist, is it raining much and so on.

**Material**

Pico W

Cables (F-M mostly), 3x resistors (560)

Soldering device

Screw driver

Really small screws

3D-printer (Ender 5 pro was used on loan)

Earth humidity sensor
https://www.electrokit.com/en/product/soil-hygrometer-module/

DHT11
https://www.electrokit.com/en/product/digital-temperature-and-humidity-sensor-dht11/

Rain sensor
https://www.electrokit.com/en/product/rain-sensor/

Light sensor
https://www.electrokit.com/en/product/light-sensor-module/

Lipo battery
https://www.electrokit.com/en/product/battery-lipo-18650-cell-3-7v-2200mah/

Lipo battery charger (for over charging protection)
https://www.electrokit.com/en/product/batteriladdare-lipo-usb-c/

Battery holder
https://www.electrokit.com/en/product/battery-holder-1x18650-wire-leads/

Solar panel (USB A to micro usb)
https://let-elektronik.dk/monocrystalline-solar-panel-5v-1a

3x leds, green yellow and red
I couldnt find any on electrokit but they are pretty standard. Green led is so weak for some reason and is barely visible in daylight

**Computer setup**

The chosen IDE for the project is VSC recommended by the course. It has been really pleasant to use although one could wish for more typing completions/recomendations. Flashing the pico with the latest firmware was done naturally. 

To flash is to move a file to the pico which the restarts and tries to boot the file. To be able to move files to the pico w you have to hold the boot sel on the pico while plugging it in. After which you move said file to the pico w in your OS explorer or what you prefer. 

You might need some supporting libraries for VSC to work. 

**Putting everything together**

For wiring, please refer to each sensors data sheet or ask the supplier. Make sure you power the project through the 3v3 slot on the pico.

The box
![](https://hackmd.io/_uploads/BJ6qRiZY2.jpg)

3D printed lid. It would probably be smart to have a bigger box and also
bigger slots for the screws
![](https://hackmd.io/_uploads/BJ3i0iWFn.jpg)

Here is the over chage protection for the battery. The USB cord is meant to be placed in the solar panel. The overcharge protection card needs some soldering both from the battery but also to power the pico w.
![](https://hackmd.io/_uploads/r18W1hWtn.jpg)

The LED's are in place
![](https://hackmd.io/_uploads/SJs-Jn-F2.jpg)

I cut of a part of the breadboard to connect all the the things
![](https://hackmd.io/_uploads/By4fk3bth.jpg)

It's a bit of a mess, yes, everything is fitted to the box in roughly the way i wanted
![](https://hackmd.io/_uploads/rJdGknZth.jpg)

Soldering the resistors to the leds since it was supposed to be healthy for the leds. I also had to solder the long legs to a (M-M) cable while the short goes into the - row (ground) on the bread board bit.
![](https://hackmd.io/_uploads/BJ2My3-Fh.jpg)

Connect everything to the pico w, see code for pins.
Basically its like this:

```
greenLed = Pin(2, Pin.OUT)
yellowLed = Pin(3, Pin.OUT)
redLed = Pin(4, Pin.OUT)
dhtSens = dht.DHT11(machine.Pin(16)) 
rainSens = ADC(Pin(26))
soilSens = ADC(Pin(27))
sunSens = ADC(Pin(28)) #photo synth
onBoardTemp = machine.ADC(4)  
```

![](https://hackmd.io/_uploads/H1y7khbKn.jpg)

It should now look like this. Don't be afraid it's not going to bite.. probably.
![](https://hackmd.io/_uploads/HkmQknWt3.jpg)

I mounted the supporting cards for rain and earth humidity sensor here to the lid as well as the pico w.

Now apply some force and luck
![](https://hackmd.io/_uploads/rkRXJhbK3.jpg)

Voila
![](https://hackmd.io/_uploads/ryDXYAWK2.jpg)




**Platform**

The project utilizes adafruit which is really generous with barely no restirctions on data, so far. The project sends data every ten minutes and it has been accepted so far. The data shipped is small in terms of size. It would be really nice if Lorawan would have worked because i think it would've been perfect for this project. Going forward i am planning to build a mini-server with raspberry pi 3 or 4 in combination with a small screen that shows the dashboard to the user. You would need to keep within range of a wifi though which is a problem since you might want to measure some place else.

**The code**

Code is available here:
https://github.com/engnisden/iot

Just take note that you need to supply your own wifi credentials in boot and adafruit username, password and feeds in main. 

About the code, it runs once and then restarts the machine. I would prefer if it could keep running inside a while loop but there was some memory limits why i did it this way. If not for the limits i would have used 1 or 2 more sensors. So first the code declares a lot of stuff like feed adresses and pin locations for each variable. Imports are also on top and i see i have two libraries i could be without for now, onewire and ds18x20. I will remove it if i plug it in again.


The program revolves around the three leds which sort of blink if the station is doing something. It should light the green led up if it has published all measurements and is waiting. While measuring the yellow led lights up constantly and blinks every measurement. If the red led is constant something is wrong.

**Transmitting the data**
Data is sent every 10 minutes on the wifi and with mqtt. That's what i got to work although lorawan whould have been prefered but there were no gateways in range apparently. 

**Dashboard**
You will have to excuse my diagrams, i've been busy with work so i haven't been able to measure for a longer time. The measurements should be accurate starting from 2/7 which in this picture is 3 point from the right.
![](https://hackmd.io/_uploads/rkuc2abK3.png)

Dashboard is also available here:
https://io.adafruit.com/twero/dashboards/allt

No triggers or anything. Like i've discussed earlier adafruit is perfect for a weather station since the data sent is so small. 

**Finalizing the design**

All in all the project went well. It would have been nice if the TTN was in range. I'm really happy with the box, although it could have been bigger. It should be bigger. The station has survived a short rain fall already but is now reporting wierd data. Earth humidity went from 62 to 32 in a couple of hours for example and rain is 7000 now, currently 5000 lower than when its not raining. 

There are some problems with components in this project i've noticed. There are some 'avlagringar' after rain which likely disturbes the sensors and solar panel. Going forward some kind of automation for cleaning these parts would be good. Possibly the battery needs to be checked too. In an early test the projected lasted 3 days without charging. Now with the solar panel that time is hopefully longer. 

To make this project actually useful to someone like say a potential customer the data has to be visualised. It has to be made easy and sort of plug and play. That's why installing a local server like with a raspberry pi 3 or similiar would be good. There you could connect it to the local wifi and maybe create an own wifi to connect the weather station to. This way the data could be uploaded to the machine and be visualised there. 

Going even furter forward, lets say it all works like on rails. Next step is a locally produced weather forecast based on earlier readings. There is a method in machine learning utilizing time series which predicts new values based on earlier readings. Using the local data with the pre-trained AI model we could get semi-accurate weather predictions. AI is sensitive to sudden changes and pretty poor at predicting them. Perhaps if we could use all collected data in combination and then we could get more accurate predictions. 

