Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Automated Door with Ultrasonic Sensor and Servo

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Automated Door with Ultrasonic Sensor and Servo

Circuit Documentation

Summary

This circuit is designed to utilize an Arduino UNO as the central microcontroller to interface with various components including LEDs, a buzzer module, an HC-SR04 ultrasonic sensor, a servo motor, and a power supply consisting of 2x 18650 batteries. The circuit is capable of measuring distance using the ultrasonic sensor and responding to certain distance thresholds by activating LEDs, a buzzer, and a servo motor. A rocker switch is used to control the power supply to the Arduino UNO.

Component List

Arduino UNO

LED: Two Pin (red)

LED: Two Pin (green)

HC-SR04 Ultrasonic Sensor

Servo

2x 18650 Battery Pack

Buzzer Module

Rocker Switch

Wiring Details

Arduino UNO

LED: Two Pin (red)

LED: Two Pin (green)

HC-SR04 Ultrasonic Sensor

Servo

2x 18650 Battery Pack

Buzzer Module

Rocker Switch

Documented Code

#include <Servo.h>

// Definición de pines
const int trigPin = 6;
const int echoPin = 5;
const int redLedPin = 9;
const int buzzerPin = 10;
const int greenLedPin = 8;
const int servoPin = 7;

Servo myServo;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(redLedPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  myServo.attach(servoPin);

  // Estado inicial
  digitalWrite(redLedPin, HIGH);
  digitalWrite(greenLedPin, LOW);
  noTone(buzzerPin); // Detiene el sonido
  myServo.write(0); // Posición inicial del servo
}

void loop() {
  // Medición de distancia
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration / 58.2; // Convertir tiempo a distancia

  // Impresión de variable
  Serial.print("Distancia: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Lógica de control
  if (distance < 7) {
    digitalWrite(redLedPin, LOW);
    digitalWrite(greenLedPin, HIGH);
    myServo.write(90); // Abrir la puerta
    tone(buzzerPin, 220); // Genera un tono de 1000 Hz
    delay(1000); // 1segundo de espera
    noTone(buzzerPin); // Detiene el sonido
    delay(5000); // Mantener abierta por 5 segundos
  } else if (distance >= 10) {
    digitalWrite(redLedPin, HIGH);
    digitalWrite(greenLedPin, LOW);
    noTone(buzzerPin); // Detiene el sonido
    myServo.write(0); // Cerrar la puerta
  }

  delay(100); // Espera para estabilizar las lecturas
}

This code is designed to run on an Arduino UNO and controls the circuit's response to distance measurements taken by the HC-SR04 ultrasonic sensor. When an object is detected within 7 cm, the red LED turns off, the green LED turns on, the servo moves to a 90-degree position, and the buzzer emits a tone for 1 second. If the object is further than 10 cm, the red LED turns on, the green LED turns off, the buzzer stops, and the servo returns to the 0-degree position. The system stabilizes for 100 milliseconds before taking another measurement.