IDC2
Pill Box Reminder
Pet Peeve:
I forget to take my morning pills.
Idea:
I want to create a box that alerts me if I forget to take my pills. My idea is to have an RTC module set to a specific time. If I have not already opened the box to take my pills, the box will open and create a noise to remind me. It will automatically turn off after a designated amount of time (in case I leave the house, so it doesn’t continue all day). A stretch goal is to add something that pops out or lights that blink when the box opens due to forgetting to take the pills.
Supplies
- Microcontroller (ESP32 because it has a RTC Module and WiFi Built in)
- Servo Motor: To open the box lid.
- Piezo Buzzer: To make a noise as a reminder.
- Switch: To open/close the box and turn off the alarm
- Battery or way to plug into the wall
- Power Supply Module (so that the battery or outlet plug doesn’t fry arduino
- Box: 3D printed
- Resistors, Breadboard, and Connecting Wires: For circuit connections.
Sketches / Circuits
I designed my circuit in Circuito.io, but I could not add a power supply module in Circuito.io.
Wiring BreadBoard
- Put esp32 on one side of the breadboard and the power supply module on the other side. Hook esp32 up to the 3.3v side.
- Hook up a buzzer on pin 13
- Put the capacitor on the breadboard right next to the ESP connection because it responds quickly to power supplies
- Hook up the switch to pin 12
Soldering
- I originally wanted the switch to be a button; however, I could not figure out how to solder any buttons available without a breadboard. I couldn’t use a breadboard because of how my enclosure is set up. So, I used a switch, which I soldered a ground and signal wire to directly.
- I soldered female header pins to the breadboard to plug in my ESP32, Power Supply Module, and switch wires.
- I soldered the piezo buzzer, capacitor, and servo wires to the board.
Coding
Coding Goals:
- Make ESP32 connect to Wi-Fi, set the RTC, and then disconnect from Wi-Fi.
- If the switch that opens the box is switched between midnight and the set alarm time, nothing will happen at the set alarm time. If the switch is not flipped between midnight and the set alarm time, the servo moves 90°, and the piezo buzzer sounds. The buzzer stops when the switch is flipped up. When it is flipped back down, the box closes as well. The box can be opened and closed with the switch for the rest of the day. At 11:59 p.m., the boolean value that tracks if the box has been opened switches back to false so the cycle can continue.
Coding Experience:
- I used a header file to work with all my import statements and keep my file cleaner. I needed to include libraries for the ESPServo, time, and Wi-Fi. I found music people have written for piezo buzzers that I incorporated to make the sound not just be a flat tone.
- I created all my variables in my main Arduino file. I found datasheets for declaring variables and my setup function that provided the code I needed for my time client. I used the code in my IDC1 to connect to the internet using my ESP32.
- Within my loop, I struggled to find a way to connect all of my components. I could get the time client to set a time and print it. I could get the servo to move when I flipped the switch. Although I could get the switch to stop the buzzer when it is flipped up, it would then block me from being able to control the servo. When I set the servo to move 90° automatically with the time, I could not get the buzzer to sound or keep the ability to have the servo move with the switch.
I attached my code files below. Many areas are commented out for the presentation, which only shows the buzzer and manual servo move function; however, I could connect to WiFi and get the current time printed on the serial monitor. I also got the servo arm to move with time, but it did not work with the manual move function or buzzer. I attached a screenshot of my code printing the time of day next to my clock app to prove it is correct.
CADing
- I used Rhino to build my enclosure. After measuring all my elements, I designed a box that resembled my original drawings.
- I used the boolean difference tool to subtract holes from the box where my power supply and switch need to be.
- I designed long hollow cylinders on the inside wall of the box to mount the servo.
- I used the arc tool to design ramps inside each container to remove pills easily.
- I simply made a rectangle for the lid and two smaller rectangles for the servo. I used screws to secure around the included servo arm.
Learning Points
Soldering: The servo wires were very difficult to solder, so next time, I should cut my own wire and not use jumper cables. I also had some solder connecting my switch to my buzzer initially, which caused lots of problems.
Code: I am a computer science minor in Principles of Programming Languages. Coding has always been a strength of mine, but I don’t have the education to debug my issues. I tried printing statements and googling each hardware component, but I could not determine why the switch would not work for each element. My print statements would show it working exactly how I intended, but the hardware would not react as expected. If I were to attempt this project again, I would take a class that dives into the principles of coding hardware so I am equipped to solve these problems before attempting.
CAD: The first time I printed, I made the enclosure slightly too small to hold the breadboard. I also did not consider soldering the header pins onto it to attach the power supply module, so the hole was in the wrong place. If I were to redo this project, I would add a lip in the lid to attach the servo arm to it so the box could only be opened with the servo. I would also include holes for the hinges in my original CAD design.
I figured out I could get the buzzer to work as intended if it is powered by the Arduino instead of the Power Supply Module. I had no idea why this happened, so I melted a hole in my box to attach the cord.