Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dsvakola/fc0f0d9d2659c108567d2828d5580410 to your computer and use it in GitHub Desktop.
Save dsvakola/fc0f0d9d2659c108567d2828d5580410 to your computer and use it in GitHub Desktop.
The CBSE Regional Science Exhibition 2019 was held at Bhavan’s B.P. Vidya Mandir, Nagpur on 29-30th November, 2019. Constructed by Vidyasagar Academy Akola.
/*
* Railway crossing automatic gate system to avoid accidents
* Emerald School, Akola
* Date: 22.11.2019
*/
#include <Servo.h>
Servo servo1,servo2;
int const trigPin=10;
int const echoPin=9;
int buzzer=2;
/*
int i;
void buzzpulse()
{
for(i=0;i<10;i++)
{
digitalWrite(buzzer,HIGH);
delay(150);
digitalWrite(buzzer,LOW);
delay(150);
}
}
*/
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(buzzer,OUTPUT);
servo1.attach(3);
servo2.attach(11);
}
void loop()
{
int duration,distance;
digitalWrite(trigPin,HIGH);
delay(1);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
if(distance<=6 && distance>=2)
{
servo1.write(180); // gate-1 close
servo2.write(180); // gate-2 close
digitalWrite(buzzer,HIGH);
delay(3000);
}
else
{
servo1.write(0); // gate-1 open
servo2.write(0); // gate-2 open
digitalWrite(buzzer,LOW);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment