---
title: IoT weather station
tags: temperature, humidity
---
# IoT weather station
Albin Kristiansson
ak224mt
A portable IoT weather station that tracks humidity and temperature.Its inserts it into a dashboard on the pybytes platform.
Took approximately 2 days to do all in all.
---
## Objective
I chose this project due to the fact that I own a boat, and humidity during winter time is kind of a bummer... So I wanted to be able to track humidity basically...
... and unfortunately I got the equipment super late when I could not enter Sweden due to corona, had to send it overseas manually - which resulted in me handing in a somewhat underwhelming project.
I think it mainly gave me a starting point of working with sensors and setting up the hardware, further it has given some insights into different means of transfering data and the protocols to do so. I want to build a sensor that can help a small moving device follow a line - this will be my next project, but there is no way that this will happen during this course due to time constraints.
---
## Materials
List of all the material used
### Hardware
- Lopy4
- Expansion board
- Antenna
- Breadboard
- Jumper cables
- DHT11 digital humidity and temperature sensor
I bought all of the above in the package supplied by electrokit.
### Software
- Atom
---
## Computer setup
I am very surprised how easy it was working with pycoms products. The setup of the device worked just fine, and atom and the REPL interface contributed with some awesome mechanics. I did not have to update the firmware of the expansion board, rather than just updating the firmware. I used the pybit firmware for the final project, but I played around a bit with the legacy firmware as well. I already had Node.js on my computer, and did not have to install it.
Lora did not work for me, and I had to base my product through wifi and pybytes.
## Circuit diagram

Note that the sensor was plugged straight into the breadboard, but this poor-mans-version of a curcuit diagram did not allow for that.
The setup is mainly for development, when something a bit more handy than a breadboard would be needed for production.
Ground is connected from the expansion board to the breadboard, and then into the sensor. The 3.3V from the pycom device goes into the breadboard and then into the sensor. Note that the output pin 3.3 V is just enough to power the sensor. It also goes through an internal resistor. Then we have the signal cable that I have put to pin 23, it also goes into the right pin in the sensor.
## Platform
I am using the pybytes platform. A tool where one can partly code up application and logic, and partly recieve and display data. The coding as made in atom, locally on my computer whils the data was recieved in pybytes as two different signals. These signals where later displayed in two different dashboards.
If I would put it in i real database - then I think my choice would fall on google cloud - google storage - big query and finaly data studio for visualization. It is a subscription model and would hence cost a bit of money, but it works quiet neat I would say.
## Code
```typescript
import time
from machine import Pin
from lib.dht import DTH
th = DTH(Pin('P23', mode=Pin.OPEN_DRAIN), 0)
time.sleep(2)
while True:
result = th.read()
type(result)
while not result.is_valid():
time.sleep(.5)
result = th.read()
print('Temp:', result.temperature)
print('RH:', result.humidity)
pybytes.send_signal(4,result.temperature)
pybytes.send_signal(5,result.humidity)
time.sleep(5)
```
## Transmitting the data / connectivity
I used Wifi as wireless protocol, soley due to the fact that I could not get a Lora connection up and running. The transport protocols used was through wifi - but with mqtt protocol.
The MQTT is saving a lot of battery power, but it doesnt really matter right now since I have everything conneted to a electricity source. In case of further development I would use MQTT and minimize each byte that I am sending in order to save battery, something I havent done right now since I am sending 8 bytes with every transmition. Of course somethign like Lora and sigfox has a great range, unlike wifi that only has a couple of meters compare to up to 10 km with Lora.
## The data
The data is currently saved once every 5 seconds when it is a bit more fun when something is constantly happening. if I would create something like this for my boat, then I would probably fetch data once a day or something in that capacity.
The data is currently saved everytime a transmition comes in, hence once every 5 seconds give or take. It is just and interface and one cannot access the database straight away.
The following is a picutre of the temperature - not too much fun to look at when it is inside, and just over a couple of minutes.

The dashboard over the humidity, the outlier is when I breathed at the sensor, giving it an instant spike.

### Picture of the beauty
As I earlier mentioned, this project was meant to be something completely different but due to Corona I had to accept the fact that there was just not enought time to go through with it. I see this rather as a starting point. But other than that, I think it was a super nice way to get setup with the pycom, start brushing up on electronics, and create a small application.
