The Best DIY STEM Tutorials and Projects

OVERVIEW
In this project we will make Automatic Door using Arduino Uno, Ultrasonic Sensor and a Servo Motor, we will detect ultrasonic waves to detect if anyone is ahead and use the Servo Motor to open and shut the door.
You can follow this video and the instructions below to make this Amazing Automatic Door Project.
Video
Components Required
Here is a list of Components that we will need to make this Project.

| Sr # | Item Name | Quantity |
|---|---|---|
| 1 | Arduino Uno | 1 |
| 2 | Breadboard | 1 |
| 3 | Male to Male Jumper Wire | 7 |
| 4 | Servo Motor | 1 |
| 5 | Ultrasonic Sensor | 1 |
Wiring Diagram
Here is a Complete Wiring Diagram along with Instructions for this Project

Program / Code
Code is Explained in the Comments of the Code
// Automatic Door by --- AceLabs ---
#include <Servo.h> //servo library
Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close door on power on
delay(100);
servo.detach();
}
void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<20 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}
Thank you so much for going through our tutorial, we hope it was easy to follow and you enjoyed it, please share your feedback and pictures of the project (if you have made it) in the comments below .!



