---
# System prepended metadata

title: Tutorial on how to build a mini weather station for indoor usage

---

# Tutorial on how to build a mini weather station for indoor usage

This project is developed to create a better understanding of humidity at home.

With the help of some hardware and software and a bit of coding, we will create a small weather station at home that can read temperature and humidity. Then, the unit's built-in LED lamp should glow red, green or blue depending on the level of humidity. The data will also be sent via WiFi to a server that visually summarizes data over a period of time

### Created by Zidan Islam (zi222ai)


## Always have the right humidity level at home!
When applying humidity in the air, it is important to maintain the recommended level. The body feels best in humidity between 40-50%. To prevent dust formation and the spread of airborne particles remaining in the air, humidity in the air should be below 45%. Bacteria thrive in 55% or higher, and at a humidity of over 70%, mold can be formed. Proper humidity helps reduce flu symptoms and can shorten illness days

## The estimated time for this project
This project is designed for beginners  and can be done quite easily. However, it requires some basic knowledge of IoT, coding language (micro python) and general interest in the technology. Whit that in mind this project will take approximately 50 hours to complete.

# Objectives

## Why choose this project?

By developing this project helps us to understand the importance of humidity level. To prevent dust formation and the spread of airborne particles remaining in the air.

## Purpose of the project
The purpose is to have a good air quality at home for reducing for example airborne bacteria which is very important at this moment during the ongoing pandemic Covid19 2020. By having the right level of humidity we can ensure a better lifestyle at home.

## Project insight

This project gives a brief insight of the exciting world of Internet of Things in general, the power of programming with micro python which is based on (python) and collecting and visualizing data for home temperature  & humidity.

# Material
Following are the materials needed for this project:

* Pycom lopy4 
* Breadboard
* DHT-11 temperature & humidity sensor
* Micro USB cable
* Wires 

**Pycom lopy4** - The LoPy4 is Micropython-programmable quadruple bearer board. It works with LoRa, Sigfox, WiFi and Bluetooth, making it an exceptional enterprise-grade IoT platform.

**Breadboard** - A breadboard is a simple device designed to let you create circuits without the need for soldering. They come in various sizes, and the design can vary, but as a general rule they look something like this:

**DHT-11** - Temperature and humidity sensor

* Low cost
* 3 to 5V power and I/O
* 2.5mA max current use during conversion (while requesting data)
* Good for 20-80% humidity readings with 5% accuracy
* Good for 0-50°C temperature readings ±2°C accuracy

**Wires** - Cables to attach the pycom with other modules and sensors

**Micro USB cable -** For power


## Where the materials were bought
* LNU - 1DT305 Tillämpad IoT - LoPy4 and sensors     bundle https://www.electrokit.com/en/product/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/, 995.00 SEK
* DHT-11 sensor
https://www.electrokit.com/en/product/temp-moist-sensor-dht11/ 39.00 SEK

### Total material cost 1 034.00 SEK

# Computer setup
This project was created using macOS, if you have a windows pc the computer setup might differ.

You need a IDE for writing the code, I used (ATOM) Download LINK --> https://atom.io/

After the installation you need to install a "pymakr" addon. Follow the steps --> https://docs.pycom.io/pymakr/installation/atom/

You might need to update the hardware. Here is a guide for downloading the updating firmware and step by step guide for the update -->
https://docs.pycom.io/gettingstarted/installation/firmwaretool/


# Circuit diagram

It is important that you wire the cables in right way. Otherwise you can damage your hardware. You can find more information in here --> https://docs.pycom.io/gettingstarted/connection/lopy4/

![](https://i.imgur.com/hHbmE8j.png)

# Platform

Pybytes is a cloud-based platform. The free version of Pybytes will be sufficient for this project. By using the Pycom updater, it was possible to force update Pybytes registration and follow the instructions given when running the firmware updater tool. My Wi-Fi were added to Pybytes (where a free account is needed), and the Pycom device added, and connected to the Wi-Fi in the Pybytes account. The Activation code given in Provisioning at Pybytes were pasted in the Pymakr terminal in Atom  to make it possible to send data from the program ran in Atom to Pybytes, and visualize it in a created dashboard.


# The code

```python=
import time
import pycom

pycom.heartbeat(False)
pycom.rgbled(0xff00)

from machine import Pin
from dht import DHT # https://github.com/JurassicPork/DHT_PyCom


th = DHT(Pin('P23', mode=Pin.OPEN_DRAIN), 0)
time.sleep(2)


while True:

    result = th.read()
    while not result.is_valid():
        time.sleep(.5)
        result = th.read()
    print('Temp:', result.temperature)
    print('RH:', result.humidity)
    pybytes.send_signal(1,result.temperature)
    pybytes.send_signal(2,result.humidity)


    if result.humidity < 40:
        print ("Oh no the humidity is getting low")
        pycom.rgbled(0x7f0000) # red. The red light will turn on if the humidity is too low

    if result.humidity > 55:
        print ("The humidity leves is too high")
        pycom.rgbled(0x0000EE) # blue. The blue light will turn on if the humidity is too high

    if  result.humidity > 40 and result.humidity < 50:
        print("The humidity level is good")
        pycom.rgbled(0x007f00) # green. The green light will turn on if the humidity is good

    time.sleep(5)


```
You need to import a lib for the dht-11 sensor which can be found in Github. Download these two files and you are good to go -->
https://github.com/iot-lnu/applied-iot-20/tree/master/sensor-examples/DHT11-22
# Transmitting the data
The data was transmitted through  WiFi. The signal is sent every second for the purpose of this tutorial. It would be more relevant to send data every half hour as the humidity does not change so quickly. As previously mentioned in the "platform" section, data is transmitted via wifi to pybytes that need to be connected to the device.

# Finalizing the design

### If the humidity level is between 40-50% then the green light will turn on.

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


### If the humidity level is over 55% then the red light will turn on.

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


### If the humidity level is under 40% then the blue light will turn on.

## Visualization of data

![](https://i.imgur.com/LJ3MQtM.png)
![](https://i.imgur.com/lT0PUkx.png)

We can after a time analyze the data and better understand how the humidity levels varies depending on time and season  of the year.

## Some thoughts

Finally, I think the project went pretty well. I was a beginner in this area so it was very educational and fun. I learned a lot about the IoT world and what opportunities exist in that industry. I will definitely continue to research in this area and experiment with new projects in the future. 

# Possible improvements

There are many different improvements areas in this project.
To begin with we could use different type of network like LoRa and combine with TTN to display values using Ubidots. For this project we only used a local wifi network. 

Other improvements are is to implement the hardware into a smart home system. For example, we could connect the pycom with a humidifier and insert some extra code to make the humidifier  run depending on the level of the humidity. For instance  if the humidity goes below 30% then it could automatically start to humidify the room so on and so forth. We could then send the data to a smartphone.

Finally, there are many ways to improve on this project and your imagination is the boundaries. If you are creative, enough you could do a lot of interesting project based on this.
