Automatic Fish Feeder - Part 2


Fish Feeder Schematic
My quick, crappy schematic drawing

The schematic is extremely simple. I tried to use parts that I already has on hand. I have a few weak stepper motors that I got from an overstock website (MOTOR1). The protection diodes (D1-4) are there to short the surge currents created by the motor coils. This will prevent the MOSFETs (Q1-4) from being destroyed over time. The gates of the MOSFETs are connected to bits <3-0> of Port C on the PICmicro. To minimize the number of parts, I used the built-in oscillator as the PICmicro's system clock. The power supply is a 5V power cable/battery charger for an old cell phone I had.

Source Code

The source code for this project was much more complicated in the beginning. As debugging became more and more frustrating, I rewrote it in the extremely simple version you see below. It is written for the SourceBoost BoostC compiler.

#include <system.h>


* Timer0 prescaler 1:256
* Feed twice a day
* Timer ticks before-prescaler at 1 MHz (4 MHz oscillator)
* Every second is 3906.25 ticks
* Every 12 hours is 168,750,000
#define TICKS_RESET 168750000


void feed (void)

    portc = 0b00000110;    // Turn on stepper motor

    unsigned char j;
    for (j = 0; j < 2; ++j)
        unsigned char i;
        for (i = 0; i < 12; ++i)
            portc = 0b00001010;
            portc = 0b00000011;
            portc = 0b00000101;
            portc = 0b00001100;
    portc = 0b00000000;    // Turn off stepper motor


void main (void)
    option_reg = 0b01010111;

    trisa = 0b11111111;
    ansel = 0x00;
    wpua = 0xFF;
    ioca = 0x00;

    trisc = 0xF0;

    while (1)
        signed short i = 720;
        for ( ; i >= 0; --i)

This code turns the motor one complete revolution every 12 hours. It doesn't minimize power consumption or use interrupts. That would be a lot better, but this started as just a quick project to last for a weekend or two.