Garage Door

by Natsuri in Craft > Cardboard

7 Views, 0 Favorites, 0 Comments

Garage Door

20250117_132953.jpg

The purpose of this project was to create a working garage door by using an Arduino circuit and supplies to allow this garage door to be automated when detecting an object. This garage door operates by using an ultrasonic distance sensor which detects an object in it's range, when the object is in it's range the code tells the servo to spin so that the door attached may open. Additionally, we added a photoresistor that when covered, gives a specific code to turn on LED's, then to turn off when uncovered by a piece of material. The material covers the photoresistor with another servo that the material is attached to, the servo spins when the object is in the range of the ultrasonic distance sensor allowing the servo to spin. In conclusion, we've tested multiple versions of the project and modified it when necessary, currently the project is reliable and works as indented. The project just needs you to connect a 9 volt battery, and the project will run smoothly.

Supplies

Materials used for construction:

-Carboard box

-Duct tape

-Hot glue

-Scissors

-Cardboard cutter



**Supplies:**

-Arduino uno circuit (1x)

-Wires (20x)

-Resistor (470 ΩOHM)

-Resistor (10k ΩOHM)

-Resistor (220 ΩOHM)

-Ultrasonic distance sensor (1x)

-Photoresistor (1x)

-Servo (2x)

-Breadboard

-Push button (1x)

-Red LED's (2x)

-9 volt battery (1x)

-Battery wire (1x)

Wiring / Equipment Arrangments

image_2025-01-17_205901687.png

To recreate this project you need to use tinker cad first to understand how the project is going to be in real life

Arrangement: (Place in the spots shown for better looking results)


  1. Grab an Arduino UNO and a Bread Board


  1. Plug the GRND to the negative side and plug the 5 volts into the positive side with a red and black wire (use red and black wire just for reference)


  1. Connect both sides of the Bread Board


  1. Place the resistors into the negative side of the bread board and connect to spots shown


  1. Connect the photoresistor's 1st terminal to the 470 Ω Ohm resistor and Analog 0 to the same terminal with wire, and connect the 5 volt positive side to the 2nd terminal with a wire


  1. Connect the 220 Ω Ohm resistor to the ground, and connect the wire in the same column that connects directly to a red LED's cathode, (recreate this with another LED)


  1. Connect the 1st red LED's Anode to D3, and the 2nd red LED with D2


  1. Place a Push Button in the middle of the bread board and connect terminal 1a to the negative side of the bread board and 2a with D5 by using a wire


  1. Grab 2 servos, plug them both to GRND and 5 Volts from the bread board, and plug the servo 1's signal to 9D, and the 2nd's signal to 8D


  1. Grab 1 Ultrasonic Distance Sensor, plug GRND into the GRND PIN, and the 5V to the 5V PIN, then plug D12 to the TRIG PIN, and lastly plug 11D to the ECHO PIN

Creating the Garage Door

20250117_132949.jpg

Building the Garage Door:

  1. Get a big Cardboard Box, and cut with a cardboard box cutter 4 to 6 inches of the box and keep the piece that has been cut off


  1. Cut another 1 to 2 inches of the cardboard box and keep the piece that has been cut off


  1. Grab 2 servos, attach one inside of the box on the left of the door by using electrical tape and scissors to hold it into place, do the same for the other servo but attach it into the front right of the door (servo 1 = right servo, servo 2 = left servo)


  1. Use the Tinker cad design to recreate it in real life


  1. Use Hot glue the bread board and the Arduino UNO use to the top of the Cardboard Box


  1. Place the Ultrasonic Distance Sensor on the top of the Garage Door, and use electrical tape to hold it in place


  1. Place the photosensor on the top left of the Garage Door, and use the electrical tape to hold it into place


  1. Use the 4 to 6 inches piece that you had just cut, and tape it to the servo 1 lever, so it can turn to open and close, do the same to servo 2, but use the 1 to 2 inch piece that you also had cut from the Cardboard Box

Writing Diagram/Code

Copy code to the tinker cad:


#include <Servo.h>

Servo servo1;
Servo servo2;

int val;
int trigPin = 12;
int echoPin = 11;
int pingTravelTime;
float pingTravelDistance;
float distanceToTarget;
int dt = 50;

// LED
int blinkPin = 2;
int blinkyPin = 3;
int blinkTime = 350;
int blinkyTime = 350;
int blink = 1;
int blinky = 1;
int j;
int photocellPin = 0;
int photocellReading = 0;

// Button
int buttonPin = 5;
int servo1Pin = 9;
int servo2Pin = 8; // The previous state from the input pin
int buttonState = 0; // Variable to store the button state
int lastButtonState = 0; // Variable to store the last button state
bool servoPositionSet = false; // Flag to toggle between servos

void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
servo2.attach(8);
servo1.attach(9);
pinMode(echoPin, INPUT);
pinMode(blinkyPin, OUTPUT);
pinMode(blinkPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as an input
}

// LED
void loop() {
// Button control
if (photocellReading >= 100) {
// Measure distance again and control servos accordingly
buttonState = digitalRead(buttonPin);
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravelTime = pulseIn(echoPin, HIGH);
delay(1);
pingTravelDistance = (pingTravelTime * 765.0 * 5280.0 * 12) / (3600.0 * 1000000.0);
distanceToTarget = pingTravelDistance / 2;
Serial.print(distanceToTarget);
Serial.println(" in.");
delay(dt);

if (distanceToTarget <= 7 && buttonState == LOW) {
servo1.write(90);
delay(25);
} else {
servo1.write(0);
}

// Control servo 2 based on distance
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravelTime = pulseIn(echoPin, HIGH);
delay(1);
pingTravelDistance = (pingTravelTime * 765.0 * 5280.0 * 12) / (3600.0 * 1000000.0);
distanceToTarget = pingTravelDistance / 2;
Serial.print("Distance to Target is: ");
Serial.print(distanceToTarget);
Serial.println(" in.");
delay(dt);

if (distanceToTarget <= 7 && buttonState == LOW) {
servo2.write(180);
delay(25);
} else {
servo2.write(0);
}

digitalWrite(blinkPin, LOW);
delay(blinkTime);
digitalWrite(blinkyPin, LOW);
delay(blinkyTime);
photocellReading = analogRead(photocellPin);
} else {
buttonState = digitalRead(buttonPin); // Read the state of the button

// Loop to measure distance using ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravelTime = pulseIn(echoPin, HIGH);
delay(1);
pingTravelDistance = (pingTravelTime * 765.0 * 5280.0 * 12) / (3600.0 * 1000000.0);
distanceToTarget = pingTravelDistance / 2;
Serial.print("Distance to Target is: ");
Serial.print(distanceToTarget);
Serial.println(" in.");
delay(dt);

// Control servo 1 based on distance to target
if (distanceToTarget <= 7 && buttonState == LOW) {
servo1.write(90);
delay(25);
} else {
servo1.write(0);
}

// Loop to measure distance using ultrasonic sensor again
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravelTime = pulseIn(echoPin, HIGH);
delay(1);
pingTravelDistance = (pingTravelTime * 765.0 * 5280.0 * 12) / (3600.0 * 1000000.0);
distanceToTarget = pingTravelDistance / 2;
Serial.print("Distance to Target is: ");
Serial.print(distanceToTarget);
Serial.println(" in.");
delay(dt);

// Control servo 2 based on distance to target
if (distanceToTarget <= 7 && buttonState == LOW) {
servo2.write(180);
delay(25);
} else {
servo2.write(0);
}

// LED control (photocell)
photocellReading = analogRead(photocellPin);

for (j = 1; j <= blink; j++) {
digitalWrite(blinkPin, HIGH);
delay(blinkTime);
digitalWrite(blinkPin, LOW);
delay(blinkTime);
}

for (j = 1; j <= blinky; j++) {
digitalWrite(blinkyPin, HIGH);
delay(blinkyTime);
digitalWrite(blinkyPin, LOW);
delay(blinkyTime);
}

}
}