JasmirJeric BehLim Weihan
Published © GPL3+

Smart Plant Monitor for Sustainable Urban Farming

My project aims to create a Smart Plant Monitor for Sustainable Urban Farming that promotes sustainable urban agriculture globally.

BeginnerWork in progressOver 8 days240
Smart Plant Monitor for Sustainable Urban Farming

Things used in this project

Story

Read more

Code

Main M5stack

Python
from m5stack import *
from m5ui import *
from uiflow import *
import time
from m5mqtt import M5mqtt
import json

import unit

setScreenColor(0x222222)
earth_7 = unit.get(unit.EARTH, unit.PORTB)
servo_5 = unit.get(unit.SERVO, unit.PORTA)


moisture = None



image0 = M5Img(110, 70, "res/droplet.png", True)
label0 = M5TextBox(22, 21, "Moisture Level:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label1 = M5TextBox(234, 21, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)



def buttonA_wasPressed():
  global moisture
  servo_5.write_angle(0)
  wait(4)
  servo_5.write_angle(90)
  pass
btnA.wasPressed(buttonA_wasPressed)


label1.hide()
m5mqtt = M5mqtt('2ccd482d-ad87-4b64-9bc1-03be4c4d7112', 'broker.qubitro.com', 1883, '2ccd482d-ad87-4b64-9bc1-03be4c4d7112', '1739333691334022897aae6f2909ae3f1b23f3d4523f6ad7033c92b79b74d161fd38516ee6d6284d3af3a8d93c17337206b', 300)
m5mqtt.start()
while True:
  moisture = earth_7.analogValue
  m5mqtt.publish(str('2ccd482d-ad87-4b64-9bc1-03be4c4d7112'), str((json.dumps(({'Moisture':(earth_7.analogValue)})))), 0)
  if moisture < 200:
    speaker.tone(1800, 200)
    rgb.setColorAll(0xff0000)
    servo_5.write_angle(0)
    label1.setText('Low')
    image0.changeImg("res/default.jpg")
  elif moisture >= 200 and moisture < 300:
    rgb.setColorAll(0x3366ff)
    label1.setText('Average')
  else:
    rgb.setColorAll(0x33cc00)
    servo_5.write_angle(90)
    image0.changeImg("res/default.jpg")
    label1.setText('High')
  wait(1)
  wait_ms(2)

Secondary M5stack

Python
from m5stack import *
from m5ui import *
from uiflow import *
from m5mqtt import M5mqtt
import json

import time
import unit


setScreenColor(0x222222)
light_3 = unit.get(unit.LIGHT, unit.PORTB)
tof_0 = unit.get(unit.TOF, unit.PORTA)


light = None
Plantheight = None



image0 = M5Img(103, 134, "res/default.jpg", True)
label2 = M5TextBox(39, 26, "Light:", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0)
label3 = M5TextBox(214, 47, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label4 = M5TextBox(266, 112, "cm", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(0, 89, "Distance:", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0)
label1 = M5TextBox(215, 99, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)




m5mqtt = M5mqtt('34471889-3e7a-4fd7-9a55-226cffae70e1', 'broker.qubitro.com', 1883, '34471889-3e7a-4fd7-9a55-226cffae70e1', '1739339137679760396456757715b5a2d6b56515eb14d4b73dcae27e84f2c31b0c67a1670e672831d101e542bdf96f5c1ba', 300)
m5mqtt.start()
while True:
  light = light_3.analogValue
  Plantheight = (240 - (tof_0.distance)) / 10
  label1.setText(str(Plantheight))
  label3.setText(str(light))
  m5mqtt.publish(str('34471889-3e7a-4fd7-9a55-226cffae70e1'), str((json.dumps(({'Height':Plantheight})))), 0)
  if light < 400:
    rgb.setColorAll(0xff99ff)
    image0.changeImg("res/No sun.png")
  else:
    image0.changeImg("res/Sun.png")
    rgb.setColorAll(0x006600)
  wait(1)
  wait_ms(2)

Credits

Jasmir
1 project • 0 followers
Jeric Beh
0 projects • 0 followers
Lim Weihan
0 projects • 0 followers

Comments