---
# System prepended metadata

title: Bedroom temperature and humidity sensor

---

# Bedroom temperature and humidity sensor
by Sofia Larsson Tibell (sl224aw)

This project describes how to easily setup a sensor that monitors the humidity and temperature of your bedroom.

Approximate time to setup: 3 hours

### **Objective**
Waking up with a too warm bedroom or a dry throat is standard in my bedroom and I've decided to try and change this. In order to determine if the changes that are made in the bedroom actually make a difference to the air, a way to monitor humidity and temperature is needed. By creating a device that monitors the humidity and temperature of my bedroom I hope to be able to more easily make changes in the room and improve sleeping quality. I might even be able to determine which methods are most effective for making changes to the temperature and/or humidity by analyzing the data.

### **Material**

List of material
| Material     | Link | Price | Specification |
|--------------|------|-------|---------------|
| LNU - 1DT305 Tillämpad IoT - LoPy4 Basic bundle | [link](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-basic-bundle/) |  849kr | The package contains: LoPy4 with headers(Microcontroller), Expansion board(Simplifies cable connection and USB power), Antenna(Improving WiFi connection), USB cable(To connect the board to power or the computer) |
| DHT11 sensor | [link](https://www.electrokit.com/produkt/temp-fuktsensor-dht11/)| 39kr | Measures humidity and temperature |
| Breadboard | [link](https://www.electrokit.com/produkt/solderless-breadboard-840-tie-points-2/)| 69kr* | For connecting the LoPy4 and the sensor |
| Jumper wires | [link](https://www.electrokit.com/produkt/jumper-wires-1-pin-male-male-150mm-10-pack/)| 29kr* | To connect components |
| 10k Ohm Resistor | [link](https://www.electrokit.com/produkt/resistor-metal-film-0-125w-1-10kohm-10k/)| 2,40kr* | Used as an adjustable resistor |

*The Breadboard, Jumper wires and 10k Ohm Resistor I got from a friend and therefore they cost me nothing however each item is linked so you can find where to buy it.

### **Computer setup for MAC OS**
In order to work with the device some computer setup is necessary. There are three things you need to install before starting. Firstly you need to install Node.js on your computer, which you can find [here](https://nodejs.org/en/). Secondly you need an IDE, in this setup the IDE is VSCode (Visual Studio Code). Instructions for installing VSCode can be found [here](https://code.visualstudio.com/docs/setup/setup-overview). Lastly you need the Pymakr plugin to help you upload, run or download your code on your device. Instructions on how to install the extension on your IDE can be found [here](https://docs.pycom.io/gettingstarted/software/vscode/)

Before going any further, it’s recommended to flash the firmware on the expansion board to the latest version, instructions are found [here](https://docs.pycom.io/updatefirmware/expansionboard/). [Pycoms tutorial](https://docs.pycom.io/updatefirmware/device/) can then be followed in order to make sure that the LoPy4 is updated. After this we are ready to follow one of [Pycoms basic tutorials](https://docs.pycom.io/tutorials/basic/rgbled/) to check that everything works.

### **Putting everything together**
When putting everything together we start with connecting the sensor to the breadboard. Starting with putting the sensor horizontal on the breadboard then connecting the ground(furthers to the right on the sensor) to the ground on the breadboard and then the power(furthers to the left) to the power on the breadboard. After this we connect the sensor to the expansion board by connecting a wire one step to the right of the power wire and connect it with P23 on the expansion board. We also put a 10k resistor as shown in the circuit diagram below. Lastly we connect the expansion board to the breadboard with the 3V3 to power and the GND to ground.

**Circuit diagram**
![](https://i.imgur.com/HvJj8wU.png)


I decided to go with a breadboard for the final product since it will be used inside and space is not an issue. The wiring is easy to take apart in case I want to use it in another project later.

### **Platform**
My first choice of cloud platform was [Pybytes](https://docs.pycom.io/pybytes/dashboard/), which I set up using this simple (tutorial)[https://docs.pycom.io/pybytes/gettingstarted/]. Pybyte's simplicity in regards of setup as well as the fact that it is free of charge and made for Pycom devices made it a natural choice. However, options for visualizing the data are limited. If i were to scale up the project I would use [Ubidots](https://ubidots.com/stem/) in order to have a broader range of visualizing the data and therefore making it easier to analyse in a later stage. Ubidots is also free of charge but you can receive more options if you choose a paid subscription. In regards to scaling the project Ubidots is also a better option since you can process and conduct analysis on the data directly in their cloud.

### **The code**
Since it was my first time working with hardware and code together, I decided to start with a project that teaches me the basics and has room for me to grow in the future. I am importing time, pin and DHT, since these are the libraries needed to use the pins and the sensor to grab the data that I am looking for. I have also set up my LoPy4 to be connected to the WiFi, and I have hidden the keys so that I could share the code without exposing sensible information. To assure valid measurements, I have included a sanity-check for the data. The code will basically wait till the DHT11 gives values that make sense, before it uploads them to Pybytes. I am still printing my result in the console, for debugging and also for future installation of a small screen.  
You can see my main-routine on the following image:
![](https://i.imgur.com/25DkSLW.png)


### **Transmitting the data / connectivity**
I have chosen to transmit my data using WiFi via MQTT protocol. This option draws more power then if I would have gone with LoRaWAN via TTN but since my device is located inside with stable access to power I saw no reason not to use WiFi. The device being stationary inside also means that distance is not a problem. This option also allows for more bandwidth which could be useful for future functions. 

Having no limitations in power and a strong WiFi connection I could have opted for more precision by sending more data points. However, the data I want to analyze is how the humidity and temperature is change over a longer time therefore it only transmits data every 10 minutes.

### **Presenting the data**
The data is preserved for one month in Pybytes and is saved as often as it is transmitted. The dashboard can present a few different kinds of graphs that you can somewhat be customize in regards to what part of the data to include.
![](https://i.imgur.com/KSAFKLa.png)


### **Finalizing the design**

Over these weeks I have learnd a lot, I have also discorverd several things I would do differently. First and foremost I would change the platform I use to [Ubidots](https://ubidots.com/stem/) because of it's broader range of visualizing the data as well as better options of processing and conducting analysis on the data directly. Futhermore, I would install a small screen on the device in order to easily check the current values instead of having to access the platform. All over I am happy with the results. It is simple but I had no prior experience working with hardware and now I have my first working device. To build a basic understanding of IOT was my personal goal for doing this project and I feel like I have achieved that. Finally, here is a picture of my small device.
![](https://i.imgur.com/AC0eBSt.jpg)
