Monday, April 18, 2016

Arduino Continuous Opening and Closing Gate System with LED, Buzzer and Servo


Note:

Here I have only given the circuit diagrams and schematics. I have no yet implemented this on hardware, but it should work.

What is it?

The two servo motor signifies two continuous opening and closing gates. The buzzer and the LED notifies that the gates have opened open.

Connect the negative pin of buzzer to ground and positive to pin $ 13 $. For LED connect cathode to ground and connect anode to a one pin of resistor. Connect the other pin of the resistor to pin $ 13 $ of arduino.

Here, pin $ 13 $ is used for lighting LED and starting the buzzer. Whenever LED lights up the buzzer is also enabled. Pin $ 9 $ and $ 10 $ is used for mini servo and servo respectively.

Connect both servo ground to arduino ground and Vcc to arduino $ 5V $. Finally connect the signal pins. Connect signal pin of mini servo to $ D9 $ and connect the other servo signal pin to $ D10 $.

Components:

1. $ 220 k \Omega $ Resistor.
2. LED.
3. Buzzer.
4. Servo.
5. Mini Servo.

Virtual Project Screenshot:

Schematic:

Arduino Code:

/*
* 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);
}
}

No comments: