<Title>Tutorial</Title> ## Tutorial on how to build a basic plant need sensor This project describes how to build a sensor for basic plant needs. It senses the relative humidity, temperature and amount of light. The data is sent via LoRa network and displayed on a Ubidots dashboard. **Name:** Oscar Wirdelius **Student ID:** ow222ej **Estimated Time:** 2-8 hours ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Objective "Objective")Objective I have recently developed an interest in growing some of my own food. I chose this project to be my first experiment on how I would be able to enhance my food production with technology. The down the road goal would be to automate some parts of the gardening process. My goal with this project was to take some first steps into enhanced gardening. I wanted to evaluate my current ability and hopefully get insights on how feasible some of my ideas are. In this project I wanted to measure some basic needs of my plants. The plant data would then help me understand how their environment change over time and affect them. A future step would then be to connect the data to a system capable of adjusting the plants environment accordingly. ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Material "Material")Material **1x Pycom [Lopy4](https://pycom.io/product/lopy4/?gclid=Cj0KCQjwgJv4BRCrARIsAB17JI518X7jezv-Tz1YyqnPWddGJqBIpS6aGQmdZ-7bjb23xTYYCCAhhVMaAvovEALw_wcB) -** IOT Development platform **1x Pycom [Expansion board 3.1](https://pycom.io/product/expansion-board-3-0/) -** Used for power source and physical inputs. **1x [LoRa & Sigfox antenna](https://pycom.io/product/lora-868mhz-915mhz-sigfox-antenna-kit/) -** Used for long range, low power transmission. **1x Breadboard** **8x Cables** **2x 10k ohm resistors** **1x [LDR](https://components101.com/sites/default/files/component_datasheet/LDR%20Datasheet.pdf) sensor -** Light Dependent Resistor; ca range 0.1-10000 Lux. **1x [DHT](https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf) 11 sensor -** Temperature and relative humidity sensor; ranges 0-50°C and 20-90% humidity; accuracy ±2℃ and ±5%RH. The Lopy 4 + Expansion board + LoRa & Sigfox antenna were bought as a kit at ["Electrokit"](https://www.electrokit.com/) together with a small sensor kit including the breadboard, cables, resistors and some sensors for almost 1000 kr. I had a DHT 11 already laying around, but buying a new DHT 11 sensor costs around 50-100 kr. ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Computer-setup "Computer-setup")Computer setup I decided to use the Atom.io IDE for this project, it was presented to me during the course under which this project took place. I think it looks clean, modern and minimalistic, which I think suits the Python/MicroPython language. I have previously used other IDEs, Eclipse and Visual Code for example, and wanted to try something that was new to me. **1.** Download and install [Atom](https://atom.io/) **2.** Install pymakr plugin **3.** Attach Lopy4 to Expansion board **4.** Plug in USB between Expansion boar and computer **5.** Download and install [firmware ](https://docs.pycom.io/gettingstarted/installation/firmwaretool/) ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Putting-everything-together "Putting-everything-together")Putting everything together I used this as reference for attaching the DHT 11 sensor. ![](https://i.imgur.com/5WZdcHt.png) My setup seems to work but might not be optimal. Both of the resistors used are 10k Ohm. ![](https://i.imgur.com/e98NQQx.jpg) ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Platform "Platform")Platform I decided to work with TTN and integrate the Ubidots cloud platform, since that seemed to be the most convenient option for me. It is easy to present the data on their dashboard and is user-friendly in general. I plan to test some other platforms but decided against it in this project. The free version of Ubidots is limited but is very accessible. ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#The-code "The-code")The code #### *main*.py ![](https://i.imgur.com/aZd2yuK.png) #### *lora*.py ![](https://i.imgur.com/RFiVaEn.png) #### *read_ldr*.py ![](https://i.imgur.com/Dv4Nd4e.png) #### *read_dht*.py ![](https://i.imgur.com/gXBIrJ8.png) ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Transmitting-the-data--connectivity "Transmitting-the-data--connectivity")Transmitting the data / connectivity The data is sent to [Ubidot](https://ubidots.com/), through [TTN](https://www.thethingsnetwork.org/), with LoRa every half an hour. After some more testing and implementation additional sensors I might change the update frequency. ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Presenting-the-data "Presenting-the-data")Presenting the data I will continue working with the dashboard and implement events that are triggered by values of the data. ![](https://i.imgur.com/A42s9mc.png) I am not sending data that I need to store for more than a month, therefore [Ubidots STEM](https://ubidots.com/) is a good free choice for this application. I did not feel the need to send this specific data to a separate database but might explore that later. ### [<span class="octicon octicon-link" style="color: rgb(0, 0, 0); vertical-align: middle; visibility: hidden;"></span>](https://hackmd.io/@lnu-iot/iot-tutorial#Finalizing-the-design "Finalizing-the-design")Finalizing the design ![](https://i.imgur.com/aL1ckOU.jpg) It went okay, I am not done with printing and installing in a case that I have constructed in [Fusion 360](https://www.autodesk.com/products/fusion-360/overview). I like how the code works and am proud of figuring out the LoRa connection, at least partially. ![](https://i.imgur.com/bhxdS1H.jpg) I still have plans to implement other components but did not manage to pick them up on time. Therefore my application is incomplete and will be extended. The plan is to implement a soil moisture sensor and a battery pack as well.