JustinJey yagheswarShawn
Published

Automated Plant Maintenance Setup

No need to worry about your plants anymore

IntermediateShowcase (no instructions)304
Automated Plant Maintenance Setup

Things used in this project

Story

Read more

Schematics

Secondary M5Stack Circuit Diagram

Main M5Stack Circuit Diagram

Code

Main M5Stack Python Code

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

setScreenColor(0x25706c)
earth_0 = unit.get(unit.EARTH, unit.PORTB)
env2_0 = unit.get(unit.ENV2, unit.PORTA)
servo_1 = unit.get(unit.SERVO, unit.PORTC)


a = None
b = None
c = None



Humidity = M5TextBox(200, 17, "Humidity:", lcd.FONT_DejaVu18, 0xffc4c4, rotate=0)
Temperature = M5TextBox(14, 17, "Temperature:", lcd.FONT_DejaVu18, 0xff0000, rotate=0)
HumidityShow = M5TextBox(234, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
TemperatureShow = M5TextBox(60, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Moisture = M5TextBox(112, 164, "Moisture:", lcd.FONT_DejaVu18, 0x00c0ff, rotate=0)
MoistureShow = M5TextBox(145, 189, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rectangleHumid = M5Rect(223, 72, 50, 10, 0xFFFFFF, 0xFFFFFF)
rectangle0 = M5Rect(177, 117, 150, 5, 0xFFFFFF, 0xFFFFFF)
rectangleTemp = M5Rect(48, 72, 50, 10, 0xFFFFFF, 0xFFFFFF)
rectangle1 = M5Rect(0, 117, 150, 5, 0xFFFFFF, 0xFFFFFF)
rectangleMoist = M5Rect(134, 207, 50, 10, 0xFFFFFF, 0xFFFFFF)
circle = M5Circle(160, 120, 30, 0xFFFFFF, 0xFFFFFF)
image0 = M5Img(147, 107, "res/thumbsup.jpg", True)

import math




while True:
  HumidityShow.setText(str((str(round(env2_0.humidity)) + str('%'))))
  TemperatureShow.setText(str((str(round(env2_0.temperature)) + str('C'))))
  MoistureShow.setText(str(round(earth_0.analogValue)))
  if (env2_0.humidity) >= 50 and (env2_0.humidity) <= 80:
    rectangleHumid.setBgColor(0x33ff33)
    a = 1
  else:
    rectangleHumid.setBgColor(0xff0000)
    a = 0
  if (env2_0.temperature) >= 21 and (env2_0.temperature) <= 28:
    rectangleTemp.setBgColor(0x33ff33)
    b = 1
  else:
    rectangleTemp.setBgColor(0xff0000)
    b = 0
  if (earth_0.analogValue) >= 100 and (earth_0.analogValue) <= 1000:
    rectangleMoist.setBgColor(0x33ff33)
    c = 1
  else:
    rectangleMoist.setBgColor(0xff0000)
    c = 0
  if a == 1 and b == 1 and c == 1:
    circle.setBgColor(0x33ff33)
    image0.show()
  else:
    circle.setBgColor(0xff0000)
    image0.hide()
  if (earth_0.analogValue) <= 100:
    servo_1.write_angle(5)
    wait(2)
    servo_1.write_angle(60)
    wait(2)
    servo_1.write_angle(5)
  wait_ms(2)

Secondary M5Stack Python Code

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

setScreenColor(0x312d2d)
pbhub1 = unit.get(unit.PBHUB, unit.PORTA)
rgb_3 = unit.get(unit.RGB, unit.PORTB)
light_3 = unit.get(unit.LIGHT, unit.PORTB)






bightness = M5TextBox(238, 151, "Text", lcd.FONT_DejaVu24, 0xf00101, rotate=270)
label1 = M5TextBox(49, 166, "Sunlight", lcd.FONT_DejaVu18, 0xf9fe00, rotate=270)
circle0 = M5Circle(160, 128, 30, 0xFFFFFF, 0xFFFFFF)
rectangle0 = M5Rect(153, 0, 13, 240, 0xFFFFFF, 0xFFFFFF)

def buttonB_wasPressed():
  # global params
  while True:
    bightness.setText(str(light_3.analogValue))
    if (light_3.analogValue) < 200:
      wait(0.1)
      pbhub1.setBrightness(0, 150)
      wait(0.1)
      pbhub1.setColor(0, 0, 3, 0x3366ff)
      wait(0.1)
      pbhub1.setColor(0, 0, 3, 0x3366ff)
    else:
      wait(0.1)
      pbhub1.setColor(0, 0, 3, 0x000000)
      wait(0.1)
    wait_ms(2)
  pass
btnB.wasPressed(buttonB_wasPressed)


while True:
  bightness.setText(str(light_3.analogValue))
  if (light_3.analogValue) < 200:
    wait(0.1)
    pbhub1.setBrightness(0, 150)
    wait(0.1)
    pbhub1.setColor(0, 0, 3, 0xff0000)
    wait(0.1)
    pbhub1.setColor(0, 0, 3, 0xff0000)
  else:
    wait(0.1)
    pbhub1.setColor(0, 0, 3, 0x000000)
    wait(0.1)
  wait_ms(2)

Credits

Justin

Justin

1 project • 3 followers
Jey yagheswar

Jey yagheswar

1 project • 3 followers
Shawn

Shawn

1 project • 3 followers

Comments