---
# System prepended metadata

title: Tutorial on how to build a temprature sensor

---

# Tutorial on how to build a temprature sensor
# Room Temprature Sensor
Credentials:Phillipp Kwizera,Personnummer(19970226-0093),student username:pk222ph@student.lnu.se

**Project Overview**
This is a project that takes a few days to get setup and be able to build a room temprature sensor for my room.

**Objective**
The objective of this project is to be able to measure the temprature of my bedroom or any room of choice using the temprature sensor i am to build.With the help of this project i can be able to monitor  temprature flactuations  during different time points in the day for instance,morning och night.With the data obtained i can then know weather  i need to make a few adjustments in my room in order obtain an optimum temprature.

**Materials**


| Item            | Figure | Use                                                      | Source                                                             |     |     |
| --------------- | ------ | -------------------------------------------------------- | ------------------------------------------------------------------ | --- | --- |
| LoPy4           | 1      | Quadraple network microPython enabled development  board | https://pycom.io/product/lopy4/                                    |     |     |
| Expansion board | 2      | Attachment for LoPy4                                     | https://pycom.io/product/expansion-board-3-0/                      |     |     |
| BreadBoard      | 3      | Connecting cicuit compnents                              | https://www.electrokit.com/produkt/kopplingsdack-400-anslutningar/ |     |     |
| Jumper wires                |  4      |  Connecting element on breadboard                                                        |  https://www.electrokit.com/produkt/kopplingstrad-byglar-for-kopplingsdack-mjuka-65st/                                                                  |     |     |
| TMP36 TO-92     | 5      | Centigrade temprature sensor                             | https://www.electrokit.com/produkt/tmp36-to-92-temperaturgivare/   |     |     |

**Fig.1**
![](https://i.imgur.com/h6JSVcM.png)

**Fig.2**
![](https://i.imgur.com/b3zAttB.png)

**Fig.3**
![](https://i.imgur.com/56RhZ2D.jpg)


**Fig.4**

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


**Fig.5**
![](https://i.imgur.com/EOAySs9.jpg)

**Computer setup**
-For this tutorial i am using the Atom IDE which can be downloaded for the official ATOM website.
-After downloading Atom i install it, on Install page, via Atom > Preferences > Install,the pymakr pycom plugin.

-pymakr enabels us to be able to communicate with the pycom board using the REPL command line
-To flash the lopy4 firmware with latest firmware,i download the update tool from https://docs.pycom.io/gettingstarted/installation/firmwaretool/.
-This is then installedand the pycom device is flashed with the latest stable firmware.


**Putting everything together**
-A TMP36 T0-92 sensor has 3 pins the power, analog signal and ground as seen in the figure below
![](https://i.imgur.com/1ckuBV2.png)
-The TMP36 pins are carefully connected to the expansion board with the help of the lopy4 datasheet
-All connections are done using jumper wires.
-For this tutorial i will use analog pin 16(P-16) on the expansion board as an input for the sensors analog signal
-The sensor is supplied power from the 3V source on the Lopy4 and ground on the Lopy4.
![](https://i.imgur.com/piAk9Uo.jpg)

**Platform**
For this project i use the pybytes platform which is a free cloud based device management platform for all pycom development boards and modules.The pybytes platform offers easy integration with other cloud based services like Amazon web services and azure which can be helpfull in the scaling up of an idea.

**The code**

```
import machine
import time
from machine import Pin

#both the machine and time module are imported

adc = machine.ADC()
#machine object is instanciated

#configure analog input on pin 16
apin = adc.channel(pin='P16')

#continous loop that reads the analog input prints it and send signal to pybytes platform via wifi

while True:
  millivolts = apin.voltage()
  #voltage is converted to degress celcius acording to TMP36 datasheet.
  degC = (millivolts - 500.0) / 10.0
  degF = ((degC * 9.0) / 5.0) + 32.0
  pybytes.send_signal(16,degC)

  print(millivolts)
  print(degC)
  print(degF)
  #sleep after every one secound
  time.sleep(30)

```

**Transmitting the data / connectivity**
-The data is transmitted  every   30 secounds using the WIFI protocal.
-I use the Wifi protocall because of my location which is out of range for both the Sigfox and LORA network. 
-From the above code i use the pybytes.send_signal(16,degC) function which had 2 arguments the pin number and the value which is the data i am sending to the pybytes platform


**Presenting the data**
-As seen in the figure below the data is represented in a dashboard with both a line and bar graph showing the hourly room temprature.
-The data is saved in pybytes for one month
-The temprature is represented on the y-axis while the time is shown on the x-axis

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


**Finalising the design**
In summary,the project went as expected as i was able to obtain the data required which was the room temprature of my bedroom.I think some adjustments that could be added to my project is maybe integrating other cloud services like AWS or Azure.I could also use more sensors to measure different things like humidity in the room hence making the project alittle more intresting




