Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quickgrid/4c056073c733b6a02260f113c1769c72 to your computer and use it in GitHub Desktop.
Save quickgrid/4c056073c733b6a02260f113c1769c72 to your computer and use it in GitHub Desktop.
Arduino Parking Gate Open Closing System with LED, Buzzer and Servo.
/*
* Author: Asif Ahmed
* Site: https://quickgrid.blogspot.com
* Description: I can not guratee that this code is bug free.
* This is a continuous gate opening and closing system
* with buzzer and LED to notify gate openings.
*/
#include<Servo.h>
// Pin 13 is used for LED connection here
int led = 13;
Servo miniservo;
Servo servo;
int miniServoPos;
int servoPos;
int pos = 10;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
// use port D9 for mini servo and port D10 for servo
miniservo.attach(9);
servo.attach(10);
miniservo.write(miniServoPos);
servo.write(servoPos);
// initialize serial connection
Serial.begin(9600);
Serial.print('\n');
Serial.print('\n');
Serial.print("Ardunio Controlled Gate System");
Serial.print('\n');
Serial.print('\n');
}
// the loop routine runs over and over again forever:
void loop() {
// Check if any data arrived and stored in serial receive buffer
if( Serial.available() ){
int serialAngle = Serial.parseInt(); // try to parse the serial data to an Integer
Serial.print("Angle: ");
Serial.println(serialAngle);
pos = serialAngle;
}
// Gate Opens (or, Closes Depending on context)
{
for( miniServoPos = 180; miniServoPos >= 0; miniServoPos -= pos ){
miniservo.write(miniServoPos);
Serial.print("Mini Servo: ");
Serial.println(miniServoPos);
delay(100);
}
}
{
for( servoPos = 180; servoPos >= 0; servoPos -= pos ){
servo.write(servoPos);
Serial.print("Servo: ");
Serial.println(servoPos);
delay(100);
}
delay(1000);
}
// After gate opened light up led then 1 seconds delay and so on
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
// Gate Closes (or, Opens Depending on context)
{
for( miniServoPos = 0; miniServoPos <= 180; miniServoPos += pos ){
miniservo.write(miniServoPos);
Serial.print("Mini Servo: ");
Serial.println(miniServoPos);
delay(100);
}
delay(1000);
}
{
for( servoPos = 0; servoPos <= 180; servoPos += pos ){
servo.write(servoPos);
Serial.print("Servo: ");
Serial.println(servoPos);
delay(100);
}
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment