---
# System prepended metadata

title: Temperatur and humidity control for the summercabin

---

### **Date:** 2023-07-03
### **Author:** Sebastian Speles, ss226hb
### **Course:** Introdcution to applied IoT - 1DT305 at Linnaeus University

# Project overview and objective

I am undertaking a project to create an IoT device for my summer cabin. The device will measure temperature and humidity, and transmit the data to a 4G-WLAN router. This will enable me to share the real-time data with my family and friends, whether they are visiting or simply curious about the current weather conditions at the cabin. I anticipate dedicating approximately 10 hours to this project over a period of one week, although be prepared to invest additional time if necessary. As a beginner in programming, I am particularly excited to learn about IoT devices and micro Python. Working with my own micro controll unit will be an interesting aspect of this project.

# Project material
## List of materials

| Name                                          | Picuture                                      | Type                            | Specification | Cost                     |
| --------------------------------------------- | --------------------------------------------- | ------------------------------- | ------------- | ------------------------ |
| Raspberry Pi Pico WH                          | ![](https://hackmd.io/_uploads/rkXzewnOh.png) | Micro controller board                          | The Raspberry Pi Pico WH is a cool little micro controller board created by the Raspberry Pi Foundation. It's got a speedy processor running at 133 MHz, which is perfect for my project. It supports different programming languages like MicroPython and C/C++, so i could code it in a way that suited me the best and it even has built-in wireless LAN capabilities.            | Includeded in starterkit |
| MCP9700 TO-92 Temperature sensor              | ![](https://hackmd.io/_uploads/S1Chgw2_n.png) | Temperature sensor              | The sensor provides a linear voltage that is proportional to the measured temperature. The sensor has a wide measurement range, from -40° to 125°C, and it requires low power consumption.             | Includeded in starterkit |
| Digital temperature and humidity sensor DHT11 | ![](https://hackmd.io/_uploads/HJvzbvnOh.png) | Temperature and humidity sensor |  Includes a digital temperature and humidity sensor. The sensor generates a series of digital data that can be read using a digital input on a microcontroller. It will be the key to my IOT project.             | Includeded in starterkit |
| Clutch deck 840 connections                   | ![](https://hackmd.io/_uploads/rJG2MP2On.png) | Breadbord                       | A breadboard is a rectangular plastic platform equipped with a grid of small holes, enabling the construction of electronic circuits without the need for soldering.              | Includeded in starterkit |
| TLV49645 SIP-3 Hall effect sensor digital     | ![](https://hackmd.io/_uploads/Skc6YD3_2.png) | Hall effect sensor              | This sensor is designed to perceive and measure magnetic fields in its surroundings. Its output remains high when there is no magnetic influence nearby, but it pulls the output low once it encounters a magnetic field surpassing a specific threshold.              | Includeded in starterkit |


## Miscellaneous
| Name                                     | Cost |
| ---------------------------------------- | ---- |
| USB-kabel A-male – micro B 5p male 1.8m  |  Includeded in starterkit    | 
|                                          |      | 
| laboratory lead 30cm male/male           |  Includeded in starterkit    | 
| laboratory lead 30cm female/male         |  Includeded in starterkit    | 
|                                          |      | 
| Carbon film resistor 0.25W 330ohm (330R)     |  Includeded in starterkit    | 
| Carbon film resistor 0.25W 560ohm (560R)     |  Includeded in starterkit    | 
| Carbon film resistor 0.25W 1kohm (1k)        |  Includeded in starterkit    | 
| Carbon film resistor 0.25W 10kohm (10k)      |  Includeded in starterkit    | 
|                                          |      | 
| LED 5mm red diffuse 1500mcd               |  Includeded in starterkit    | 
| LED 5mm yellow diffuse 1500mcd               |  Includeded in starterkit    | 
| LED 5mm green diffuse 80mcd                |  Includeded in starterkit    | 
|                                          |      | 
| Photocell CdS 4-7 kohm                |  Includeded in starterkit    | 
| Tilt sensor                              |  Includeded in starterkit    |
| Magnet Neo35 Ø5mm x 5mm                  |  Includeded in starterkit    |

## Cost

I purchased the complete kit from Electrokit.com based on the recommendation from my supervisors, and I am extremely satisfied with both the price and the contents of the kit. It fulfilled all my project requirements perfectly, and the price of 399 SEK was very reasonable. I am grateful for the recommendation and pleased with the overall experience of using the kit for my project.
[*Electrokit.com starter kit applied IoT at Linnaeus University* ](https://www.electrokit.com/produkt/start-kit-applied-iot-at-linnaeus-university-2023/)

# Computer Setup

## IDE

I decided to use Visual Studio Code as my integrated development environment (IDE) for my project, even though I was already familiar with it for Python and javaScript programming. Since I learned by reading up on MicroPython, I discovered that it is known to be quite similar to Python. I thought it would be a seamless transition and a convenient choice to stick with my go-to IDE. This allowed me to leverage the familiar features and functionalities of Visual Studio Code. 
*To download Visual Studio Code for free just go to this link https://code.visualstudio.com/download*

## Flashing the firmware on Raspberry Pi Pico WH with Micropython firmeware


| Picture                                       | Instructions                                                                                                                                                                                                                                  |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://hackmd.io/_uploads/HJpkBu2O2.jpg) | Please hold down the white button indicated by the red arrow while keeping the micro USB cable connected to the Raspberry Pi Pico WH.                                                                                                         |
| ![](https://hackmd.io/_uploads/rkZlwunO2.jpg) | While continuing to hold down the button, connect the USB cable to your computer to flash the firmware. After approximately 2 seconds of holding the button, you can release it while keeping the USB connection intact.                      |
| ![](https://hackmd.io/_uploads/BkgJsexKn.png) | After you have flashed the firmaware on the Raspberry Pi Pico WH download the latest firmware for Micropython from https://micropython.org/download/rp2-pico-w/ and put the file on to the Raspberry Pi Pico WH and let it install itself to. |
| ![](https://hackmd.io/_uploads/HkV65u2_n.jpg) | Lets head to extions in Visual studio code and install Pymakr                                                                                                                                                                                 |
| ![](https://hackmd.io/_uploads/rkNrzl4Fn.jpg) | Now its time to connect the device using Pymakr. Navigate to the pymaker icon as shown in the picture. There u will find your connected device.                                                                                               |
| ![](https://hackmd.io/_uploads/B1TtXlEKh.jpg) | Find the lightning icon in the seriell USB-port under Devices and press it as shown in the picture, that lets me connect to the Raspberry Pi Pico WH                                                                                                                                     |
| ![](https://hackmd.io/_uploads/HyciNlEt2.jpg) | Then Press the ‘+’ , or if you don’t got a project active, there will be a blue box “Create project”. Press it. Lets chose a location for the project and save. Now we are ready to code the Raspberry Pi Pico WH |





## Installing plugins

Although Visual Studio Code is already my go-to IDE, I have installed multiple plugins to enhance my overall experience. However, the details of these plugins are beyond the scope of this report. For this specific project, I made sure to install the "Pymakr" plugin to facilitate my development process with MicroPython on the Raspberry Pi Pico WH.

![](https://hackmd.io/_uploads/HkV65u2_n.jpg)
*Figure 1* 

The developer mode in Pymakr proved to be highly beneficial, allowing me to work seamlessly with the code and update it directly to my Raspberry Pi Pico WH. I found this feature to be extremely convenient and efficient, and it greatly enhanced my development workflow. As a result, I am likely to continue using the same Pymakr extension for future projects due to its effectiveness and the positive experience it provided.

![](https://hackmd.io/_uploads/Hy8IDFhOh.jpg)
*Figure 2* 



# Connetion setup

## Setup
The displayed in Figure 3, illustrates the wiring configuration. It is important to note that the Digital temperature and humidity sensor DHT11 is depicted with 4 pins in the diagram, while in reality, it has 3 pins. Therefore, when examining the diagram, disregard the first pin from the left which is not connected to any wiring. Again all the connected cables are correct if you ignore the unconnected first pin from the left.

As shown in Figure 3, both the DHT11 digital temperature and humidity sensor and the Raspberry Pi Pico WH are connected to a breadboard. This connection is achieved by utilizing a 30cm male-to-male laboratory lead wire. The red lead wire is used for power, the yellow lead wire is used for data, and the black lead wire is used for ground.

## Circuit diagram

![](https://hackmd.io/_uploads/BJwcrbetn.jpg)
*Figure 3* 

# Chosen platform and presenting the data

## Azure virtual machine
First, I attempted to set up my platform on a virtual computer using my Azure student account. However, I quickly realized that this approach was too time-consuming and challenging given my current level of knowledge. Therefore, I decided to postpone that idea for future use. Nonetheless, during the process, I did gain some knowledge about virtual machines on Azure.

## Adafruit
While exploring the roadmap, I made the decision to go with Adafruit, which I found to be quite appealing. I proceeded to set up four feeds on my dashboard (refer to Figure 3). These feeds include the latest temperature reading, the current humidity level, as well as historical data for temperature and humidity spanning the last 30 days.

![](https://hackmd.io/_uploads/r1G2CyXKn.png)
*Figure 3* 


# The code

## File structure

I used the following file structure, as shown in Figure 4. At the top level, I have a file named 'main' that handles all the communication with the Raspberry Pi Pico WH. Additionally, I created a directory where I placed smaller files that the 'main' file calls upon. For example, I have a file called 'WifiConnection' responsible for connecting to the router, a 'keys' file that stores all the necessary information for Adafruit, and an 'mqtt' file that handles communication between the Raspberry Pi Pico WH and Adafruit.

![](https://hackmd.io/_uploads/HkmErflK2.jpg)
*Figure 4*

## Main

### Imports
As shown in Figure 5, these are all the imports used in my project. However, for the purpose of this report, I will focus specifically on the 'Machine,' 'DHT,' and 'Network' imports.

Firstly, the "Machine" module is imported, enabling me to establish a connection with the Raspberry Pi Pico WH. This module provides necessary functionality for interacting with the board.

Additionally, the "DHT" module is imported, granting me the ability to utilize the DHT11 digital temperature and humidity sensor. This module facilitates reading data from the sensor.

Furthermore, the "wifiConnection" file in the "lib" folder is imported, which internally imports the "network" library. It's worth mentioning the importance of the "network" library, as it enables me to connect to wifi networks. This is particularly relevant since my Raspberry Pi Pico WH is utilized with a WLAN connection.

![](https://hackmd.io/_uploads/BJxnXzxFn.jpg)
*Figure 5*

### Code

Within Figure 6, the showcased function is responsible for measuring the temperature and humidity in my project. It accomplishes this task by utilizing the DHT11 digital temperature and humidity sensor. Furthermore, the function publishes the obtained values to designated feeds through the MQTT client.

To prevent any complications, I have deliberately implemented a 10-minute delay between each data push of temperature and humidity. This choice derived from a past experience where I encountered a ban from Adafruit due to excessive sensor updates.

![](https://hackmd.io/_uploads/H1Tmsfgt2.jpg)
*Figure 6*


## Lib folder

### WifiConnection
Within Figure 7, the showcased function is responsible for the connection to a Wifi-network and ensures a successful connection, retrieves the assigned IP address, and returns it for further use in the program. this function is later called in the main file.

![](https://hackmd.io/_uploads/H1yeRfeYn.jpg)
*Figure 7*

### Keys
I will not illustrat all this variabels, In summary, the provided code segment contains the configuration settings necessary for establishing a connection with the Adafruit IO platform, including server details, authentication credentials, client ID, and feed names.

### Mqtt

The 'MQTTClient' class provides the necessary functionality to establish an MQTT connection, communicate with an MQTT broker in my project i use Adafruit as broker, and handle incoming messages.

# Transmitting the data / connectivity
As i mention earlyer, to ensure that I don't get banned by Adafruit, I have set up my sensor program to send data every 10 minutes. I believe the weather conditions won't change significantly within this time frame.

I'm utilizing the Wifi capabilities of the Raspberry Pi Pico WH and have configured it to connect to a router that operates on 12 volts. Additionally, the router using a SIM card making it work in cabin where we use solar panels as elektrik and 4G as internet and that will allow me to use the Raspberry Pi Pico WH in my cabin.

For my transport protocol, I have chosen MQTT, which facilitates the efficient and reliable transmission of data. As my MQTT broker, I have opted for Adafruit. Currently, I haven't had the opportunity to explore Webhooks, but I plan to set up some interesting Webhooks later this summer. These Webhooks will enable me to receive notifications when the humidity reaches high levels.

# Presenting the data
For presenting the data i choice to use adafriut whit 4 feeds as u can se in figure 8 as i mentioned in the adafriut part. These feeds include the latest temperature reading, the current humidity level, as well as historical data for temperature and humidity spanning the last 30 days.

![](https://hackmd.io/_uploads/r1G2CyXKn.png)
*Figure 8*


# Finalizing the design
This is the assemble project figure 8, it works as i want it to. Whats left is to make a 3D case, solder the cabel and move it out to the cabin and make one more for the basement.

![](https://hackmd.io/_uploads/Hk9eAmgY2.jpg)
*Figure 9* 


# Final Thoughts

I think the Conclusion of, my IoT device project for the summer cabin has been a success. My objective was to create a device that measures temperature and humidity and transmits the data to a 4G-WLAN router that could be powered by solar panels, allowing real-time data sharing with family and friends.

The project materials, including the starter kit from Electrokit.com, proved to be suitable for the project requirements and offered good value for the price. The complete kit provided all the necessary components, such as the Raspberry Pi Pico WH, sensors, breadboard, and various other miscellaneous items.

Transmitting the data involved utilizing the Wi-Fi capabilities of the Raspberry Pi Pico WH and connecting it to a router. MQTT was chosen as the transport protocol, with Adafruit serving as the MQTT broker. To prevent excessive updates, a deliberate 10-minute delay was implemented between each data push.

Overall, my project successfully achieved its objectives, and the device is functional and ready for deployment in the summer cabin. The next steps for me is to solder the cabels and create a 3D case for the device to secure it and buy additional devices for different areas, such as the basement and attic in my house where i need to keep a check on humidity levels.

I truley believe this project has offered valuable hands-on experience with IoT devices. It has also showcased the potential of IoT technology in everyday life which was realy fun, allowing for remote monitoring and sharing of real-time data. I will probley build more fun IoT devices in the near future.