Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
priyanka_p1
Created May 28, 2021

Door Opener using Arduino

The device automatically opens the door when it senses objects in its range.

IntermediateFull instructions provided2 hours18
Door Opener using Arduino

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×3
Resistor 1k ohm
Resistor 1k ohm
×2
Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×10

Software apps and online services

Tinkercad
Autodesk Tinkercad

Story

Read more

Schematics

Circuit DIagram

Simulated from TInker CAD

Code

Code for the device

C/C++
// C++ code
//
#include <Servo.h>

int distance = 0;

Servo servo_6;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}

void setup()
{
  pinMode(9, OUTPUT);
  servo_6.attach(6, 500, 2500);

  pinMode(8, OUTPUT);
}

void loop()
{
  digitalWrite(9, HIGH);
  servo_6.write(90);
  distance = 0.01723 * readUltrasonicDistance(7, 7);
  if (distance <= 100) {
    servo_6.write(180);
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_6.write(90);
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
  }
  servo_6.write(90);
}

Credits

priyanka_p1
4 projects • 4 followers
Contact

Comments

Please log in or sign up to comment.