top of page
Writer's pictureSanskruti Ashtikar

Building an Automatic Door Opener with TinkerCAD and Arduino

Updated: Nov 23

Introduction


An Automatic Door Opener is a practical and innovative project that showcases automation and control systems. This project involves creating a system that opens a door automatically when a certain condition is met, such as detecting an object or a person. Using TinkerCAD and Arduino, we'll build a simple automatic door opener using a servo motor and an ultrasonic distance sensor. This system can be applied in various scenarios, from automated entry systems to robotic doors.





Materials Needed


To build this project, you will need:

  • Arduino Uno

  • Breadboard

  • Servo Motor

  • Ultrasonic Distance Sensor (HC-SR04)

  • Jumper Wires

  • Power Source (e.g., 9V battery or external power supply)

  • (Optional) LED for status indication


Step 1: Setting Up the Components


  1. Arduino and Breadboard: Open TinkerCAD and create a new circuit project. Drag and drop an Arduino Uno and a breadboard onto the workspace.

  2. Servo Motor: This motor will be used to open and close the door.

    • VCC: Connect to the 5V pin on the Arduino.

    • GND: Connect to GND on the Arduino.

    • Signal: Connect to a PWM pin on the Arduino (e.g., pin 9).

  3. Ultrasonic Distance Sensor (HC-SR04): This sensor measures the distance to an object.

    • VCC: Connect to the 5V pin on the Arduino.

    • GND: Connect to GND on the Arduino.

    • TRIG: Connect to a digital pin on the Arduino (e.g., pin 7).

    • ECHO: Connect to a digital pin on the Arduino (e.g., pin 6).

  4. LED (optional): For visual status indication.

    • Anode (+): Connect to a digital pin on the Arduino (e.g., pin 13) through a current-limiting resistor (e.g., 220Ω).

    • Cathode (-): Connect to GND on the Arduino.


Step 2: Wiring Diagram


Ensure your wiring follows these connections:

  • Servo Motor:

    • VCC → 5V on Arduino

    • GND → GND on Arduino

    • Signal → Digital Pin 9 on Arduino

  • Ultrasonic Distance Sensor:

    • VCC → 5V on Arduino

    • GND → GND on Arduino

    • TRIG → Digital Pin 7 on Arduino

    • ECHO → Digital Pin 6 on Arduino

  • LED (optional):

    • Anode (+) → Digital Pin 13 on Arduino through a 220Ω resistor

    • Cathode (-) → GND on Arduino





Step 3: Writing the Code


With the components connected, let's write the Arduino code to control the servo motor based on the distance measured by the ultrasonic sensor.


#include <Servo.h>
const int trigPin = 7;       // Trigger pin for ultrasonic sensor
const int echoPin = 6;       // Echo pin for ultrasonic sensor
const int servoPin = 9;      // Servo motor control pin
const int ledPin = 13;       // LED pin (optional)
const int openDistance = 10; // Distance in centimeters to open the door
const int closeAngle = 0;    // Servo angle to close the door
const int openAngle = 90;    // Servo angle to open the door
Servo doorServo;             // Create a Servo object
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(ledPin, OUTPUT);
  
  doorServo.attach(servoPin); // Attach the servo to the pin
  doorServo.write(closeAngle); // Start with the door closed
  
  Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
  long duration;
  int distance;
  
  // Send a pulse to trigger the ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);


  
  // Measure the duration of the echo pulse
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance in centimeters
  distance = duration * 0.0344 / 2;
  
  // Debugging information
  Serial.print("Distance: ");
  Serial.println(distance);
  
  if (distance < openDistance) {
    // Open the door if the object is within the openDistance
    doorServo.write(openAngle);
    digitalWrite(ledPin, HIGH); // Turn on the LED (optional)
  } else {
    // Close the door if the object is outside the openDistance
    doorServo.write(closeAngle);
    digitalWrite(ledPin, LOW); // Turn off the LED (optional)
  }
  
  delay(100); // Short delay for stability
}

Step 4: Simulating the Circuit


  1. After entering the code, click the "Start Simulation" button in TinkerCAD.

  2. Adjust the distance in the simulation to see how the servo motor reacts. The door should open when the distance is less than the specified threshold (openDistance) and close otherwise.

  3. Monitor the Serial Monitor for real-time distance readings and debug information.





Step 5: Understanding the Code


  • Ultrasonic Sensor Reading: The pulseIn() function measures the duration of the echo pulse, which is then converted into a distance using the speed of sound formula.

  • Servo Control: The doorServo.write() function sets the angle of the servo to open or close the door.

  • LED Indicator: The LED provides visual feedback of the door's state (optional).


Step 6: Enhancing the System


You can enhance the Automatic Door Opener with additional features:

  • Adjustable Threshold: Use a potentiometer to adjust the distance threshold dynamically.

  • Multiple Sensors: Add additional sensors for more sophisticated control (e.g., detecting multiple entry points).

  • Manual Override: Implement a button or switch to manually control the door.


Conclusion


You have successfully built an Automatic Door Opener using TinkerCAD and Arduino. This project showcases the integration of sensors and actuators to automate a task, demonstrating key concepts in robotics and automation.


Want us to guide you through your project or make the project for you ?







Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



11 views0 comments

Related Posts

See All

Comments


bottom of page