We are going to build an automatic fish feeder which can feed the fish every 24 hours.
It will have a knob to control the food portion.
By default, it will feed the fish every day at 8AM but there will be 2 buttons to set the custom time.
Also, there will be a display, which will show details like set time, portion size, real-time, and temperature.
The device runs on a 9V power supply.
It will have a knob to control the food portion.
By default, it will feed the fish every day at 8AM but there will be 2 buttons to set the custom time.
Also, there will be a display, which will show details like set time, portion size, real-time, and temperature.
The device runs on a 9V power supply.
Required Components
- Raspberry Pi Pico
- 3D Printed Funnel
- 9V Motor
- 5V Relay
- RTC Clock
- Display Module
- Potentiometer
- Push Button
- LM 7805
- LM 7809
- 9V Power Adapter
- DC power Female Adapter
- Capacitor
- Resistor
- Vero Board
- Soldering Tools
- Acrylic Sheet
- Other random parts and components
Circuit Diagram
Code
from machine import I2C, Pin
from urtc import DS1307
from ssd1306 import SSD1306_I2C
import utime
import machine
import time
counter=-1
motor=Pin(2, Pin.OUT)
led=Pin(25,Pin.OUT)
push_button = Pin(3, Pin.IN)
push_button1 = Pin(5, Pin.IN)
push_button2 = Pin(4, Pin.IN)
analog_value1 = machine.ADC(28)
analog_value2 = machine.ADC(27)
analog_value3 = machine.ADC(26)
led1=Pin(11,Pin.OUT)
led2=Pin(12,Pin.OUT)
led3=Pin(13,Pin.OUT)
led4=Pin(14,Pin.OUT)
led5=Pin(15,Pin.OUT)
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
i2c1 = I2C(1,sda = Pin(6), scl = Pin(7), freq=200000)
oled = SSD1306_I2C(128, 64, i2c1)
i2c0 = I2C(0,sda = Pin(0), scl = Pin(1), freq=400000)
rtc = DS1307(i2c0)
print("Current time:" + str(rtc.datetime()))
def map(x, in_min, in_max, out_min, out_max):
""" Maps two ranges together """
return int((x-in_min) * (out_max-out_min) / (in_max - in_min) + out_min)
def action():
if counter==-1 and hour == 8 and minute == 0 and second == 0: #set time for feeding
motor.value(1)
utime.sleep(unit)
elif hour==counter and minute== 0 and second==0:
motor.value(1)
utime.sleep(unit)
else:
motor.value(0)
def button():
if logic_state == 1:
motor.value(1)
else:
motor.value(0)
def active():
led.toggle()
while True:
if push_button1.value()==1:
print("Button Pressed")
counter+=1
elif push_button2.value()==1:
print("Button 2 prssed")
counter-=1
print("Count={}".format(counter))
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
#print(temperature)
(year,month,date,day,hour,minute,second,p1)=rtc.datetime()
logic_state = push_button.value()
reading1 = analog_value1.read_u16()
unit = map(reading1,0, 65535,1,5)
#print("Unit", unit)
#print("time_hour",time_hour)
#print("time_hour",time_minute)
#print(hour,":",minute,":",second)
oled.fill(0)
oled.text("Time: ", 0, 0)
oled.text((str(hour) + ":" + str(minute) + ":" + str(second)), 40, 0)
oled.text("Feed: ", 0, 15)
oled.text(str(counter), 40, 15)
oled.text("Hours", 60,15)
oled.text("Temp: ",0,30)
oled.text(str(round(temperature,1)),50,30)
oled.text("*C",85,30)
oled.text("Portion:",0,45)
oled.text(str(unit),70,45)
oled.show()
action()
button()
active()
utime.sleep(0.2)
from urtc import DS1307
from ssd1306 import SSD1306_I2C
import utime
import machine
import time
counter=-1
motor=Pin(2, Pin.OUT)
led=Pin(25,Pin.OUT)
push_button = Pin(3, Pin.IN)
push_button1 = Pin(5, Pin.IN)
push_button2 = Pin(4, Pin.IN)
analog_value1 = machine.ADC(28)
analog_value2 = machine.ADC(27)
analog_value3 = machine.ADC(26)
led1=Pin(11,Pin.OUT)
led2=Pin(12,Pin.OUT)
led3=Pin(13,Pin.OUT)
led4=Pin(14,Pin.OUT)
led5=Pin(15,Pin.OUT)
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
i2c1 = I2C(1,sda = Pin(6), scl = Pin(7), freq=200000)
oled = SSD1306_I2C(128, 64, i2c1)
i2c0 = I2C(0,sda = Pin(0), scl = Pin(1), freq=400000)
rtc = DS1307(i2c0)
print("Current time:" + str(rtc.datetime()))
def map(x, in_min, in_max, out_min, out_max):
""" Maps two ranges together """
return int((x-in_min) * (out_max-out_min) / (in_max - in_min) + out_min)
def action():
if counter==-1 and hour == 8 and minute == 0 and second == 0: #set time for feeding
motor.value(1)
utime.sleep(unit)
elif hour==counter and minute== 0 and second==0:
motor.value(1)
utime.sleep(unit)
else:
motor.value(0)
def button():
if logic_state == 1:
motor.value(1)
else:
motor.value(0)
def active():
led.toggle()
while True:
if push_button1.value()==1:
print("Button Pressed")
counter+=1
elif push_button2.value()==1:
print("Button 2 prssed")
counter-=1
print("Count={}".format(counter))
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
#print(temperature)
(year,month,date,day,hour,minute,second,p1)=rtc.datetime()
logic_state = push_button.value()
reading1 = analog_value1.read_u16()
unit = map(reading1,0, 65535,1,5)
#print("Unit", unit)
#print("time_hour",time_hour)
#print("time_hour",time_minute)
#print(hour,":",minute,":",second)
oled.fill(0)
oled.text("Time: ", 0, 0)
oled.text((str(hour) + ":" + str(minute) + ":" + str(second)), 40, 0)
oled.text("Feed: ", 0, 15)
oled.text(str(counter), 40, 15)
oled.text("Hours", 60,15)
oled.text("Temp: ",0,30)
oled.text(str(round(temperature,1)),50,30)
oled.text("*C",85,30)
oled.text("Portion:",0,45)
oled.text(str(unit),70,45)
oled.show()
action()
button()
active()
utime.sleep(0.2)
Comments
Post a Comment