Skip to main content

Automatic Fish Feeder using Raspberry Pi Pico



Introduction
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.

Required Components
  1. Raspberry Pi Pico
  2. 3D Printed Funnel
  3. 9V Motor
  4. 5V Relay
  5. RTC Clock
  6. Display Module
  7. Potentiometer
  8. Push Button
  9. LM 7805
  10. LM 7809
  11. 9V Power Adapter
  12. DC power Female Adapter
  13. Capacitor
  14. Resistor
  15. Vero Board
  16. Soldering Tools
  17. Acrylic Sheet
  18. Other random parts and components

Circuit Diagram



Automatic fish feeder using raspberry pi pico



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)

Comments

Popular posts from this blog

Macropad using Raspberrypi Pico and Circuit Python

A budget-friendly DIY macro pad or a replacement for the Elgato stream deck. Components Required Cherry MX Switches Raspberry Pi Pico LED- the color of your choice Copper clad and other related items to make PCB board Other miscellaneous items Circuit Diagram PCB and Circuit Diagram via EasyEDA Project Link https://oshwlab.com/anurag_mehta/macropad-pcb Code: import time import digitalio import board import usb_hid import rotaryio from adafruit_hid.keyboard import Keyboard from adafruit_hid.keycode import Keycode from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.consumer_control import ConsumerControl from adafruit_hid.consumer_control_code import ConsumerControlCode led = digitalio.DigitalInOut(board.LED) led.direction = digitalio.Direction.OUTPUT keyboard = Keyboard(usb_hid.devices) write_text = KeyboardLayoutUS(keyboard) button = digitalio.DigitalInOut(board.GP15) button.direction = digitalio.Direction.INPUT button.pull = digitalio.Pull.UP encoder = rotar...