---
# System prepended metadata

title: Weather thermometer with online display

---

# Weather thermometer with online display

###### by Niklas Andersson (na222xz)

For this project a weather termomether was built using the Lopy4 and a MCP9700 sensor. The measured data was sent to Pybytes using Wi-fi and displayed in a chart. 

The estimated time for the project is about 5 hours if you're new to IoT going down to about 1 hour if you're experienced and have most of the basic set up already.
## Objective

The purpose of this project was to build a weather thermometer which could display how hot it is, and has been, in a chart. 
I chose this project for two reasons. The first being convience. The temperature sensor was included in the sensor bundle recommended from Electrokit and therefor it was natural to use it in the project. 
The second reason is connected to it's purpose. Me and my roomates have a balcony with windows that get really hot when it's sunny outside. We have been speculating for over a year how hot it actually gets and how much the temperature differs from a sunny day comapred to the same night or a colder day. 
The purpose was for us to be able to scratch our curiosity-itch with some statistics and get answers to our questions. 
Besides the information about how hot it actually gets the project also gives insights to how you can start working with sensors and microcontrollers. 

## Material

- Table

| Product              | Quantity | Purchased  | Price        |
| -------------------- | -------- | ---------- |:------------ |
| LoPy4                | 1        | Electrokit | ~390 SEK     |
| Expansion board      | 1        | Electrokit | ~180 SEK     |
| Breadboard           | 1        | Electrokit | 59 SEK       |
| USB 2.0              | 1        | Electrokit | 39 SEK       |
| MCP 9700 Temp sensor | 1        | Electrokit | 8 SEK        |
| Wires                | 5        | Electrokit | < 1 SEK/Wire |

Lopy 4 is a micropython-pragrammable IoT platform. It is easy to work with and it works with LoRa, Sigfox, WiFi and Bluetooth, giving the user a lot of options. This is the "machine" that makes everything work, it's this device that connects everything and make something out of it.
![](https://i.imgur.com/4Z2782T.png)

The expansion board is used to connect the Lopy4 to the sensor and to give it power.
![](https://i.imgur.com/ICpIu6b.png)

Breadboard and wires. The wires functions is to connect the sensor to the Lopy4, through the expansion board. The breadboard is used to make it easier to structure the wires and sensor but it not a must.
![](https://i.imgur.com/23JLfup.jpg)
![](https://i.imgur.com/ins7ip8.jpg)

The MCP9700 temperature sensor is what senses the temperature in the room. The Lopy then interprets the sensors output. 
![](https://i.imgur.com/4hUkZUK.jpg)

The USB 2.0 is used to power the Lopy4 and is connected to the expansion board. 
![](https://i.imgur.com/DHqzMXM.jpg)


## Computer setup

The IDE i chose was Visual Studio Code since i have used it before, Atom is also an option. You can download VS code here: https://code.visualstudio.com/. You may also need to download Node.js if you are using VS code and you can do that here: https://nodejs.org/en/. 
Once that is done you need to download the PyMakr extension to VS Code. Once you have opened VS Code there is a button to the left with four squares on it, press that and then search for PyMakr. When you have done that you're ready to continue.

The next step is making sure your firmware, the Lopy4 and expansion board, is up to date.
First, the expansion board. Before connecting your Lopy to the Expansion board, you may update its firmware. The expansion board should be up to date (which mine were) but if you have problems with the set up you might need to update the expansion board firmware. You can follow Pycoms instructions on how to do that here: https://docs.pycom.io/index.html.

Now onto the Lopy4 itself. To update the firmware on the Lopy4, you first need to connect the module to the expansion board. The small white square (surrounding the LED) on the LoPy4 should be positioned over the USB socket on the expansion board and then you simply click them together, a bit like LEGO.
When the module is attached to the expansion board, you are ready to update the firmware. Instructions on how to proceed with this can be found here as well: https://docs.pycom.io/index.html.


Once everything is done you can write your code and upload it to the Lopy4 by simply pressing the Upload button shown below (this is the PyMakr extension) or first All commands and then "Upload project".
![](https://i.imgur.com/n6GOZMt.png)

## Putting everything together

This is how the wiring looks:

![](https://i.imgur.com/ACUBuk7.png)
The green wire is connected to P16 on my extensionboard, this picture is on a different but very similar version and everything else is accurate. You could also use only one blue and red wire and remove the "middle man", I do think that this way made it more clear to me how it's connected though.
For more information on how the sensor works, check out https://learn.adafruit.com/tmp36-temperature-sensor .

## Platform
For this project I used PyComs own platform PyBytes. It's a really neat option which let you keep track of all of your Pycom devices and it's really easy to use as well. Pybytes allows you to visualize the sensor data with customizeable graphs. 
Pybytes is free to use and stores your data in a cloud for 30 days, which is plenty for this project but perhaps not always suitable. 
In this project I really prioritized simplicity and Pybytes is just that.

## The code
This project is simple and the code consists of two files, one boot.py which connects the device to the Wifi and one main.py which recieves the sensor data and sends it to Pybytes once every hour. No lib.
You can read more about how ypu connect to Wifi here: https://docs.pycom.io/tutorials/networks/wlan/

Boot.py
![](https://i.imgur.com/fP6Z0Kc.png)

Main.py
![](https://i.imgur.com/NPaW7XO.png)


## Transmitting the data / connectivity

The data is, as mentioned above, transmitted using Wifi. I chose Wifi since the device would be located in my apartment where the connection is good and I have some future projects in mind which require the use of Wifi so this was a good learning opportunity.
If you wish to use a more batteryefficient alternative to Wifi I would recommend trying Lora, you can read more about that here: https://docs.pycom.io/tutorials/networks/lora/

The data is transmitted using Pybytes own functionality as you can see on row 12 in the picture above. The data is transmitted once every hour (or once every 3600 seconds) as you can se on row 14 in the picture above. If you wish to change the timeframe in which the data is sent, you can simply change this number. 
Pybytes utilizes MQTT to send the data. MQTT is  a lightweight messaging protocol for small sensors and mobile devices and suitable for IoT.

## Presenting the data
The dasboard is really easy to build and allows the user to customize some aspects like how often the recieved, what kind of graph to use and if you want to fill the graph with colour and show the points. More information on how to set up and customize your dashboard can be found here: https://docs.pycom.io/pybytes/dashboard/

Every transmitted signal (that is recieved) is stored for 30 days in Pybytes cloud storage. 


Below is a picture of how my graph looked like for a day, showing that the temperature was rather steady around 25 degrees celcius.
![](https://i.imgur.com/Zqh2Dna.png)


## Finalizing the design
The picture below shows my finished project. It worked out great and does what it was supposed to do. This project was more about getting my feet in the IoT-water and getting mor knowledge about all of the options that are out there in the IoT-world. 
I'm pleased with how the result turned out but if I was to continue on this project I would change the sensor to one that is a bit more accurate, when sending the sensor data within a couple of seconds the temperature could shift up two degrees which is quite a difference. I would also like to create a case to put the device in so it looks better. Finally I would probably extend the project further and add more functionality like a notification when the temperature is at a certain degree or something along those lines.   

![](https://i.imgur.com/5bgiz16.jpg)


