Automatic Dispenser
This dispenser can dispense objects that are being stored. It is portable, cheap, and efficient and can help improve lives of many people.
Supplies
Cardboard box
Arduino
Jumper wires
Ultrasonic sensor
Micro-servo motor
Velcro
tape
Tennis Ball(can be any other object)
Cutting the Box
Take the box and make a hole in the bottom big enough to fit your chosen object.
Make 2 holes where the ultrasonic sensor will be placed.
Connect the Arduino, servo motor, and ultrasonic sensor with jumper wires according to the image.
Bread board is not necessary.
Putting Everything Together
Tape arduino to box and tape ultrasonic sensor to fit into the two holes. Tape popsicle sticks to servo motor and velcro the servo motor to the box.
Optional Information
Can paint the box to make it look better.
Code for Arduino: #include
Servo servo1; int trigPin = 9; int echoPin = 8; long distance; long duration;
void setup() { servo1.attach(7); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);// put your setup code here, to run once: }
void loop() { ultra_sonic(); servo1.write(90); if(distance <=9) { servo1.write(270); } }
void ultra_sonic() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration*0.034/2; }
Code was adapted from https://techtermite.blogspot.com/2020/04/using-ser...