ok, first figure out how you’re going to determine if there are pills in the container to dispense, then how you’re going to get them out one at a time.
Forget the Arduino at the moment.
You’re asking a problem that requires observation and mechanical answers.
We can help you address the logical part after you figure out the first two.
Detecting pills... weight? Optical ? Counting from a known number...?
Dispensing... tipping the bottle? an augur (without smashing the pill or over-dispensing multiples... some other mechanism?
Over to you.