# A simple temperature measuring device using TMP36 By: Adiba Puspita Anggraini (aa225kt) tags: LNU,IoT,LoPy4,Pycom ## Project Overview This project describes how to construct a simple temperature monitoring device using Lopy and TMP36. These instructions includes turning on the RGB LED as well as adding a few lines of Micropython code to activate the device. If you're a novice like me and have all of the necessary materials, it should take you 3-5 hours to finish these instructions. ## The purpose of the project This project is my first ever IoT project. My goal with the project is to get a practical understanding of how to produce data from a sensor through a Sigfox network using Micropython to program the device. ## Material All materials used was part of [LNU – 1DT305 Tillämpad IoT – LoPy4 and sensors bundle](https://www.electrokit.com/en/product/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/), and bought on [Electrokit](https://www.electrokit.com/en/). **List of materials used:** 1. Pycom device (Lopy4) 2. Expansion board (3.1) 3. Temperature sensor (TMP36) 4. USB cable 5. Antennae 6. Jumper wire 7. Breadboard ## Software and hardware setup I started the process with downloading and installing the softwares while waited for the materials I ordered from Electrokit to arrive. I used my laptop with Windows 10 as OS to run Micropython. The expansionboard I used was Pycom Expansinboard v3.1. **Software** 1. I had to install Pycom Firmware Update on my computer in order to update the Lopy4 device. Once installed, I ran the program and followed [this](https://docs.pycom.io/updatefirmware/device/) instructions. 2. The IDE I used to support the software development is Visual Studio Code. Since I had no VSC downloaded on my computer, I had to download the latest version [here](https://code.visualstudio.com/docs/setup/windows). Once dowloaded, I installed the program by following [this](https://hackmd.io/a1Nq_9kqR0CZBrYL1xNJDg) instructions. 3. After the IDE is set, I installed Pymakr from VSC by going to the Extensions page -> Search for Pymakr, once it's found click on install. [Here is the complete instructions by Pycom](https://docs.pycom.io/gettingstarted/software/vscode/). **Hardware** I started by attaching the Lopy device to the expansionsboard, and then attach the antenna to the Lopy4 device. See the picture above for more details. I used an USB cable to connect my device to the computer. If you forgot to attach your Lora antenna and want to attach it now, make sure that the antenna is properly attached and the USB cable is unpluged from the computer. If you are not properly attach the antenna while having the USB pluged to the computer and have the Micropython running, you may destroy your device. ![](https://i.imgur.com/5ADWS9L.png) ## Putting everything together ![](https://i.imgur.com/nNeU9nR.jpg) ![](https://i.imgur.com/TevkQLR.jpg) ## Platform The cloud platform I used to show the data is Pybytes. The data can be access both from desktop and mobile application. To access the data on Pybytes, you need to create your account on this [page](https://sso.pycom.io/register?response_type=code&scope=profile&client_id=pycom&redirect_uri=https%3A%2F%2Fpycom.io%2Fwp-admin%2Fadmin-ajax.php%3Faction%3Dopenid-connect-authorize&state=d2f6b1a2a31e3d2987492ea8885c01ef) ## Code **main.py** The code in the `main.py` file is the main code that run the Lopy4 device. To convert millivolts into temperature I used `celsius = (millivolts - 500.0) / 10.0` and `time.sleep(11*60)` for the device giving the data every 11 minutes. ``` import machine import time adc = machine.ADC() apin = adc.channel(pin='P16') while True: millivolts = apin.voltage() celsius = (millivolts - 500.0) / 10.0 print(celsius) pybytes.send_signal(1, celsius) time.sleep(11*60) ``` **boot.py** My `boot.py` is empty since I do not need any code in it for this project. **keys.py** `keys.py` is simply to save the wifi ssid and its password to connect the sensor to the network. ![](https://i.imgur.com/5KhHWh3.png) ## Transmitting the data Because this prototype is meant to be portable and consume less power, which is crucial for embedded devices, the project is using SigFox to facilitate data transfer over a larger range. I intent to use Lora for my network, but I tried SigFox, I found it has better network coverage than Lora, so I decided to use SigFox at the end. The picture below is showing the network coverage in my area. ![](https://i.imgur.com/O4DXFeU.png) The following picture is showing the data sent through SigFox ![](https://i.imgur.com/KDY6EfV.jpg) I used the following script in `main.py` t connect with SigFox. ``` import time while True: #Select a value to send, #perhaps before this you've read from a sensor value = 5 #Send the value pybytes.send_signal(1, value) print("sending: {}".format(value)) #Sending data once every 11 minutes time.sleep(30) ``` ## Presenting the data The data is easily accessible on the Pybytes page. ![](https://i.imgur.com/WPPplmH.jpg) ![](https://i.imgur.com/4JEsSaZ.jpg) ## Conclusion ![](https://i.imgur.com/btET8QA.png) This simple project have given me the basic knowledge of how to program a device and connect the sensor that is attached to it and make it send its data through a network. This project has as well motivated me to improve my technical skills on IoT.