Search

Automatic pill dispenser

Updated: Aug 18



I constantly forget to take my medication, I've always wanted some kind of a pill dispenser so that I don't forget.

but looking around the only pill dispensers that come up are ones that are just cheap plastic

containers that make me feel like a pensioner

and on the other end some of them cost more than 3 times my rent, there are also some subscription models but I like many don't appreciate having to pay a monthly subscription to a physical object.

so I decided to design my own one, and after a lot of tests and revisions.

you can learn more about the development process in the dedicated YouTube video


but here we're just going to skip to the point this is version 6 of the automatic pill dispenser


The D1 Mini is running esphome which let me control it through home assistant,

The Raspberry Pi Pico is hard coded to to dispense a pill check if the vibration sensor went off, if it hasn't try again until it does and then moved to another pill.


the code can be improved hugely eventually I'm planning for it to have a web interface to schedule pills being dispensed but I'm much better at designing than I am programming.


here is the code for the Pico

from machine import Pin, PWM, ADC,
from time import sleep
import utime

button = Pin(4, Pin.IN, Pin.PULL_DOWN)
analog_value = ADC(26)

servo0Pin = PWM(Pin(16))
servo0Pin.freq(40)

servo1Pin = PWM(Pin(17))
servo1Pin.freq(40)

servo2Pin = PWM(Pin(18))
servo2Pin.freq(40)

def dropcheck():
    raw = analog_value.read_u16()
    hellow = 0 + (raw - 0) * (1 - 0) / (60000 - 0)
    if int(hellow) == 1:
        return True
    else:
        return False

def servo0():
    print('servo0')
    servo0Pin.duty_u16(6866)
    sleep(1)
    servo0Pin.duty_u16(2333)
    sleep(1)
    servo0Pin.duty_u16(1000)
    sleep(0.5)
    servo0Pin.duty_u16(0)
    if dropcheck() == False:
        servo0()
    else:
        return

def servo1():
    print('servo1')
    servo1Pin.duty_u16(6866)
    sleep(1)
    servo1Pin.duty_u16(2333)
    sleep(1)
    servo1Pin.duty_u16(1000)
    sleep(0.5)
    servo1Pin.duty_u16(0)
    if dropcheck() == False:
        servo1()
    else:
        return

def servo2():
    print('servo2')
    servo2Pin.duty_u16(6866)
    sleep(1)
    servo2Pin.duty_u16(2333)
    sleep(1)
    servo2Pin.duty_u16(1000)
    sleep(0.5)
    servo2Pin.duty_u16(0)
    if dropcheck() == False:
        servo2()
    else:
        return

while True:
    if button.value():
        servo0()
        servo1()
        servo2()

the STLs are available

https://www.printables.com/model/215611-automatic-pill-dispensers


1,222 views0 comments

Recent Posts

See All