# How to build an indoor thermometer to monitor your room temperature and how to make a green LED light up as long as temperature is acceptable, or red LED light when too hot/cold By Amanda Heikki - ah225mw Project description: This is a tutorial on how you can create a very simple indoor thermometer with LED guidlines. This project tutorial includes instructions on how/what hardware to use as well as how to get the device connected to your computer. This will be done using Pycom togheter with the IDE Visual studio code. To be able to get any use of the data from the sensors, the tutorial will also include instructions of how to use Pybytes to acess the data via wifi. Time estimation: It's depending on previous experience and if you already have the firmware/IDE and are registrated at Pybytes. For an absolute beginner as me i would say between 2-4 hours. # Objective I choose this project because it seemed perfect for a beginner like me since I have no previous experience. It will be a great start for me to get a better grip of IoT and will be a great entry to further developing. I bought a start bundle with everything you might need for an IoT project and since it included a temperature sensor I decided to stick to that. After getting the temperature sensor to work and send accurate data I decided to test the LED lights that also was included in the bundle and decided to integrate them with the temperature sensor. # Material Price estimation: I bought the LoPy4 and sensors bundle at Electrokit for about 93€ (949SEK). For this project you wont need everything in the bundle so the price can be lower if you sort out the things you need seperately. [Find the LoPy4 and sensors bundle here](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/?fbclid=IwAR2nq9GgZV3BLr-acCW3mR6mpur2fodpW5bO6S5f93DNbfc_dLwt_2A3Du4) | Components| Description | | -------- | -------- | | Pycom LoPy4 | Development board, programmable with micropython | | Expansion board | Used for connecting the sensors | | Micro USB cable | Needed to give power to your unit and connect it to the computer | | Temperature sensor | For measuring the temperature | | Breadboard | Making it easier to connect sensors to the expansion board without having to solder | | Jumper wires | For connection between the device and sensors | | 2 x LED ligths | I choose one green and one red, for acceptable/non acceptable temperature | | 2 x Resistors | The resistors are needed to regulate the electrial flow to the LED lights | # Computer setup For the computer setup the two first tutorials offered by LNU was very helpful, links below. [Tutorial 1](https://hackmd.io/@lnu-iot/rk4qNlajd) [Tutorial 2](https://hackmd.io/@lnu-iot/BJnuGmJh_) The steps are the following: - Connect your LoPy4 to the expansionboard and attach the micro usb cable to the computer. There was no need to update the firmware for the expansion board since it was new. - Install Node.js on your computer. I used the macOS installer but you choose the right one for you OS https://nodejs.org/en/download/ - If you dont have and IDE (development environment) you need to install that. I chose VS code since I already had it installed and are used to it. You can choose either VS Code or Atom https://code.visualstudio.com/download https://atom.io/ - You also need to install the Pymakr plugin to be able to communiacte with your Pycom device. If your using VS code you might need to click "All commands" and search for: Pymakr > Extra > List Serial Ports and then chose Global settings. Then it should work fine. https://marketplace.visualstudio.com/items?itemName=pycom.Pymakr (for VS code) https://atom.io/packages/pymakr (for Atom) - Create a new (empty)folder anywhere on your computer and open it in your IDE. Then you create a new sheet in your projectfolder naming it main.py and from there you can start programming! # Putting everything together For the wiring its a good idea to use different colors to be able to tell them apart. ![](https://i.imgur.com/rDQiRzL.jpg) *Simple circuit diagram made in google draw* Explanation of the diagram: - The white wires in this example is to connect the sensors to the GND pin. I connected these to the negative side on the breadboard because I have two different sensors that both needs to be powered by the GND pin. - The green and yellow are both for connecting to the Port pins, to later be able to program them in your code. Here the green is connected to P16 and yellow to P10 and P11. - The red cable is for connecting your temperature sensor to the 3V3 pin. - Green/Red dots are the LED lights. - Black dot is the temperature sensor. - The orange "dots" are the resistors, connected to the same spots as LED lights and on the negative side of the board to regulate the electrical flow. Pycom has a detailed Pinout diagram for LoPy4 if you are interested to learn more, can be found in this pdf: https://docs.pycom.io/gitbook/assets/lopy4-pinout.pdf # Platform I used Pybytes as a platform since it seemed easy and compitable with the device. It was also easy to get started. First you need to be registered and logged in at pybytes, then configure a network. I decided to use WIFI since it works automatically with the LoPy4 and it was enough for this little project. You enter your WIFI name and password - be careful to write the correct ones! I didn't get a connection to my device at first and later found out that I had the wrong WIFI name. You then click "add device" and follow the steps. I chose the offline mode when provisioning my device. It is very well described and easy to follow. Just remember to close your IDE program if it is open on your computer - i first failed with provisioning and discovered that VS Code was open. ![](https://i.imgur.com/5qNcESD.jpg) *Here you can see where you configure your network/add your device* # The code My code is very easy and for this project (and as a beginner) a boot.py file is not necessary, neither did I need any libraries for the sensors. ``` import time import machine from machine import Pin adc = machine.ADC() apin = adc.channel(pin='P16') #Giving the pins values redLed = Pin('P10', Pin.OUT, pull = Pin.PULL_DOWN) greenLed = Pin('P11', Pin.OUT, pull = Pin.PULL_DOWN) #As long as statement is true, it will keep looping while True: millivolts = apin.voltage() celsius = (millivolts - 500.0) / 10.0 #Just an example of how to decide the "perfect" indoor temperature for you #The green led will light up as long as celsius is between 18 and 24, else the red led will light up if celsius > 18 and celsius < 25: greenLed.value(1) redLed.value(0) else: redLed.value(1) greenLed.value(0) #pybytes.send_signal(3, celsius) print(celsius) pybytes.send_signal(3, celsius) #Temperature will update every 5 sec time.sleep(5) #To turn off both lights when program is executed redLed.value(0) greenLed.value(0) ``` Code inspiration: From tutorial 2 [Tutorial 2](https://hackmd.io/@lnu-iot/BJnuGmJh_) From LNU - David M [Button and LED ](https://gitlab.lnu.se/1dt305/sensor-libs/-/blob/master/Button%20&%20Led/led.py) # Transmitting the data/connectivity I used Pybytes and WIFI to trasnmit the data. I have already mentioned how to connect to Pybytes, but for your program to actually send it you need to write "pybytes.send_signal(1, value)" in your code and then choose what signal to send to (1 in this case) and the value is in my case the celsius, the temperature measured. You can easily set up new signals on pybytes. Just make sure that you have connection and that the line next to "LAST CONNECTION" changes from "NO CONNECTION" to the time of the last signal transmitted. # Presenting the data This is an overview of one of the sessions when data was being transmitted. You can see the temperature changing over time. This session was only a couple of minutes and as mentioned in the code, it updated the temperature every 5 seconds wich is very often. I have only used this for fun when using the computer so it has only been active for short times. To test that the temperature is measuerd accurately I started the AC and saw how the temperature went down. I also tested carefully with a blowdryer over the sensor to get the temperature over 25C to see that both LED ligths worked as planned, wich they did. When temperature was lower than 18C or higher than 25C the red LED lights up, and if temperature is inbetween the green LED lights up. If this would be used for real it would be an easy way of knowing that the room temperature is OK, without having to start the computer. ![](https://i.imgur.com/SoSKjaH.jpg) # Finalizing the design Here are som pictures of the final result. It shows the device when either LED lights are activated due to temperature changes. For many this would probably be a very easy project but for me it took quite some time to figure out where to connect all the parts to get it all to work as intended, and it took a lot of testing and almost burning out the temperature sensor. It managed to survive though it got quite hot at one point. I wish I could have been active during workshops but life gets in between sometimes and i was not able to participate. It would definately have helped to be able to disucuss with teachers and other students. In the end it was a very fun assignment and I have definately learned a lot! ![](https://i.imgur.com/GxTR0rH.jpg) ![](https://i.imgur.com/5Xhzioy.jpg) ![](https://i.imgur.com/9wW4qH8.jpg)