Deepash Patel
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Tutorial on how to build The Plant Monitor 2000 **Deepash Patel - dp222mj** --- **Table of Contents** [TOC] --- ## Overview A plant monitor project that uses a RP2040 based microcontroller, the Raspberry Pi Pico W, and multiple sensors. in order to take measurements for temperature, humidity, soil moisture level and light level. If the soil moisture falls below a certain level a RGB LED is used as an alarm signal as well as a passive piezo buzzer that plays a melody. A 16x02 LCD screen displays the last taken measurements and a button toggle allows the backlight to be turned on and off between measurements to check last readings. A Wi-Fi connection is set up so that the reading can be sent using the MQTT protocol to the Adafruit IO platform for storage and visualisation. The platform also allows us to send an alert via email when the mositure level in the soil is too low. **Estimated time taken: 4 hours (not including any 3D-printing).** --- <br></br> ## Objective We like to grow chilli plants in the kitchen in our household, this room often gets a lot of sunlight in the summer months. This can lead to the soil drying out quickly. This is especially problematic when we are away and anyone coming to water the plants forgets to actually water them (true story), all my tasty chillis die! :slightly_frowning_face: The Plant Monitor 2000 allows you to check if the conditions for your plant are satisfactory, notifying you if they aren't so you can give your precious plants the care and attention they need to thrive. An email will be sent to you if the plant is thirsty so if you are away, you can call your plantsitter and berate them profusely for their lack of care (this would have been handy last summer)! The optimum range for the moisture level for chilli plants is between 32% and 58% and The Plant Monitor 2000 can helps us make sure that our chilli plants stay in that range! The insights gathered through monitoring can help to keep our plants in the best conditions, we can aim for a temperature of between 15-30 degrees, air humidity of 50%, optimum soil mositure levels and to make sure they are getting enough light. With these insights they can be moved to a better place if needs be or watered more regularly. The data provided can also be further investigated to see which conditions correlate to better yield and plant health especially if scaled up to multiple plants. --- <br></br> ## Material Below you can find a table containing the materials used for the project and an explanation of their purpose and costs. I bought the kits which supplied the majority of the materials but have included links to separate products for ease of purchase. In addition to these, a computer running VSCode on Mac OS was used to program and setup the Pico W as well as a 3D printer to print a case for the breadboard, LCD screen and soil sensor. A capacitive soil sensor was chosen as they do not expose the conducting material to the medium thereby avoiding corrosion which will occur with resistive sensors. | Product | Purpose | Purchase Link | Photo | Price | |:-------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------:|:-------:| | Applied IOT LNU Starter Kit | Contains Pico W, breadboard, cables and a few sensors, resistors and LEDs. | [Electrokit](https://www.electrokit.com/lnu-starter) | ![Starter Kit Contents](https://hackmd.io/_uploads/SkTbulqLR.png) | 399 SEK | | 25 Module Sensor Kit | Contains an assortment of 25 different sensors, resistors and LEDs. | [Electrokit](https://www.electrokit.com/sensor-kit-25-moduler) | ![Sensor Kit Contents](https://hackmd.io/_uploads/Sy6v2TcLA.jpg) | 299 SEK | | Raspberry Pi Pico WH | Our microcontroller unit (MCU) which will be the brains of our operation. A 40 pin header is soldered on to make it easy to use with a breadboard. | Included in the starter kit but can be purchased separately here: [Electrokit](https://www.electrokit.com/raspberry-pi-pico-wh) | ![Raspberry Pi Pico WH](https://hackmd.io/_uploads/r1HY1R5L0.jpg) | 109 SEK | | 840 pin Breadboard | Allows us to connect our MCU to all our sensors, LED, button and screen. | Included in the starter kit but can be purchased separately here: [Electrokit](https://www.electrokit.com/kopplingsdack-840-anslutningar) | ![Breadboard - 840 pin](https://hackmd.io/_uploads/ryrpkCqUR.jpg) | 69 SEK | | DHT11 | A temperature and humidity sensor. | Included in the starter kit and sensor kits but can be purchased separately here: [Electrokit](https://www.electrokit.com/digital-temperatur-och-fuktsensor-dht11) | ![DHT11](https://hackmd.io/_uploads/SJtfrkoI0.jpg) | 49 SEK | | Adafruit STEMMA Soil Sensor | Allows us to measure the moisture level in the soil of our plant pot using the I2C protocol. | Purchased from: [Electrokit](https://www.electrokit.com/en/jordfuktighetssensor-kapacitiv-i2c) | ![Soil Sensor](https://hackmd.io/_uploads/ByR9wyjU0.jpg) | 115 SEK | | JST-PH 2.0mm 4-pin female cable | A STEMMA compatible cable to connect our Soil Sensor to the breadboard and MCU. | Purchased from: [Electrokit](https://www.electrokit.com/kabel-med-jst-ph-4-pol-hona-/-0.64mm-hylsor-200mm) | ![JST-PH cable](https://hackmd.io/_uploads/HkC3sJoLR.jpg) | 24 SEK | | 4-7 kohm Photoresistor | A Photoresistor to help us measure light levels, connected via an ADC capable pin. | Included in the starter and sensor kits but can be purchased separately here:[Electrokit](https://www.electrokit.com/fotomotstand-cds-4-7-kohm) | ![Photoresistor](https://hackmd.io/_uploads/BJ-C0kiLC.jpg) | 8 SEK | | Resistor carbon film 0.25W 4.7kohm (4k7) | Used between the photoresistor the Pico W's ADC pin and 3.3V as a voltage divider. | Included in the starter kit but can be purchased here:[Electrokit](https://www.electrokit.com/en/motstand-kolfilm-0.25w-4.7kohm-4k7) | ![resistor](https://hackmd.io/_uploads/H1UKIgjLR.png) | 1 SEK | | Freenove 1602 LCD Screen | An LCD screen which uses the I2C protocol to receive characters and strings for display. | Purchased from: [Amazon](https://www.amazon.se/Freenove-Display-Compatible-Arduino-Raspberry/dp/B0B76Z83Y4) | ![Freenove LCD](https://hackmd.io/_uploads/SyaDKejLR.jpg) | 139 SEK | | RGB LED | An RGB LED module allowing us to make it flash as an alert when the plant needs attention. | Included in the sensor kit but can be purchased separately here: [Electrokit](https://www.electrokit.com/en/led-modul-rgb) | ![RGB LED](https://hackmd.io/_uploads/rJvP5gsUA.jpg) | 22 SEK | | Passive Piezo Buzzer | Allows us to play a melody when the plant needs attention. | Included in the sensor kit but can be purchased separately here: [Electrokit](https://www.electrokit.com/piezohogtalare-passiv) | ![Piezo Buzzer](https://hackmd.io/_uploads/SJbc2goIR.jpg) | 36 SEK | | Momentary Push Button Module | A button that is programmed to toggle the LCD backlight on and off when pressed. | Included in the sensor kit but can be purchased separately here: [Electrokit](https://www.electrokit.com/en/tryckknapp-momentan) | ![Button](https://hackmd.io/_uploads/rJ3O6goI0.jpg) | 19 SEK | | USB-A male to Micro USB B male Cable | Allows us to supply power over USB to the Pico WH. | Included in the sensor kit and most likely you'll have one lying around but can be purchased here: [Electrokit](https://www.electrokit.com/usb-kabel-a-hane-micro-b-5p-hane-1.8m) | ![USB Cable](https://hackmd.io/_uploads/Hk02fR5IR.png) | 39 SEK | | Power supply for the Pico (a spare USB-A phone charger works great) | Allows us to supply power over USB to the Pico WH. | Most likely you'll have one lying around but here is an example: [Amazon](https://www.amazon.se/-/en/aisens-A110-0063-Charger-White/dp/B07DCWJ4WQ) | ![Power Supply](https://hackmd.io/_uploads/Hk-GIR5U0.jpg) | 45 SEK | | 10x female/male 30cm Jumper Cables | Allows us to connect our MCU and sensors/modules through the breadboard. | Included in the starter kit, can be bought separately here but only in 20x quantity: [Electrokit](https://www.electrokit.com/en/labsladd-1-pin-hane-hona-150mm-10-pack) | ![Jumper 30cm fem](https://hackmd.io/_uploads/ryy5305UR.jpg) | 29 SEK | | 20x male/male 30cm Jumper Cables | Allows us to connect our MCU and sensors/modules through the breadboard. | Included in the starter kit, can be bought separately here: [Electrokit](https://www.electrokit.com/en/labbsladd-20-pin-15cm-hane/hane) | ![Jumper 30cm male](https://hackmd.io/_uploads/B1fsTCqU0.jpg) | 29 SEK | | 20x female/male 15cm Jumper Cables | Allows us to connect our MCU and sensors/modules through the breadboard. | Included in the starter kit but can be separately here, though only in amounts of 10 so two purchases will be required: [Electrokit](https://www.electrokit.com/en/labsladd-1-pin-hane-hona-150mm-10-pack) | ![Jumper 15cm fem](https://hackmd.io/_uploads/Hk4KfyoIC.jpg) | 58 SEK | If all the items are purchased separately the total cost comes to 791 SEK, which is a little cheaper than combining the kits and buying extras (1021 SEK). *Prices are accurate as of June 2024.* I have given a brief description on the materials used but want to highlight the microcontoller unit the Pico WH. The Raspberry Pi Pico W is a RP2040 microcontroller with dual Cortex M0+ processor cores, up to 133MHz and a 30 multifunction GPIO, a four channel ADC and supports SPI, UART and I2C. Below you can see the pinout diagram. >[![picow-pinout](https://hackmd.io/_uploads/SkRXMWj80.svg)](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html) >Fig. 1. Pinout Diagram for the Raspberry Pi Pico W. raspberrypi.com --- <br></br> ## Computer Setup A computer running Mac OS was used for this project but it's possible to use Windows and Linux as well. I also used VSCode but Thonny is a good option too for our IDE. You can [**find VSCode here**](https://code.visualstudio.com/download). I used Micropython with the Pico W so it's a good idea to also [**install the Python support**](https://code.visualstudio.com/docs/editor/extension-marketplace) extension for VSCcode. As I used the Pymakr plugin for VSCode I needed to install node.js first which I did through [**Node Version Manager**](https://nodejs.org/en/download/package-manager). Then I [**installed the Pymakr extension in VSCode**](https://docs.pycom.io/gettingstarted/software/vscode/). A full guide for the VSCode setup can be found [**here**](https://hackmd.io/@lnu-iot/rkiTJj8O9). The next step was to flash the Pico W with the latest Micropython firmware by using the UF2 bootloader, this was achieved by holding down the BOOTSEL button on the unit whilst connecting it to the USB port on the computer which mounts the Pico W as a mass storage device. Then it was a simple case of [**downloading the latest firmware from the Micropython website**](https://micropython.org/download/RPI_PICO_W/) and then copying the uf2 file over to the Pico mass storage device. Once the file is copied the Pico will recognize it and flash the firmware automatically after unmounting the drive from your system. A full guide on how to flash the Pico W with Micropython and how to access it in Pymakr can be found [**here**](https://hackmd.io/@lnu-iot/rkFw7gao_). Now I was able to connect to the Pico W via Pymakr in VSCode and access the REPL running on the Pico, the interactive standard shell for Python. Using VSCode and Pymakr in the sidebar I was be able to see which devices I could connect to. In MacOS the Pico shows up as beginning with "tty.usbmodem". Once connected click on the termminal icon to bring up the REPL and test some code. It's best to create a new project under Pymakr though and add the device here and connect to it. How did I upload and run my code on the Pico? I began by putting the Pymakr project into dev mode, so each time I saved it updated the code on the Pico and ran the code. Dev mode doesn't delete any existing files so you end up with more files on the Pico's limited storage than you realise. However you can also upload by syncing the entire project to the Pico with the sync icon (a folder with am arrow pointing upwards), when not in dev mode this will delete everything else on the Pico and upload the current project and is what I did to upload the final code to the device. The GIF below shows how to add a device to a Pymakr project, how to access the terminal on the device and where to find the buttons for syncing and dev mode. >![Pymakr](https://hackmd.io/_uploads/r19GnfiLA.gif) >Fig. 2. An example of how to use VSCode and Pymaker with the Pico W. --- <br></br> ## Putting everything together Below is a list detailing how I wired everything together as reference, with a diagram below that shows the wiring in place. Numbers in brackets in the list match the number of the pin on the Pico W pinout diagram and the order of the list follows the diagram clockwise from top left of the breadboard to bottom left. <br></br> * Vbus - (40) - 5v rail only for the LCD Screen to the bottom positive rail of the breadboard. * GND - (38) - Taken to the top negative rail of the breadboard. * 3v3(Out) - (36) - Taken to the the top positive rail of the breadboard. * Photo resistor - ADC 1 pin GP27 (32), 3.3v top rail , GND top rail. * 4.7 kohm resistor - Bridging between the ADC 1 line and 3.3v top rail. * DHT 11 - GP22 (29), 3.3v top rail, GND top rail. * RGB LED - GP21 (27), GP20 (26), GP19 (25), GND top rail. * Button - GP18 (24), 3.3v top rail, GND top rail. * STEMMA Soil Sensor - I2C0 GP16 SDA (21), I2C0 GP17 SCL (22), 3.3v top rail, GND top rail. * Passive Piezo - GP13 (17), GND bottom rail. * LCD Screen - I2C1 GP2 SDA (4), I2C1 GP3 SDC (5), 5v bottom rail, GND bottom rail. * GND (3) - Taken to the bottom negative rail. <br></br> >![Plant Monitor_bb](https://hackmd.io/_uploads/rytRvln8R.png) > Fig. 3. Wiring Diagram for project. <br></br> ### Power considerations | Device| Loop Active | Loop Idle | | -------- | -------- | -------- | | Pico W | 70mA | 25mA (not deep/light sleep) | |DHT11|0.5mA|0.1mA| |Soil Sensor|0.5mA|0.1mA| |Photoresistor & resistor|Light Max - 0.6mA|Light Min - 0.0315mA | |LCD Screen|23mA|3mA| The table above shows the current draw in mA when the main loop is active and when it is idle for the parts listed, other sensors and modules were hard to find information on but their current draw will be negligible. Because we will take measurements only every hour we have to take this into acout to calulate how long a 20000mAh battery/powerbank could supply the Plant Monitor with power. However the backlight toggle for the LCD Screen complicates things, as there is a large difference between both states and the varying light levels that will affect the photoresistor also change things slightly. However we can make a rough guess that everything will mainly be in an idle state and only in an active state for a max average of 30 secs every hour if no alarm is triggered. >*Idle state = 25 + 0.1 + 0.1 + 0.0315 + 3 = **28.2315mA** >Active state = 70 + 0.5 + 0.5 + 0.6 + 23 = **94.6mA*** 30 seconds is 1/120 of an hour so we can multiply the active state by this and the idle state by the remainder, 119/120, and then add them together to get the average current consumption. >*Idle avg = 119/120 * 28.2315 ≈ **27.996mA** >Active avg = 1/120 * 94.6 ≈ **0.788mA** >I avg = 27.996 + 0.788 ≈ **28.784mA*** Now we can divide the battery capacity by the average current draw to get a rough estimate of how many hours the battery could power the Plant Monitor. >*20000mAh / 28.784mA ≈ **695 hours*** As the Plant Monitor is intended to be used indoors it will be connected to a power outlet but it is good to know that it could be connected to an external battery if you wanted to place it where power supply could be an issue. One thing to note is when the WiFi is active it uses an additional 45mA, which is a huge increase, which is why the code disconnects from the WiFi when not sending data. I also tried *deepsleep()* and *lightsleep()* from the machine library but the button for the backlight interferes with this, if it wasn't for this the idle power might be able to be lowered significantly. The voltage divider resistor between the photoresistor and the 3.3V OUT was used as initiallythe KY-018 LDR module from the Sensor Kit but the readings were not very sensitive to changes in light. I noticed that this module uses a 10k resistor and thought that might be the issue, so I took a photoresistor and a 4.7k ohm resistor from the Starter Kit and used them instead resulting in more responsive readings. This project is intended for development purposes and is a proof of concept. --- <br></br> ## Platform I chose to use the free version of the Adafruit IO platform for this project. Adafruit IO can be used with either REST or MQTT to send data to the platform, I decided to go with the MQTT protocol which uses topics and a publish/subscribe model to send and recieve data. I have also tested Ubidots which sends data over HTTP requests, this worked great as well but intially I wanted to use LoRaWAN and wanted to use an MQTT broker with it. However I was unable to get the coverage in my area, so then I decided on implementing a TIG stack. The plan was to host the TIG stack on my Raspberry Pi 4 and host a MQTT server on it as well with Mosquitto, but I had issues getting the Telegraf to communicate with Mosquitto. In the end Adafruit seemed like a great fallback option as I had already tested it, providing an MQTT broker, time-series databases and great dashboard visualisation options all for free. I created a feed for each measurement for the project, four in total and used these in the MQTT settings within my ***keys*** file along with the API key and other info. I used a [**tutorial**](https://hackmd.io/@lnu-iot/r1yEtcs55) to begin to implement the code but then adapted some of the code into my own function for better scalability, this can be found in the ***send_sensor_data.py*** file. --- <br></br> ## The Code My code is fairly modular and therefore my main file imports a lot modules, and can then access custom functions. I feel this makes the main logic easier to read but it can make it harder to understand from a quick glance, I won't focus on everything in this section, but I will link to my GitHub for the project code. I do like to comment a lot to make the code easier to understand. I initally had issues with implementing the Adafruit STEMMA Soil Sensor, as the code examples that Adafruit supply are for Circuitpython I tried getting to get the Blinka library to work on Micropython with the Pico W to help using their modules but I kept on getting errors. I started to write my own function to try and access the data via I2C but then I thought I should check if anyone else tried to get it to work with Micropython. In the end I found a tutorial from a previous student who managed to get it to work, so huge thanks to Samuel Tinnerholm for the base code 🙂. The only thing I changed was to work out the reading as a percentage in the function. The LCD screen required some work but I found some libraries that helped a lot, Freenove actually include these on their website but it isn't obvious where to find them. I am also quite pleased how the LCD screen custom characters came out, a minor detail in terms of functionality but fun, I used a handy [**generator found here**](https://maxpromer.github.io/LCD-Character-Creator/) to help create the hex data. The button implementation was harder than I expected, but I got some good help from ChatGPT and by intiating a pull up resistor in Micropython on the Pin and implementing a toggle function, it works great. The logic for the photo resistor I worked out myself as it is fairly straightforward (explained in the comment above it). The network connectivity was implemented via a Wi-Fi connection, which was straightforward to set using the guide, the code via the boot file connects on startup and then at the beginning of the main loop, disconnecting before sleeping for an hour to save on power. I used the following guides and code for implementing the various sensors and fucntionalty but have edited some of them and adapted them for my needs. [LCD Screen](https://github.com/T-622/RPI-PICO-I2C-LCD) [Soil Sensor](https://github.com/realfishsam/bnbPlants?tab=readme-ov-file) [DHT11](https://github.com/iot-lnu/applied-iot/tree/master/Raspberry%20Pi%20Pico%20(W)%20Micropython/sensor-examples/P5_DHT_11_DHT_22) [Passive Piezo Buzzer](https://github.com/iot-lnu/applied-iot/tree/master/Raspberry%20Pi%20Pico%20(W)%20Micropython/sensor-examples/P19_Passive_Piezo_Buzzer) [RGB LED](https://github.com/iot-lnu/applied-iot/tree/master/Raspberry%20Pi%20Pico%20(W)%20Micropython/sensor-examples/P9_RGB_LED) [Wi-Fi Connection](https://github.com/iot-lnu/applied-iot/tree/master/Raspberry%20Pi%20Pico%20(W)%20Micropython/network-examples/N1_WiFi_Connection) <br></br> [**The full project code can be found on GitHub here.**](https://github.com/dp222mj/lnu_iot_project_plant_monitor/tree/main) <br></br> Below you will find the main logic with commenting. ```python= # Setup for humidity and temp sensor DHT11 tempSensor = dht.DHT11(Pin(22)) # Setup for Soil Moisture Sensor (Adafruit Stemma) i2c_soil = I2C(0, scl=Pin(17), sda=Pin(16)) # i2c_soil = I2C(0, scl=Pin(17, Pin.PULL_UP), sda=Pin(16, Pin.PULL_UP)) ss = Seesaw(i2c_soil) # Setup for LDR/Photo Resistor photo_resistor = ADC(Pin(27)) # Main logic for monitoring, will run endlessly until disconnected from power. while True: try: # Read humidity and air temp from DHT11 tempSensor.measure() temperature = tempSensor.temperature() humidity = tempSensor.humidity() # Read moisture level from the soil sensor moist = round(ss.get_moisture()) # Read the light level from the photo resistor and display as a percentage light = photo_resistor.read_u16() # Light level is calculated as a percentage by subtracting the 16-bit integer reading from ADC from the ceiling value of the 16-bit integer (65535), this value is divided by the ceiling value and then multiplied by 100 to get the light level as a percentage. light_level = round((65535 - light) / 65535 * 100) print(f"Temperature is {temperature} degrees Celsius and Humidity is {humidity}%") print(f"Soil Moisture: {moist}%") print(f"Light level: {light_level}%") # Need to switch backlight on here for the loop to display on repeat lcd.backlight_on() backlight_state = True lcd.clear() lcd.putstr(f"{chr(0)}: {temperature}{chr(5)}C {chr(1)}: {humidity}%") lcd.move_to(0, 1) lcd.putstr(f"{chr(2)}: {moist}% {chr(3)}: {light_level}%") try: # Connect to Wi-Fi to send data wifi_connection.connect() # Send the MQTT data to Adafruit IO send_data.client.connect() send_data.send_sensor_data(temperature, humidity, moist, light_level) sleep(5) send_data.client.disconnect() # Disconnect from Wi-Fi to save energy wifi_connection.disconnect() except Exception as error: print("Could not connect to Wi-Fi and send data...", error) # Here is our if statement to check the condition we want, in this case if the soil moisture is below 32% or above 58% if moist < 32 or moist > 58: led_flash(10) playsong(song) sleep(20) lcd.backlight_off() backlight_state = False # Sync the state with the actual state of the backlight except Exception as error: print("Exception occurred", error) print("Waiting for 1 hour...") sleep(3600) ``` ___ <br></br> ## Transmitting the data / conncectivity The data the sensors gather is transmitted hourly via the MQTT protocol through a WiFi internet connection. As mentioned I did test LoRaWan but as I could not connect from home I abandoned that idea. WiFi was a perfect alternative though as the Plant Monitor is deployed indoors within the range of my home Wi-Fi Network. As mentioned earlier the WiFi uses a lot of power so that's why we only connect when we want to send data and disconnect directly afterwards as part of the main logic. The code to implement this is linked both in the project's GitHub and the guide above. Once connected to the internet via WiFi, the main logic uses the send_sensor_data module to connect to the MQTT broker using the credentials in the **keys** file. Then the **send_sensor_data** function sends the values read from the sensors and stored in the variables for temperature, humidity, soil moisture and light level to the MQTT broker, in our case, Adafruit IO. The feeds specified in the **keys** file are the topics to which the incoming MQTT messages will be published. Finally we disconnect from the broker using the send_sensor_data module. I touched upon the choice of using MQTT earlier, but one great thing about using Adafruit IO is the option to implement webhooks as actions. This means you can for example set a trigger to post in a Disocrd channel when a certain conditon is met! --- <br></br> ## Presenting the data Here are some examples of how the visualisation looks in Adafruit IO. The feeds in Adafruit IO are time-series databases which store the readings published through it's integrated MQTT broker. The data is stored everytime the Pico can connect through Wi-Fi and publish to the MQTT broker, ideally every hour as specified in the main logic. This data can be visualised through a customizable dashboard as you see fit, I however have used mainly line graphs. As mentioned before actions can be automated based on a trigger condition, in this case I have set up an action to email me when the soil moisture level goes below 32%. In addition I have also created a webhook that posts to a Discord server based on the same condition. [**The dashboard for the data visualisation can be accessed here**](https://io.adafruit.com/deep_lnu_iot/dashboards/lnu-project-plant-monitor?kiosk=true). >![Dash Dial](https://hackmd.io/_uploads/HJe6o5hLA.png) ![Dash 1 + 2](https://hackmd.io/_uploads/rk8poqhU0.png) ![Dash 3 + 4](https://hackmd.io/_uploads/B1g36jcn80.png) Fig. 4-6. Screens showing how I visualised the sensor readings from the feeds >![Email Alert](https://hackmd.io/_uploads/H1F4Uqn8A.png) >Fig. 7. An email received through a triggered reaction on Adafruit IO. >![Discord Webhook](https://hackmd.io/_uploads/ry3VLqnUR.png) >Fig. 8. Discord channel receiving a message due to a triggered action via a webhook. --- <br></br> ## Finalizing the design Here you can see some of the work in progress as well as the final design, a fellow student was kind enough to help me design and 3D print a case for the Plant Monitor, in addtion I [**found a handy cover for the soil sensor**](https://www.printables.com/model/63833-adafruit-stemma-capacitive-soil-sensor-cover-for-i/files) and was able to print that too! Overall I think the project went well, it ended up being more complex than I intially had planned partly due to the addition of extra components, but I am happy with the result. I would still like to get the TIG stack up and running and have locally a hosted MQTT broker, data handling and visualisation. <br></br> >![IMG_8836 SM](https://hackmd.io/_uploads/SJ2X9ih8A.jpg) ![IMG_8876 SM](https://hackmd.io/_uploads/rye89ohIR.jpg) ![IMG_8881 SM](https://hackmd.io/_uploads/BJE8cohLR.jpg) ![IMG_0080 SM](https://hackmd.io/_uploads/H1dUqj2IC.jpg) Fig 9-12. Various states of development from prototype to final design. <br></br> And here is a video presentation of the project! {%youtube 1To9930yVUg%} ___

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully