0% found this document useful (0 votes)
11 views1 page

Arduino Garage Door Controller Code

This document contains an Arduino sketch for controlling a garage door using a servo motor and an ultrasonic distance sensor. It measures the distance to an object and opens the door if the distance is less than 10 cm, while also allowing manual control via a button. The setup includes initializing pins and continuously checking the distance and button state in the loop function.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Arduino Garage Door Controller Code

This document contains an Arduino sketch for controlling a garage door using a servo motor and an ultrasonic distance sensor. It measures the distance to an object and opens the door if the distance is less than 10 cm, while also allowing manual control via a button. The setup includes initializing pins and continuously checking the distance and button state in the loop function.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <Servo.

h>

const int trigPin = 9;


const int echoPin = 10;
const int buttonPin = 2;

Servo garageDoor;
int doorPin = 6;

long duration;
int distance;

void setup() {
[Link](9600);

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);

[Link](doorPin);
[Link](0);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration / 2) * 0.0344;

[Link]("Distance: ");
[Link](distance);
[Link](" cm");

if (distance < 10) {


[Link](90);
[Link]("Door Opened!");
} else {
[Link](0);
[Link]("Door Closed!");
}

if (digitalRead(buttonPin) == LOW) {
[Link](90);
[Link]("Manual Button Pressed: Door Opened!");
}

delay(500);
}

You might also like