# IOT Project Double Thermometers Carl Carlson cc222nh ## ### Project Overview Simple temperature sensor setup using 2 sensors to double check values and get a rough average between them. Easy to setup. #### Time Required: 1 hour ### Objective Originally I wanted 3 sensors to make sure that everything worked as planned, including one of them being analog to learn how to work with that. After the analog sensor didn't work as planned I had to cut it out and only went with 2. I always feel it's good to have multiple sensors in case one stops working, and a backup in that case is a necessity. Here even if one sensor stops working and the average becomes a bad measurement, the other sensors measurements will still be in place. I still learnt plenty about setting up analog sensors as well, but also learnt that good documentation of a sensor helps a lot. ### Material * LoPy4 (WiPy works as well since only WiFi was used) * The main computer behind everything * DHT11 * Digital humidity and temperature sensor * DS18B20 * Digital temperature sensor * Expansion Board 3.1 (Any expansion board that fits would work probably) * Breadboard * 8 wires to connect everything All of these were acquired from https://www.electrokit.com/ , the sensors in the 25 sensor-kit: https://www.electrokit.com/produkt/sensor-kit-26-moduler/, and the LoPy4 with expansion board as well. The latter can be acquired from https://pycom.io/product/lopy4/?gclid=EAIaIQobChMIhvyAgIXK6gIV2wJ7Ch3hdgofEAAYAiAAEgJVHvD_BwE instead. WiPy would be cheaper but overall I think everything together is less than 100€. ### Computer Setup For this course I chose to use Atom, so I followed the instructions to install Atom and add pymakr from the pycom website: https://docs.pycom.io/pymakr/installation/atom/. The getting started guide on pycom guided me through everything I needed to setup hardware and software. Since I am using Windows 10 I didn't need to install any extra drivers. To update the board I followed the guide as well: https://docs.pycom.io/gettingstarted/installation/firmwaretool/. The code is uploaded through using Atom with the built in pymakr features. Very simple and easy to use. I didn't have to install node.js either so that made things easier. ### Putting Everything Together ![](https://i.imgur.com/kqJKeKY.png) Figure 1. Diagram of setup (excluding LoPy4 in picture) I connected the two sensors into the breadboard, and then as displayed connected the wires to the breadboard for ground and electricity so that they could both be plugged in to the expansion board simultaneously. The 3V3 port was used instead of 5V but either should be fine as both modules can take at least 5V. The DS18B20 (green in the diagram) was plugged in to port P10 (GPIO17 in diagram) while the DHT11 (black in the diagram) was plugged in to port P11 (GPIO22 in diagram). ### Platform Pybytes I have only tried this platform (pybytes) specifically but I think this is a simple home project which can use most any platform as long as you get the sensors. It is fairly scalable and more sensors could be added but it will work as long as you find proper documentation. The platform provides the necessities and does it in a simple way, only lacks a bit of documentation for some sensors but usually there is some guidance from those who have tried before. ### The Code ```python= import pycom import time from machine import Pin from dth import DTH from onewire import DS18X20 from onewire import OneWire #DHT11 Connected to pin P11 th = DTH(Pin('P11', mode=Pin.OPEN_DRAIN)) #DS18B20 data line connected to pin P10 ow = OneWire(Pin('P10')) dsResult = DS18X20(ow) while (True): dsResult.start_conversion() time.sleep(1) dsTemp = dsResult.read_temp_async() #Fetches DS18B20 Data print("DS: " + str(dsTemp)) dhtResult = th.read() #Fetches DHT11 data if dhtResult.is_valid(): print("DHT: " + str(dhtResult.temperature)) temp = ((dhtResult.temperature + dsTemp) /2) #average of the results else if dsTemp < 100: temp = dsTemp print("Result: " + str(temp)) print("--------") #sends data as signals 1, 2, and 3. pybytes.send_signal(1, float(dsTemp)) pybytes.send_signal(2, float(dhtResult.temperature)) pybytes.send_signal(3, float(temp)) time.sleep(300) #waits 5 minutes before sending more data ``` 2 external libraries were used as well, in the from of a DHT library: https://github.com/JurassicPork/DHT_PyCom and a Onewire library: https://github.com/pycom/pycom-libraries/tree/master/examples/DS18X20. These were used to properly obtain the data from the sensors. All credit goes to the libraries creators. ### Transmitting the Data / Connectivity Data is sent every 5 minutes using WiFi to Pycom, and then through Pycom to a webhook: https://webhook.site/#!/96c43c02-bfc2-46bf-b888-192e351e8850/aa13ec21-425a-4e47-b01f-fc4bdb6ad9e9/1 It sends 3 signals every time, 1 for each sensor, and 1 for the average of the signals. ### Presenting the Data ![](https://i.imgur.com/peqNId5.png) Figure 2. Dashboard of 3 graphs, Both sensors have had an error each where reading were off The data is saved to webhooks every 5 minutes when it comes in to Pycom. The data will also exist on Pycom for a month before being removed. ### Finalizing the Design ![](https://i.imgur.com/q2wYbtX.jpg) Figure 3. Final Setup In the end the project was what I had planned, albeit missing a sensor. I learned plenty from setting this up and from what I wasn't able to accomplish, but it can help in setting up better things for the future. What I would like to do is set up a similar thing with more sensors, and make a program that actually compares all the sensors results with each other and makes sure that none of them are acting up before the data is used or sent. Thank you for following through my project, it was my first proper try at doing everything with pycom from scratch.