Zheng Yu
Published

(Team 3) Delta 0 Greenhouse Monitoring System

By: Zheng Yu (Leader), Nathan, Malcolm, Yap Xiang

BeginnerWork in progress16
(Team 3) Delta 0 Greenhouse Monitoring System

Things used in this project

Story

Read more

Schematics

Circuit Setup

Code

Code

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

setScreenColor(0x222222)
env21 = unit.get(unit.ENV2, unit.PAHUB1)
rfid1 = unit.get(unit.RFID, unit.PAHUB0)
servo0 = unit.get(unit.SERVO, unit.PORTB)
pbhub0 = unit.get(unit.PBHUB, unit.PAHUB2)
pahub1 = unit.get(unit.PAHUB, unit.PORTA)


RFID = None
setup = None
x = None
y = None
Aircon = None
Temp = None
earth = None


label0 = M5TextBox(9, 15, "Temperature:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label2 = M5TextBox(192, 15, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label6 = M5TextBox(9, 131, "Aircon :", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label7 = M5TextBox(192, 131, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label8 = M5TextBox(109, 88, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label4 = M5TextBox(9, 45, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label5 = M5TextBox(9, 159, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label9 = M5TextBox(60, 217, "+", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label10 = M5TextBox(149, 217, "-", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label1 = M5TextBox(9, 88, "Moisture:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label3 = M5TextBox(246, 15, "Deg C", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonA_wasPressed():
  global RFID, setup, x, y, Aircon, Temp, earth
  if RFID >= 1:
    if x == 0:
      if Aircon == 28:
        label5.setText('Maximum Temperature')
      elif Aircon < 28:
        label5.hide()
        Aircon = (Aircon if isinstance(Aircon, Number) else 0) + 1
  elif RFID == 0:
    label5.setText('Press Button C')
    y = (y if isinstance(y, Number) else 0) + 1
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
  global RFID, setup, x, y, Aircon, Temp, earth
  if RFID >= 1:
    if x == 0:
      if Aircon == 18:
        label5.setText('Minimum Temperature')
      elif Aircon > 18:
        label5.hide()
        Aircon = (Aircon if isinstance(Aircon, Number) else 0) + -1
  elif RFID == 0:
    label5.setText('Press Button C')
    y = (y if isinstance(y, Number) else 0) + 1
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
  global RFID, setup, x, y, Aircon, Temp, earth
  label5.setText('Scan Card')
  if rfid1.isCardOn():
    if (rfid1.readUid()) == '40b93f9cf':
      label5.setText('Nathan')
      RFID = 1
      timerSch.run('timer1', 10000, 0x01)
      label5.setText('Access Granted')
      y = 0
    else:
      label5.setText('Access Denied')
      wait(1)
      label5.setText('Scan Again')
      y = 1
  pass
btnC.wasPressed(buttonC_wasPressed)

@timerSch.event('timer1')
def ttimer1():
  global RFID, setup, x, y, Aircon, Temp, earth
  RFID = 0
  pass


setup = 1
x = 0
Aircon = 20
y = 0
RFID = 0
while True:
  Temp = env21.temperature
  earth = pbhub0.analogRead(0)
  label7.setText(str(Aircon))
  label2.setText(str(Temp))
  if Temp < 15:
    speaker.sing(247, 2)
    speaker.setVolume(0)
    label4.setText('Temperature Low')
  elif Temp < 25:
    label4.setText('Temperature Optimal')
  elif Temp > 25:
    speaker.sing(220, 2)
    speaker.setVolume(0.1)
    label4.setText('Temperature High')
  if earth >= 700:
    label8.setText('Dry, Watering Now')
    servo0.write_angle(90)
    wait(1)
    servo0.write_angle(10)
    wait(3)
  elif earth < 700:
    label8.setText('Good Moisture')
  wait_ms(2)

Credits

Zheng Yu

Zheng Yu

0 projects • 0 followers

Comments

Add projectSign up / Login