Nowadays a lot of children suffer from hyper activity, sugar cravings, overweight and diabetes, so i thought about making a candy dispenser box with password, so that the parents can manage the amount of candies intake for their children at home.
By this, the box won't open again till the parent permits that next day.
I got inspired from this video:
https://www.youtube.com/watch?v=LkHy7KyMxgM
https://ai.thestempedia.com/project/diy-automatic-chocolate-dispenser/
First, I designed cardboard prototype for my project to imagine it, define places of mounting electrical components and needed holes and calculate the needed measurements for all faces.
Second, I designed candy dispenser chassis using Fusion 360
I was inspired from the design of game kit that we used in the first session, so i designed the candy box similar to it but with bigger dimensions that i need, i made holes and spaces for arduino usb, power socket, switch, LCD, nails like in the game kit.. i used a switch instead of push button so i made a bigger hole for it (22 mm), and i added a hole for power socket (10 mm) and a keypad to my design so i put 4 holes for screws in front side and designed an external frame to fix it.
I Sketched sides, top, and bottom parts on fusion 360
I also sketched container (2 sides) for holding the candies inside the candy dispenser
I used the technique of T-slots and captive nuts to assemble the box faces together and i designed x-slot guides to assemble boxy enclosures.
I Extruded my sketches into a 2.5D parts and assembled all my components using M3 screws and nuts in Fusion 360.
I Exported my box faces in *.DXF format.
Third, I needed to make the dispensing mechanism with 3D printed parts.
I downloaded the STL files from Thingiverse website
the link: https://www.thingiverse.com/thing:465349
1- I prepared my *.DXF files in Laser Cad software and fabricated them using Laser Cutting machine.
I used 3ml thickness plywood in fabrication
2- I prepared my *.STL files in ultimate Cura Software and fabricated them using 3D Printer machine
I used PLA filament plywood in fabrication
Brain:
Arduino UNO board act as the smart device's brain that processes the Input and send orders to perform Action
Input components : (Sensing)
keypad to enter password
Buzzer to make alarm if we enter wrong password
Action components:
Graphical Action: The device display a message through a graphical screen (LCD)
Physical Action: servo motor for dispensing mechanism of candies
At last, I added an on/off switch in series connection to control the whole device (open and close it)
I designed Circuit wiring diagram using tinkercad
The power source that i used is 5v adaptor
I used arduino ide software to program my project
I was inspired by the tutorials of safelock in the portal
Steps of programming each function of my code:
I downloaded libraries of keypad, servo motor and LCD
definition of all the pins, characters and variables required to run my code smoothly
The void setup function runs once when the device is powered and it declares the pin mode for all the pins, the starting position of the servo motor and start LCD and serial communication
The void loop function runs repeatedly and shows the display of LCD function
I tried each component first alone to make sure it's working, so after downloading the libraries of servo, keypad, and LCD.. I tried one of the examples from the libraries for all of them, and i defined the address of the LCD (0x27)
I made a counter for the number of keys pressed on the keypad, then i will read the 4digits of the password and the enter key, then i will check them.
I printed the values of the digits and the messages of keypad first on the serial print on my laptop to make sure the program is functioning correctly, then i added the LCD and programmed it to display all the values on it
I programmed the keypad that:
1- when the child enter the correct password (1234#) for the first time, the servo motor will work and rotate 180 degree so the gear will rotate and move the rack forward so the child will have his candy.. then the servo will go back to it's initial position and rack go backwards to it's place.. the buzzer will give a short tone and the LCD will show a message " your candy for today"
2- If the child entered wrong password on the keypad , the device won't work, so the servo won't rotate, the buzzer will give a long tone, and the LCD will show a message " wrong password"
3- If the child entered wrong enter key on the keypad (any key except #) , the device won't work, so the servo won't rotate, and the LCD will show a message " wrong enter key"
4- If the child entered the correct password again on the keypad, the device won't work, so the servo won't rotate and the LCD will show a message " come back tomorrow".
by that the parent can control the amount of candies intake and permits the child to take candy again by switching on the smart device again next day.
5- at the end i reset the 4 digits and remade the counter =1 to repeat the code from the beginning.
I integrated my smart device physical parts/ chassis and electronic components in one assembly using T-slots and captive nuts and x-slots
first, i attached the box faces together using x-slots and they are all attached to base then i fixed them using T- slots and captive nuts
Next, i mounted all electronic components in it's place using screws and nuts
At last, i made the whole wiring using jumper wires.
The smart device performs the minimum features:
takes input signals from keypad AND performs a smart action which is rotating servo motor, dispalying messages on LCD and producing alert from buzzer.
Here is a demo video is provided proving functionality of the minimum features of my smart device
1- I asked my instructors about how to mount the keypad in my smart device.. they told me to make an outer frame with dimensions from inside less than the keypad to stick it in between the box panel and the outer frame
the keypad size is 70*77 mm
so the inner size of the frame is 60*67 mm
and outer size is 80*87 mm
then i added holes (3mm) for the screws in the 4 sides
2- In the code, when i put the starting position of the servo motor zero degree and after rotating it goes back to zero degree.. when i upload the code the laptop used to shut down, so i asked my instructors and they told me the servo is taking to much power so try making the starting point to be 40 degree for example, i tried it and it worked.
I had two problems in wiring of my project:
1- when i connected the switch in series with my project, it wasn't working
My instructors told me to measure the 3 terminals of the buzzer by avometer (each two terminals together).. i found no buzzer sound between two terminals.. so i knew that the switch is broken and i got another one.
2- When i connected the adaptor to My device after trying it several times by the USB cable, the movement of servo motor wasn't functioning correctly, so i asked my instructors, we tried several things:
- putting the out jumper wire of 5v from breadboard in vin in arduino instead of 5v pin, the problem wasn't solved
- switching the adaptor by 9v adaptor and we put it in the arduino socket not in the power jack, the servo worked well..
- then we tried switching the 5v adaptor with another one and it worked good.. so the problem was in my 5v adaptor.
I would add millis function to my code to calculate time of one day (24 hours) so that the box won't open again after giving the child a candy till next day
millis function is better than delay function as all tasks keep working when we use it
When i tried using delay in my code, the whole code stopped !
First, i defined values of second, minute, and hour Then i made a delay for 1 minute as a trial after the child enter the correct password for the second time to prevent him from taking more candies, I programmed the LCD to show message "come back tomorrow" and have along sound from the buzzer then the delay will work for 24 hours but i started trying a delay of 1 minute as a trial...
But actually all that didn't happen.. after the child enter the password for the first time the delay works not the second time, and all the code stopped, so you can't even try entering wrong password or wrong enter key..
So that's why millis function is a better choice than delay function...
And at the end i didn't even use the delay function in my code as i want to show all cases of the code on the LCD.
part of my code showing delay function