This week, we added servo motor and the ultrasonic sensor into the circuit. It worked great. So basically whenever the RTC counts to the preset time, the feeding function starts.
The feeding function first takes in the distance from ultrasonic sensor. If the distance is higher than a certain number (which means the bowl is empty because we are putting the sensor above the bowl), the motor will turn about 180 degrees opening the food feeding valve. Then the ultrasonic sensor will continuously read distance until the point the distance is equal or smaller to the preset feeding amount. And the servo will turn backwards to close the gate.
Next we need to consider the algorithm a little further. Suppose something is stuck between the bowl and the ultrasonic sensor, in our current algorithm, the motor will never turn and food will never be fed. So we need some sort of protection against that. Also, it's time to combine the electronics with mechanical structure to configure the system for it to actually work.