The idea is a simple vending machine, It is a part of my final project so I do care to make it work to demonstrate a very important part of the final project.
In the reference video, The maker used a continuous servo motor to run the spring and let the items be presented to the user.
My idea is to use an H-bridge module and geared DC motor instead of the continuous servo motor and also activate the vending mode using IR sensor.
I used TinkerCad Circut to design the electronic circuit & the following materials:
Cardboard for the enclosure.
A 2mm diameter metal wire for the spiral spring.
Used craft tools to fabricate the enclosure.
A piece of 9 mm plywood for the spring holder.
I did a simple sketch using pen and paper and started with the gifts and spiral tray then to the rest of the enclosure.
Then prepared the place of the components from the back view of the box, started to measure each component to make sure it will fit within the box.
I decided to use a 9V adapter as a power supply as I will power the Arduino, H-Bridge module, DC motor with the load, and a power LED. The Arduino will power and gift place LED and IR sensor module, Here I needed to power the Arduino using the Vin pin.
On TinkerCad added a 9V 2A power supply, 2 LEDs with different resistors - 1 Kohm for the Red LED (as I will use 9V) and 220 ohms for the White LED (as it will be powered by 5V from the Arduino).
Input:
Added a PIR instead of the IR sensor but it will be the same function.
on/off switch.
Output:
Added L293D instead of the L298N driver but it is the same wiring.
Added a Buzzer for vending sound.
LED
Motor
And finally tested the functionality by simulating the circuit as shown in the video.
TinkerCard Circuit - We used L293D instead of the L298N Driver Module.
TinkerCard simulation video.
Started to get the equation of the spiral wire to know how long the piece of wire needed to hold 4 items.
Used spray can to bend the wire over to get the spiral shap.
Used a 9 mm plywood piece of wood to connect the wire to the geared motor shaft.
Fixed the gifts tray to the box by using hot glue and fixed the motor using Zip tie.
Created the enclosure box using cardboard.
Fixed the motor to the enclosure box using a zip tie.
Created a precise cut for the on/off switch, the female adapter jack, and the power LED.
Connected the circuit all together outside the box to make sure everything works great, used the small breadboard to save space inside the box.
Added all the components inside the box and did make sure they fit with no shorts.
Mounted the IR sensor and LED in place using tap. & added the gifts for the first run.
And here is the vending machine :)
The LED designed to light the item after vending.
And now with the code, I used TinkerCad codeblocks for the code
I used an If condition to read the IR sensor status if it is HIGH ( LOW in real life) it will set the motor speed to 160 and run the motor for 1 sec (adjusted to 500 ms in real life).
Then, turn of the motor and make a sound and turn on the LED for 4 sec. (the time the user will grab the gift.
Else, turn off the speaker, turn of motor and turn off LED.
On the Arduino IDE, I did tweak the code a bit to make it work as expected. I did make sure that the pins are the same as TinkerCad.
I changed the status of the IR to low not High.
I changed the wait time of the motor to 500 ms.
And uploaded the code to arduino.
And this was the functional machine :)
The pull-up concept in Arduino.
I did help my colleagues to understand the concept of the pull-up pins and why should we add pullup for the push button.
I did help my colleagues during the End of Week session when they had a problem using the ultrasonic sensor so I suggested sharing my code to their Arduino to check if everything functioning well.
I asked my Instructor Amany about using the H-bridge with the Arduino for driving two DC motors and we agreed to use it to control the motor speed.
And asked Ibrahim our instructor if we can have 9V out of Arduino so we mentioned that the Vin is connected directly to the power jack of the Arduino.
I got stuck on calculating the wire length to make the spiral so I did some research and found an equation for that.
I got stuck during powering my vending machine as we have one female adapter jack and I need to give power to all the circuit including the Arduino so I did a quick research and found that I can power the Arduino using Vin pin for a safe range from 7 to 12 Volts.
The assignment project was a part of my final project so I did learn a lot.
We had this discussion on Slack about the LED diameter and I did figure out that the diameter is for the LED body, not the shoulder so it can fit well in a 5mm hole.
I managed to get Wifi enabled LED strip that can be controlled from a mobile app to connected to any home assistant like Amazon Alexa.