Chen RainChuranBaulsWatlet
Published

Automatic Plant Watering System

It is an automatic plant watering system that will help to water the plants when the soil is too dry.

IntermediateFull instructions provided2 hours548
Automatic Plant Watering System

Things used in this project

Story

Read more

Schematics

photo of how to connect

M5Stack, Pa.Hub to port A, Earth sensor to Port B, ENV II sensor to the Pa.Hub Port 0 and servo motor to the Pa.Hub port 1

Code

M5Stack code for watering plants

Python
It is simple to use. Just run it and there is a QR code that can be accessed when you press on Remote+ and a phone will appear. Click on the QR code icon to access the QR code. Apart from that, the button on the M5Stack can be used to adjust the preference of how moist the user wants the soil to be
from m5stack import *
from m5ui import *
from uiflow import *
from servo import Servo
import time
import unit
remoteInit()

setScreenColor(0x222222)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA, 0x70)
env2_0 = unit.get(unit.ENV2, unit.PAHUB0)
earth_0 = unit.get(unit.EARTH, unit.PORTB)


switch_value = None
WhenToWater = None
HowMoistUserWantsItToBe = None
OpenOrNot = None



TemperatureName = M5TextBox(43, 13, "Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
TemperatureValue = M5TextBox(143, 13, "Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
WHentowaterlabel = M5TextBox(30, 129, "When to water:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
HumidityName = M5TextBox(69, 42, "Humidity:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
WhenToWaterValue = M5TextBox(156, 129, "When to water:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
HumidityValue = M5TextBox(156, 42, "Humidity:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
MoistureName = M5TextBox(70, 79, "Moisture:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
MoistureValue = M5TextBox(156, 79, "Moisture:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
MoistValue = M5TextBox(168, 184, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
MoistMEter = M5TextBox(54, 184, "MoistMeter:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(34, 219, "Decrease", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(208, 224, "Increase", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonA_wasPressed():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot
  if HowMoistUserWantsItToBe > 0:
    HowMoistUserWantsItToBe = (HowMoistUserWantsItToBe if isinstance(HowMoistUserWantsItToBe, Number) else 0) + -1
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonC_wasPressed():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot
  if HowMoistUserWantsItToBe < 100:
    HowMoistUserWantsItToBe = (HowMoistUserWantsItToBe if isinstance(HowMoistUserWantsItToBe, Number) else 0) + 1
  pass
btnC.wasPressed(buttonC_wasPressed)



def switch_1_callback(switch_value):
  global WhenToWater, HowMoistUserWantsItToBe, OpenOrNot, pahub_0, env2_0, earth_0 
  print(switch_value)
  if switch_value == 1:
    rgb.setColorAll(0xffffff)
  elif switch_value == 0:
    rgb.setColorAll(0x000000)

def gauge_3_callback():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot, pahub_0, env2_0, earth_0 
  return WhenToWater
def gauge_Temperature_callback():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot, pahub_0, env2_0, earth_0 
  return env2_0.temperature
def gauge_Humidity_callback():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot, pahub_0, env2_0, earth_0 
  return env2_0.humidity
def gauge_5_callback():
  global WhenToWater, HowMoistUserWantsItToBe, switch_value, OpenOrNot, pahub_0, env2_0, earth_0 
  return earth_0.analogValue
pahub_0.select(1, 1)
servo0 = Servo(21,50,500,2500,180)
servo0.write_angle(0)
wait(1)
pahub_0.select(1, 0)
HowMoistUserWantsItToBe = 50
OpenOrNot = 0
while True:
  WhenToWater = 10 * (HowMoistUserWantsItToBe + (env2_0.temperature) * 0.1 - (env2_0.humidity) * 0.1)
  if (earth_0.analogValue) <= WhenToWater and OpenOrNot == 0:
    pahub_0.select(1, 1)
    servo0 = Servo(21,50,500,2500,180)
    servo0.write_angle(1)
    wait(1)
    pahub_0.select(1, 0)
    wait(3)
    OpenOrNot = 1
  elif (earth_0.analogValue) > WhenToWater and OpenOrNot == 1:
    pahub_0.select(1, 1)
    servo0 = Servo(21,50,500,2500,180)
    servo0.write_angle(90)
    wait(1)
    pahub_0.select(1, 0)
    wait(1)
    OpenOrNot = 0
  MoistureValue.setText(str(earth_0.analogValue))
  TemperatureValue.setText(str(env2_0.temperature))
  HumidityValue.setText(str(env2_0.humidity))
  MoistValue.setText(str(HowMoistUserWantsItToBe))
  WhenToWaterValue.setText(str(WhenToWater))
  wait(1)
  wait_ms(2)

Credits

Chen Rain
1 project • 0 followers
Churan
1 project • 0 followers
Bauls
1 project • 0 followers
Watlet
1 project • 0 followers

Comments