Plant Monitoring System with M5Stack

Plant monitoring using M5stack and sensors to help a potted plant in its growth process.

IntermediateWork in progress500
Plant Monitoring System with M5Stack

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×1
M5Stack FIRE IoT Development Kit (PSRAM 2.0)
M5Stack FIRE IoT Development Kit (PSRAM 2.0)
×2
Earth Module Grove Compatible Soil monitoring
M5Stack Earth Module Grove Compatible Soil monitoring
×2
M5stack envii sensor
×1

Software apps and online services

ifttt software

Story

Read more

Schematics

Circuit Diagram

Code

M5STACK 1 (ENVii sensor + servo motor)

Python
from m5stack import *
from m5ui import *
from uiflow import *
import urequests
import wifiCfg
import time
import unit

setScreenColor(0x222222)
env20 = unit.get(unit.ENV2, unit.PAHUB0)
servo0 = unit.get(unit.SERVO, unit.PORTB)
pahub0 = unit.get(unit.PAHUB, unit.PORTA)




wifiCfg.doConnect('', '')
title0 = M5Title(title="Title", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF)
title1 = M5Title(title="Title", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF)
label0 = M5TextBox(104, 30, "User Menu", lcd.FONT_Default, 0xFFFFFF, rotate=0)
title2 = M5Title(title="ENVII Function", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF)
label3 = M5TextBox(0, 50, " Plant Data is listed below.Update every min.", lcd.FONT_Default, 0xFFFFFF, rotate=0)
line0 = M5Line(M5Line.PLINE, 6, 81, 75, 81, 0xFFFFFF)
line1 = M5Line(M5Line.PLINE, 126, 82, 197, 82, 0xFFFFFF)
line2 = M5Line(M5Line.PLINE, 247, 83, 317, 83, 0xFFFFFF)
label1 = M5TextBox(0, 98, " Temperature", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(136, 98, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(237, 98, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(0, 124, " Pressure", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(136, 136, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(236, 136, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

# Describe this function...
def Temperature():
  while True:
    if (env20.temperature) > 24:
      label4.setText('Too High')
      servo0.write_angle(90)
      wait(60)
    else:
      label4.setText(' Acceptable')
      servo0.write_angle(0)
      wait(60)
    wait_ms(2)

# Describe this function...
def Pressure():
  while True:
    if (env20.pressure) < 500:
      label7.setText(' Low Pressure')
      try:
        req = urequests.request(method='GET', url='https://maker.ifttt.com/trigger/LowPressure/json/with/key/bG1i-Q-c9tnwLeu64gMnbw8rNSlGMLopgXpzu-LbK-u')
      except:
        pass
    elif (env20.pressure) > 500 and (env20.pressure) < 1100:
      label7.setText(' Ideal Pressure')
    elif (env20.pressure) > 1100:
      try:
        req = urequests.request(method='GET', url='https://maker.ifttt.com/trigger/HighPressure/json/with/key/bG1i-Q-c9tnwLeu64gMnbw8rNSlGMLopgXpzu-LbK-u')
      except:
        pass
      label7.setText(' High Pressure')
    wait_ms(2)



servo0.write_angle(0)
label1.show()
label2.show()
while True:
  label2.setText(str((str((env20.temperature)) + str('C'))))
  label6.setText(str((str((env20.pressure)) + str('Pa'))))
  Pressure()
  Temperature()
  wait_ms(2)

M5STACK2 (Earth Sensor + Servo Motor)

Python
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import urequests
import unit

setScreenColor(0x222222)
earth0 = unit.get(unit.EARTH, unit.PORTB)
servo0 = unit.get(unit.SERVO, unit.PORTA)


notGate = None
servoAngle = None
earthTrigger = None
notGateOutput = None
earthInputPercent = None
earthInput = None

wifiCfg.doConnect('', '')
label3 = M5TextBox(55, 107, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
image0 = M5Img(130, 69, "res/pot64.png", True)
image1 = M5Img(185, 135, "res/warning-24.png", True)
label0 = M5TextBox(32, 195, "Sending notification", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)

import math


# Describe this function...
def notGate2():
  global notGate, servoAngle, earthTrigger, notGateOutput, earthInputPercent, earthInput
  notGate = float(1024)
  notGateOutput = notGate - earthInput
  earthInputPercent = notGateOutput / 11.38

# Describe this function...
def servoDriver():
  global notGate, servoAngle, earthTrigger, notGateOutput, earthInputPercent, earthInput
  servoAngle = earthInputPercent
  servo0.write_angle(servoAngle)



earthTrigger = 400
image1.hide()
label0.hide()
while True:
  earthInput = earth0.analogValue
  notGate2()
  if earthInput < earthTrigger:
    servoDriver()
    try:
      req = urequests.request(method='GET', url='https://maker.ifttt.com/trigger/SensorLow/with/key/bG1i-Q-c9tnwLeu64gMnbw8rNSlGMLopgXpzu-LbK-u')
    except:
      pass
    label0.show()
    image1.show()
  else:
    image1.hide()
    servoDriver()
  label3.setText(str((str(round(earthInput)) + str('%'))))
  wait_ms(2)

Credits

JAMES KHOH WEI EARN

JAMES KHOH WEI EARN

1 project • 0 followers
Mohammad Irwan Zulkarnaen Bin Salleh

Mohammad Irwan Zulkarnaen Bin Salleh

0 projects • 0 followers
Jiaxin

Jiaxin

0 projects • 0 followers

Comments

Add projectSign up / Login