"""
IoT based automated water regulation system for fish farming
Main file IoT fish Pond
Date 28/11/2023
version: 1.0
*********Sensors********************
OLED display
ph sensor
ds18x20.py --> temperature sensor
water level sensor
****** Actuator ********************
4 channel relay -> valves 1,2,3 and pump 4 (220V)
**** PIN configuration *****
OLED_SDA-> Pin(0)
OLED_SCL-> Pin(1)
Relay_1 -> Pin(2)
Relay_2 -> Pin(3)
Relay_3 -> Pin(4)
Relay_4 -> Pin(5)
"""
# import your library
from machine import Pin, I2C
import time
from ssd1306 import SSD1306_I2C # OLED
import onewire # Temperature sensor
import ds18x20 # Temperature sensor
# connect to Wi-Fi
# connect to MQTT
# configure GPIO pins OLED
i2c = I2C(0,sda=Pin(0), scl=Pin(1), freq=400000) # Initialize I2C communication
# Initialize OLED display
oled = SSD1306_I2C(128, 64, i2c)
# display the following info on the OLED
oled.fill(0) # Clear the OLED display
oled.text(" IoT Fish Pond", 0, 0)
oled.text(" Supervised by:",5, 10)
oled.text("Dr. Stella O. ",5, 20)
oled.text(" Designed by:", 7, 30)
oled.text(" Peculiar .C", 5, 40)
oled.text(" Blessing .O", 5, 50)
oled.show()
time.sleep(5) # Sleep for 5 seconds
oled.fill(0) # Clear the display
oled.show()
# configure GPIO pins for the 4 channel Relay
valve_1 = Pin(2, Pin.OUT) # control valve 1
valve_2 = Pin(3, Pin.OUT) # control valve 2
valve_3 = Pin(4, Pin.OUT) # control valve 3
pump = Pin(5, Pin.OUT) # control pump
water_level_tank = Pin(20, Pin.IN) # tank water level sensor
water_level_pond = Pin(21, Pin.IN) # pond water level sensor
# configure GPIO pin for temperature sensor
temp_pin = Pin(7)
# Create a OneWire object and a DS18X20 object
ow = onewire.OneWire(temp_pin)
temp_sensor = ds18x20.DS18X20(ow)
# configure GPIO pin for pH sensor
# initialize paramters
oled_msg = " IoT Fish Pond"
tank_level = 1
pond_level = 1
pH_value = 1
temp = 20
valve = [1,2,3 ]
#pump = 0
# function to read temperature sensor
def read_temperature():
pass
# function to read PH sensor
def read_pH():
pass
# function to read water level sensor
def read_water_level(pin):
pass
# function to on relay
def on_relay(pin):
pin.value(1)
# function to off relay
def off_relay(pin):
pin.value(0)
# function to off relay
def display_default(tank_level, pond_level, pH_value, temp, valve):
#oled_msg = " IoT Fish Pond"
oled.text(oled_msg, 0, 0)
oled.text(f"Tank Level: {tank_level}",0,10 )
oled.text(f"Pound Level: {pond_level}",0,20 )
oled.text(f"pH_value: {pH_value}",0,30 )
oled.text(f"Temp_value: {temp}",0,40 )
oled.text(f"Value: {valve}",0,50 )
oled.show()
while True:
#oled_msg = " IoT Fish Pond"
#tank_level = 1
pond_level = 1
pH_value = 1
temp = 20
valve = [1,2,3 ]
display_default(tank_level, pond_level, pH_value, temp, valve)
# Check tank level and control pump
def check_water_tank():
if tank_level < 1.5:
pump.on()
time.sleep(1)
if tank_level > 3:
pump.off()
tank_level = tank_level+0.1
print(tank_level)
def check_pond_water():
# check pond level and control pump
read_water_level()
if pond_level < 1.5: # low level
off_relay(pump)
def check_pond_condition():
read_temperature()
read_pH()