Plant Watering System
2022-02-15 | By M5Stack
License: General Public License Humidity Arduino
* Thanks for the source code and project information provided by @C1 Group 1
Nowadays people are too busy with work and/or studies to properly take care of their plants at home. It could come to the point that they might completely neglect them, causing the plants to dehydrate, wilt, and die. With this system, plants can still be cared for even if people are away for a long time.
The system uses an Earth sensor that detects moisture in the soil. If it detects low moisture, the LED will turn red and the buzzer will turn on to notify the user. A servo motor then proceeds to let out water from a container which will then flow into the plant's soil.
Code
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
setScreenColor(0x222222)
earth0 = unit.get(unit.EARTH, unit.PORTB)
servo1 = unit.get(unit.SERVO, unit.PORTA)
label0 = M5TextBox(14, 109, "Text", lcd.FONT_DejaVu18, 0xffffff, rotate=0)
rectangle1 = M5Rect(-94, 190, 1000, 50, 0xff0000, 0xFFFFFF)
rectangle2 = M5Rect(-101, 0, 1000, 50, 0x22ff00, 0xFFFFFF)
while True:
rectangle1.hide()
rectangle2.show()
servo1.write_angle(0)
if (earth0.analogValue) <= 20:
rectangle1.show()
rectangle2.hide()
rgb.setColorAll(0xff0000)
label0.setColor(0xff0000)
label0.setText('MOISTURE LOW, WATERING...')
servo1.write_angle(90)
speaker.tone(800, 200)
wait(2)
speaker.tone(800, 0)
else:
rectangle1.hide()
rectangle2.show()
rgb.setColorAll(0x000000)
label0.setColor(0x33ff33)
label0.setText('MOISTURE LEVEL OK')
servo1.write_angle(0)
wait_ms(2)
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum