# Project IoT - Which is the optimal bedroom during summer?
**Frida Forssell - *ff222kf***
This project is about measuring the temperature in different bedrooms in the house, at different floors. This, to see whether the temperature differs a lot or not depending on where the room is located in the house. But also to conclude where the optimal bedroom is located during summer. For the measurements a temperature sensor was used, MCP9700.
The estimated time for the tutorial is maximum 1 hour.
### Objective
The reason why I chose this project was because when I'm home during summer, visiting my family, I claim that I have the best bedroom since it is cold even during summer times. My bedroom is located in the basement and my sister and mum on the other hand complain about the heat in their bedrooms and both of their bedrooms are located upstairs. Thus, I wanted to see if there was a big temperature difference between the three bedrooms or not.
The main purpose for this project was to learn more about IoT. The project also gave me a better insight that it is pretty easy to send a lot of data through WiFi and then be able to analyse and interpret the data using Pybytes. But the drawback with this project is that it may also have given my sister an insight into how much cooler my bedroom is during the summer and thus there is a risk that she will take my bedroom until next summer.
### Material
* **LoPy4** - can be programmed using MicroPython
* **Expansion Board** - connect the LoPy4 to the expansion board and a micro USB cable.
* **Temperature sensor MCP9700** - measures the temperature
* **Jump Wires (5 pcs)** - connects the expansion board with the breadboard
* **Breadboard** - where the temperature sensor was connected
* **Micro USB cable**
I bought a kit from electro:kit for this course, 949 kr. In this kit everything needed for this tutorial is included. [:link:][Electrokit]
[Electrokit]:https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/
### Computer setup
Chosen IDE for this project was Visual Studio Code, since I was familiar with the program from before.
**Steps for the computer setup for this tutorial:**
1. Download Visual Studio Code [:link:][VisualStudioCode]
2. Install Pymakr package [:link:][PymakrPackage]
3. Install Python on your computer (I already had Python installed) [:link:][PythonInstall]
4. Connect to Pybytes [:link:][PybytesConnect]
[VisualStudioCode]: https://code.visualstudio.com/docs/setup/setup-overview
[PymakrPackage]:https://docs.pycom.io/gettingstarted/software/vscode/
[PythonInstall]:https://www.python.org/downloads/
[PybytesConnect]:https://docs.pycom.io/pybytes/gettingstarted/
To then be able to run the code when measuring the temperature, I connected the expansion board via micro USB to my computer. In Visual Studio Code’s Terminal I could see that the connection was established. Then I confirmed that the connection between the LoPy4 and Pybytes also was established. Finally, I pressed the button “Run” in Visual Studio Code and data was sent and stored in Pybytes.
### Putting everything together
How to put everything together for this tutorial, see Figure 1. The drawn lines in Figure 1 represent the jump wires as shown in Figure 2 below.

*Figure 1.* Picture of the connections done for this tutorial.

*Figure 2.* Picture of the actual connections with jump wires.
### Platform
The selected platform for this tutorial was Pybytes. Using Pybytes means that everything is stored in a cloud, which makes it possible for me to access the data from every single device online. Pybytes let you store data 1 month for free, which is the version I used for this tutorial. Another advantage of Pybytes is that it offers different tools for visualizing data, which makes it easier to analyse your data directly.
### The code
```python=1
import time
import machine
adc = machine.ADC(bits=10) # Get the data from the temp sensor
apin = adc.channel(pin='P16')
while True:
millivolts = apin.voltage() # Reading the sensor
temp_celsius = (millivolts - 500.0) / 10.0 # Convert to celsius from millivolts
pybytes.send_signal(3, temp_celsius) # Send signal to pybytes, the signal number was changed between the measurements
print(temp_celsius)
time.sleep(60) # Measure temperature every 60 seconds
```
### Transmitting the data
The data was with an interval of 60 seconds and the wireless protocol used for the tutorial was WiFi. The transport protocol used was MQTT since the command pybytes.send_signal was used in the code for transmitting the data.
### Presenting the data
Common to all three measurements was that data was sent every 60 seconds to Pybytes database. Below are pictures of the three measurements.

*Figure 3.* The night temperature in the basement. Measured between 0 am - 8 am.

*Figure 4.* The night temperature upstairs. Measured between 1 am - 10 am.

*Figure 5.* The night temperature upstairs. Measured between 1 am - 10 am.
### Finalizing the design
The summary from this project is that there is a big difference in temperature if the bedroom is located in the basement or upstairs in the house. In the basement the temperature is about 20°C, see Figure 3. In both of the bedrooms upstairs, the temperature never goes below 25°C and the average temperature there is almost 27°C during night in both of the bedrooms, see Figure 4 and 5.
One limitation with the project may have been that I didn't take into consideration the actual temperature outside. This is something that could have been improved since that affects the temperature inside. On the other hand, during the three nights I measured the temperature in the three different bedrooms, the temperature outside was similar so that shouldn't affect the result too much. Optimal would have been if I had equipment to measure the temperature in the three bedrooms at the same time, during the same night. Another improvement could also have been that I could have measured the night temperature in the bedrooms more than one night to get a more reliable result. I could also have measured the temperature in the three bedrooms during the same time interval.
To conclude, the optimal bedroom for a good sleep during summer times in my family’s house is the bedroom located in the basement. Since there is almost a 7°C difference in temperature during night if the bedroom is located upstairs or in the basement.