Automatic Pill Dispensor
I created an automatic pill dispenser for my home automation project because my mother and sister have very bad migraines. I thought that it would be helpful to make a pill dispenser since sometimes either my mom or sister misplaces the bottle of migraine pills that they both use. Sometimes, my sister takes the bottle mistakingly to school and my mom is left with nothing. A fully reloaded pill dispenser would allow my mom to have some pills left in the house and my sister to take some to school with her.
This project was originally going to have facial recognition as the trigger. It was supposed to exclusively recognize my sister's and mother's faces and then dispense a migraine pill to them. Unfortunately, I was unable to download OpenCV, the python framework necessary for the facial recognition feature, since I kept running into errors. I first tried downloading OpenCV while having the Raspbian Buster OS as required in the tutorial that I was using. However, when I tried the installation through its source code on the terminal, many of the dependencies did not download causing the installation process to be defective. I then tried doing the same thing but by using another raspberry pi os named 'Bullseye' as it was the newest version. Many dependencies were downloaded this time, but there were still problems with the -CMAKE command towards the end of the installation. At one point I was able to successfully download OpenCV, however, there were still problems importing it to a python file. I knew the reason was that the numpy version was not compatible with the version of OpenCV that I had downloaded. I tried the commands to get them both up to date and even looked up which versions were compatible. I was still unable to unfortunately get it done. I spent a month (4 weeks) trying to download OpenCV due to my resilience, but I knew I had to turn something in for my project. Now I know that the next time someone warns me about something being too hard to do, I have to take it seriously despite how capable I think I may be.
Supplies
The following supplies are needed to make this pill dispenser:
- Argon computing device
- Particle Argon web IDE
- Breadboard
- 10 male-to-male jumper wires
- Two Servos
- Cardboard Box
- Cardboard
- Cylindrical object (such as a pringles can)
- A paper towel roll
- Medicine bottle (optional as explained later)
- Double-sided tape
- Duck Tape
- A circular pill container
- A cutting knife
- A platform for the bottom servo to catch the pill
Setting Up the Circuit With Servos
- Place the argon towards the top of the breadboard
- Power the Argon
- Grab six male-to-male jumper wires and connect one to each slot of the Servo sockets
- You're going to want to connect the wire that is connected to red wire to the VUSB port on the Argon, the black one to ground, and the orange one to a pin of your choice
- Do the same for the second servo
- Place the button slightly above the argon as well (as shown in the picture)
- The picture above attempts to represent the circuit that was used for this project
Adding the Firmware
Below is the code to allow the button on your breadboard to move the servos. When the button is pressed a certain amount of degrees, the servo will move a certain amount of degrees so that the next pill can be dispensed. Here is the link to set up your Particle Argon account: https://www.particle.io/
Servo myFirstServo;
Servo mySecondServo;
int analogPinFirst = 8;
int analogPinSecond = 4;
int button = 5;
int counter = 0;
unsigned long lastTime = millis();
bool isPressed = false;
bool hasIncremented = true;
int angle = 45;
void setup() {
pinMode(button, INPUT_PULLUP);
myFirstServo.attach(analogPinFirst);
myFirstServo.write(30);
mySecondServo.attach(analogPinSecond);
mySecondServo.write(10);
}
void loop() {
int btnState = digitalRead(button);
if (btnState == HIGH && isPressed == true) {
isPressed = false;
hasIncremented = false;
lastTime = millis();
}
if (btnState == LOW && isPressed == false) {
isPressed = true;
hasIncremented = false;
counter++;
lastTime = millis();
}
if (counter == 1 && hasIncremented == false) {
myFirstServo.write(angle);
hasIncremented = true;
lastTime = millis();
mySecondServo.write(170);
delay(1500);
mySecondServo.write(10);
}
if (counter > 1 && hasIncremented == false) {
lastTime = millis();
angle+= 20;
lastTime = millis();
myFirstServo.write(angle);
lastTime = millis();
hasIncremented = true;
lastTime = millis();
mySecondServo.write(170);
delay(1500);
mySecondServo.write(10);
}
}
Setting Up the Box
- Take a big box like the one shown above (no specific dimension requirements)
- Cut an opening on the bottom for the servo to be placed
- Take a servo and tape a platform on top, I used the packaging of a MicroSD card as it was the only thing I had
- Place the servo inside the box right next to the opening so that when it rotates, it can dispense the pill out of the box (you will see this in the video later)
- Insert the circuit that we have just set up on an opening in the box just as shown above be careful which servo is which for the programming as the pins matter
Making the Catridge
- Use a circular pill container as shown above
- Using a knife cut holes in the bottom of each section with a small knife (the part without the flaps that open)
- Next take small pieces of cardboard and fold them into small circles and insert them into the pill dispenser as shown above (this will help the pills stay in place and even help them slide when turned)
- Tape a small piece of cardboard as shown above and place it on the bottom, this will be used as a platform that will later be taped to one of our servos
Adding the Mount for the Servo
- Cut an opening of the box and make sure a servo can fit through it
- Grab your Pringles can and wrap some tape around it as shown above
- Grab the double-sided tape and stick the servo on the top of the can as shown above
- Mount the Pringles can onto the side of the box which is what the tape is used for
- Make sure while taping the servo went through the box cutout for the servo
- You want to have the servo fins be slightly above the box but low enough to have the cartridge slide the pills out of the small hole
- Cut a hole right above the platform where the pill will be dispensed
Installing the Cartridge to the Servo
- Use double-sided tape to connect the small piece of cardboard on the bottom of the cartridge that we installed earlier to the servo
- Therefore make sure which way your servo is going to turn (clockwise or counterclockwise) because it may depend on the way you mounted the servo onto the tube.
- Mines turned counterclockwise so I had to place the openings more toward the right side
Building the Shoot
- Cut a small bottle's bottom as shown above and tape it underneath the hole
- Use a paper towel roll and cut as much as you need in order to have it fit from the small bottle's opening to the platform as shown above
- Tape the paper towel to the side of the box and to the small bottle
Testing
- As soon as your setup looks like something similar to the picture above press the button once
- If the servo moves and dispenses the pill to the bottom successfully, you are halfway done testing
- Press the button many times after
- If the servo moves an additional amount of degrees and dispenses the next pill(s) then congratulations!
- If there are errors, then you may have to adjust the angles at which the servo starts or rotates