# Temperature Measurement By Elin Asplund (Ea224ek), Applied IoT IDT305, Linné University My project will give a brief introduction in applied IoT through a temperature measurement setup. The summer is here and with a home office located in the sun direction I wanted a unit that simply show, if my homee office is too hot, based on my desired temperature of 23 degrees C. The unit will be able to read the temperature in the room initiated by a push button and vizualizing the data in pybytes but also by a led indication. Since I´m a beginner myself the tutorial is written on a very basic level. Time estimation to reproducing this project as a beginner is approx 3 hours. ## Objective I´ve chosen this project since I think it´s a very good project to get familiar with some of the very common functions and sensor like measuring temperature, use a push button and visualizing the data. It should also provide a good foundation, of hardware and software platforms, to later be able to expand and add complexity. ## Materials Material used in this project can be seen in the list below. This material can be found at several providers, but I picked electrokit for most of the parts because it was very convenient. I had macOS 10.5 as the operating system. | Material | Quantity | point of purchase | cost | | -------------------------- | -------- | ----------------- | ------- | | Pycom Lopy4 | 1 | electrokit.com | 350 SEK | | Pycom Expansion Board v3.1 | 1 | electrokit.com | 140 SEK | | USB 2.0 cable | 1 | electrokit.com | 60 SEK | | Li-Po Battery 3,7 V | 1 | kjell.com | 100 SEK | | Breadboard | 1 | electrokit.com | 60 SEK | | DS18B20 sensor | 1 | electrokit.com | 40 SEK | | Key switch module | 1 | electrokit.com | 20 SEK | | Jumper wires male-male | 8 | electrokit.com | 25 SEK | **Pycom Lopy4** is a Microphyton-programmable development board. Since it can be used with LoRa, Sigfox, WiFi and Bluetooth it´s well suited for IoT projects. To be able to connect sensors and program Lopy4 the **Pycom Expansion Board** is needed. The expansion board will also enable power supply by either a micro **USB connectio**n or a Li-Po Battery. The **Li-Po Battery** is used when the unit needs to be disconnected from the computer. The **breadboard** is used to build electronic circuits by connecting wires and components together. The board used does not require soldering. The chosen temperature sensor for the project is the **DS18B20 sensor module**. This sensor allows temperature measurement using digital serial bus. It consists of a single-bus digital temperature sensor,a LED and a resistor. To initiate the temperature measurement the **Key switch module** is used. It consists of a tactile push button switch ana a pull-up resistor. It will output a high signal when pressed. ![4](https://i.imgur.com/V4Rs9G4.png) Fig.1 Pycom Lopy [pycom.com](https://pycom.io/product/lopy4/?gclid=CjwKCAjw97P5BRBQEiwAGflV6RZ-nEFyxq2YWxA-K5tQI92VSxAf2p7yjBbl6ep0RslR6bggb7sKGhoCkR0QAvD_BwE) ![](https://i.imgur.com/SiWn4F5.jpg) Fig.2 Pycom expansion board [pycom.com](https://pycom.io/product/expansion-board-3-0/) ![](https://i.imgur.com/7XbCoMc.png) Fig.3 DS18B20 sensor module [elctrokit.com](https://www.electrokit.com/en/product/temperature-sensor-ds18b20/) ![](https://i.imgur.com/M69Soeo.jpg) Fig.4 Key Switch Module [elektrokit.com](https://www.electrokit.com/en/product/momentary-push-button-module/) ## Computer setup To get started I followed the steps below. **1. Update firmware on expansion board** Before you attach the Lopy4 to the expansion board it´s recommended to update the expansion board with the latest firmware. [link to instructions](https://docs.pycom.io/pytrackpysense/installation/firmware/) **2. Update firmware on Lopy4** As well as the expansion board the Lopy4 shall be updated with the latest firmware before continue with the programming. To update the firmware on Lopy4 you need to connect the Lopy to the expansion board and connect it to the computer with a micro USB **3. Upload an integrated development environment (IDE)** To be able to program and communicate with your lopy you need to download an IDE. Both [Atom](https://atom.io) and [Visal Studio Code](https://code.visualstudio.com) both have a plug-in,Pymakr, developed by Pycom to make the development environment for Pycom modules very easy. Hence I can recommend to use one of them. I had no experience of these before. But after been using Atom in this project, I think it worked very well. When I had installed the Atom IDE i added the pymakr plug-in. In Atom this is done in the core settings, install packages. ![](https://i.imgur.com/1fCzQUv.png) when that is done you can connect the device with the USB cable.The pymkr plugin shall then automatically connect the device. If not click on connect. ![](https://i.imgur.com/FVfs9tP.png) [pycom.com](https://docs.pycom.io/pymakr/installation/atom) If three arrows >>> can be seen, the device is connected and you can start uploading code to the device. It may be necessary to download some drivers,to be able to get the devices to be recognised. macOS and Linux does right now not require it, still check Pycom.com for the latest information. ## Putting everything together The setup of my device can be shown in the simple schematics below. ![](https://i.imgur.com/tlc2lsr.jpg) To be able to connect the sensors in the right way I used the data sheets of each sensor that can be found at the suppliers website. The pinout of the Lopy4 can be found [here](https://![.imgur.com/V757wlw.png]). Since this was a prototype the robustness of the wiring is low, and it could easily fall apart, why it shall only be used in controlled environment. Don´t forget to disconnect all power sources before connecting sensors. Black lines= jumper vires for ground (GND) Red lines= jumper vires for Voltage in (Vin) Blue lines= jumper vires for data connection from sensors to Lopy. The DS18B20 was connect to pin10 and the key switch button to pin14. ## Platform Since this was a beginner project I didn´t had so many requirements of the platform. I wanted it to be easy to get started with, and I wanted to be able to visualize the data in a simple way and to be free of charge. I tried two cloud platforms [Pybytes](https://pybytes.pycom.io/) and [Ubidots](https://https://ubidots.com/). I really liked visualization possibilities and functionality options in Ubidots. However I chose to end up using Pybytes, as I started with, to explore it a little bit further before swithing to another platform. Pybytes is free and ubidots have a free account but with reduced functionality, if you want all features you need to have a paid subscription. ## The code the structure of the code is like follow /main.py /boot.py /lib/onewire.py main.py ![](https://i.imgur.com/uxkzHi5.png) ![](https://i.imgur.com/liq8uuJ.png) the complete code can be found at [Github](https://github.com/easplund/temperature_device) ## Transmitting the data / connectivity My first thougth was to use LoRa as the wireless protocol, but it turned out that I was not within any network. And at the moment I did not have the opportunity to set up my own hence I chosed to use WiFi, via MQTT protocol. This will also work fine for this device and application since it will be located in my home with a stable WiFi connetion. The device will only be connected to power and send data when in use and not be in idle mode for extended periods. ## Presenting the data I used Pybytes also for the visualizing of the data, this since the project only included one sensor value and did not need several different visalization possibilities. Further it was very easy and convienient. The data will be saved in the database each time you initiate a measurement, i.e when you push the button, and saved for 30 days in Pybytes. ![](https://i.imgur.com/HnyiXqa.png) ![](https://i.imgur.com/k11tsu9.png) ![](https://i.imgur.com/zpuPlg9.png) ## Finalizing the design ![](https://i.imgur.com/9W2SW9z.jpg) blue light between the measurements ![](https://i.imgur.com/1xNm4Ku.jpg) red light indicating that the temperature is above 23 degrees. Since it was a beginner project the main focus has been on getting familiar with the different platforms and hardware setup. I think the project was not only a lot of fun but also a really good way to get started with smaller IoT projects, and create a good foundation for continuing to explore the area. Further I think to write your own tutorial was very valuable. What I would like to do in a different way is to build the code in a different way from the beginning, it felt like it became a lot of add-on and not so much reusable code. Further I would also have added more sensors as well as some continuous measurements that did not require initialization of the push button. Unfortunately, the time for the project become more limited for me than expected and I was not able to work with it than very short moments, and I think it would have been good to get a few more hours at each time to reduce the start-up time.