Soil moisture sensor with message notification

This project comes in handy for people that love gardening. The idea is simple, monitoring the soil humidity and notifying the Gardner.

BeginnerShowcase (no instructions)5 hours1,472
Soil moisture sensor with message notification

Things used in this project

Story

Read more

Schematics

Connect the bluetooth module

Connect the sensor

Connect the Led

Code

code.py

Python
from machine import ADC, Pin, Timer, UART
import utime
uart = UART(0,9600)
#ledplacuta
led_placuta = Pin(25, Pin.OUT)
timer = Timer()
def blink(timer):
    led_placuta.toggle()
    
#led pus de noi
led = Pin(14, Pin.OUT)

# use variables instead of numbers:
soil = ADC(Pin(26)) # Soil moisture PIN reference
#Calibraton values
min_moisture=0
max_moisture=45235

readDelay = 2 # delay between readings

send=UART(0,9600)
while True:
    message=''
    moisture = (min_moisture+soil.read_u16())*100/(max_moisture-min_moisture)
    message=str(moisture)
    print("moisture: " + "%.2f" % moisture +"% (adc: "+str(soil.read_u16())+")")
    if moisture < 1:
        print("Florile au nevoie de apa")
        message+="  u" 
        led.value(1)
    elif moisture > 70:
        print(" Florile au prea multa apa")
        message+=" s" 
        led.value(1)
    else:
        led.value(0)
    send.write(message)
    utime.sleep(readDelay) # set a delay between readings
    timer.init(freq=25, mode=Timer.PERIODIC, callback=blink)
led.value(0)
    
    

Credits

Gelu-Florin Boldureanu

Gelu-Florin Boldureanu

1 project • 3 followers
Vecliuc Draia-Teodora

Vecliuc Draia-Teodora

0 projects • 0 followers
Marian-Gabriel Nechifor

Marian-Gabriel Nechifor

0 projects • 1 follower
Thanks to monur.

Comments