Mini Box/House With Automated Door
by arman_a in Circuits > Arduino
46 Views, 1 Favorites, 0 Comments
Mini Box/House With Automated Door
A mini house/box that has a small door that can be opened with an ultrasonic sensor. The door slides to open and close. You can put whatever you want or you can turn the box around to turn it into a dispenser.
This project is made without a breadboard. It can be improved in almost all aspects, but if you want to make something with limited supplies then this might be something for you.
Downloads
Supplies
Circuit components:
- Arduino Uno and cable
- 7 male to male jumper wires
- Ultrasonic sensor
- Micro Servo 9g SG90
Box components:
- Hardboard (122x61 cm 3,2 mm)
- Foamboard
Tools:
- Adhesive for wood
- Duct tape
- utility knife
- laptop/pc
Connect the Components
Connect the Arduino components like this:
Code
Connect the Arduino to a laptop or computer and use the software Arduino IDE to setup the program. Use this code and test it by uploading the code to the Arduino.
#include <Servo.h>
// Pin ultrasonic sensor
const int trigPin = 10;
const int echoPin = 9;
// Servo object
Servo myServo;
// Variables
long duration;
int distance;
void setup() {
// Set up pins ultrasonic sensor
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// pin 7
myServo.attach(7);
// debugging
Serial.begin(9600);
}
void loop() {
// Send out pulse to the ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echo time
duration = pulseIn(echoPin, HIGH);
// Calculate distance in cm
distance = duration * 0.034 / 2;
// Print distance to serial monitor for debugging
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Map the distance to a servo angle (0 to 90 degrees)
int angle;
if (distance > 0 && distance <= 100) {
angle = map(distance, 0, 100, 90, 0); // 0 cm = 90°, 100 cm = 0°
} else {
angle = 0; // Set servo to 0 degrees if out of range
}
// Move the servo motor to the calculated angle
myServo.write(angle);
// Add a short delay to smooth out the servo movement
delay(100);
}
Make the Box
- Use the hardboard and cut it up with the utility knife. Cut the holes on these sides so the parts and door can be exposed. A laser cutter can make the process quicker.
- Put the foamboard on the micro servo.
- Put all the components inside the box and make them fit the holes.
- Use glue and/or duct tape to make the box and the components stay in their place.
Iterations and Conclusion
Iterations:
I used a carton box to prototype it. I first had to change the code to test the door rotation. I made the door bigger and also used different components to allow the door to have a smooth movement and also cover the door. I also soldered the ultrasonic sensor to the jumper wires.
After making this project, I learned that I need to order materials earlier and I shouldn't expect things to keep working. Laser cutting is something that would make the build time way quicker and using screws will make the box sturdier. 3d printing is also a good alternative. The hardboard was difficult to cut and also easy to break after I folded it. I will know the next time to do it differently. It was still a fun challenge to limit myself and keep making the project smaller. Other ideas like using led's wouldn't be really possible for me without the use of a breadboard.