Components and supplies
SG90 Micro-servo motor
Arduino UNO
Ultrasonic Sensor - HC-SR04 (Generic)
Apps and platforms
Arduino IDE
Project description
Code
Program of Automated Rail Crossing System
arduino
1//the code is entirely created by: SHEEKAR BANERJEE (at December 2017) 2//Dept. of CSE, IUBAT UNIVERSITY 3//AI-ML-IOT Solution Engineer and Researcher 4 5 6#include<Servo.h> //This calls the Header of the repository containing the library files of Servo Motor Driver Modules 7#define trigPin 9 //This initializes the Trig pin of HC-05 Ultrasonic Sensor to the pin no. 9 of Arduino Microcontroller 8#define echoPin 10 //This initializes the Echo pin of HC-05 Ultrasonic Sensor to the pin no. 10 of Arduino Microcontroller 9 10Servo sm; //Servo is a Class which is providing an independent data type // sm is a variable which is representing the servo motor 11int sound=250; 12 13 14void setup() { 15 Serial.begin(9600); //Streaming 9600 bits of sensor data per second 16 pinMode(trigPin,OUTPUT); //Here, Trig pin triggers the electrical impulses into the sensor as an output 17 pinMode(echoPin,INPUT); //Here, Echo pin inputs the reflective signals into the sensor 18 sm.attach(3); //The Coding Yellow Wire of the Servo motor is attached to the pin no. 3 of Arduino Microcontroller 19} 20 21void loop() { 22 long duration, distance; 23 digitalWrite(trigPin, LOW); 24 delayMicroseconds(2); // It will wait for 2 microseconds after every single electrical implulse of Trig pin if it is sending LOW(less than 1.6V) signal 25 digitalWrite(trigPin, HIGH); 26 delayMicroseconds(10); //It will wait for 10 microseconds after every single electrical implulse of Trig pin if it is sending HIGH(greater than 1.6V) signal 27 digitalWrite(trigPin, LOW); 28 29 30 duration=pulseIn(echoPin, HIGH); //Sensor inputs the signal through the Echo pin 31 distance=(duration/2)/29.1; //Calculation of distance 32 if(distance<10) //According to the reflection time calculation, if the distance is less than 10 cm 33 { 34 35 sm.write(80); //than the Servo Motor will rotate for 80 degrees 36 } 37 else { 38 39 sm.write(0); //Unless this, the Servo motor will stand still 40 41} 42 43}
Program of Automated Rail Crossing System
arduino
1//the code is entirely created by: SHEEKAR BANERJEE (at December 2017) 2//Dept. of CSE, IUBAT UNIVERSITY 3//AI-ML-IOT Solution Engineer and Researcher 4 5 6#include<Servo.h> //This calls the Header of the repository containing the library files of Servo Motor Driver Modules 7#define trigPin 9 //This initializes the Trig pin of HC-05 Ultrasonic Sensor to the pin no. 9 of Arduino Microcontroller 8#define echoPin 10 //This initializes the Echo pin of HC-05 Ultrasonic Sensor to the pin no. 10 of Arduino Microcontroller 9 10Servo sm; //Servo is a Class which is providing an independent data type // sm is a variable which is representing the servo motor 11int sound=250; 12 13 14void setup() { 15 Serial.begin(9600); //Streaming 9600 bits of sensor data per second 16 pinMode(trigPin,OUTPUT); //Here, Trig pin triggers the electrical impulses into the sensor as an output 17 pinMode(echoPin,INPUT); //Here, Echo pin inputs the reflective signals into the sensor 18 sm.attach(3); //The Coding Yellow Wire of the Servo motor is attached to the pin no. 3 of Arduino Microcontroller 19} 20 21void loop() { 22 long duration, distance; 23 digitalWrite(trigPin, LOW); 24 delayMicroseconds(2); // It will wait for 2 microseconds after every single electrical implulse of Trig pin if it is sending LOW(less than 1.6V) signal 25 digitalWrite(trigPin, HIGH); 26 delayMicroseconds(10); //It will wait for 10 microseconds after every single electrical implulse of Trig pin if it is sending HIGH(greater than 1.6V) signal 27 digitalWrite(trigPin, LOW); 28 29 30 duration=pulseIn(echoPin, HIGH); //Sensor inputs the signal through the Echo pin 31 distance=(duration/2)/29.1; //Calculation of distance 32 if(distance<10) //According to the reflection time calculation, if the distance is less than 10 cm 33 { 34 35 sm.write(80); //than the Servo Motor will rotate for 80 degrees 36 } 37 else { 38 39 sm.write(0); //Unless this, the Servo motor will stand still 40 41} 42 43}
Program of Automated Rail Crossing System
arduino
1//the code is entirely created by: SHEEKAR BANERJEE (at December 2017) 2//Dept. 3 of CSE, IUBAT 4//AI-ML-IOT Solution Engineer and Researcher 5 6 7#include<Servo.h> 8 //This calls the Header of the repository containing the library files of Servo 9 Motor Driver Modules 10 11#define trigPin 2 //This initializes the Trig pin of 12 HC-05 Ultrasonic Sensor to the pin no. 2 of Arduino Microcontroller 13 14#define 15 echoPin 3 //This initializes the Echo pin of HC-05 Ultrasonic Sensor to the pin 16 no. 3 of Arduino Microcontroller 17 18Servo sm; //Servo is a Class which is 19 providing an independent data type // sm is a variable which is representing the 20 servo motor 21 22int sound=250; 23 24void setup() { 25 Serial.begin(9600); 26 //Streaming 9600 bits of sensor data per second 27 28 pinMode(trigPin,OUTPUT); 29 //Here, Trig pin triggers the electrical impulses into the sensor as an output 30 31 32 pinMode(echoPin,INPUT); //Here, Echo pin inputs the reflective signals into 33 the sensor 34 35 sm.attach(9); //Servo motor data pin is attached to Arduino 36 Digital Pin 3 37} 38void loop() { 39 long duration, distance; 40 41 digitalWrite(trigPin, 42 LOW); 43 delayMicroseconds(2); 44 45 digitalWrite(trigPin, HIGH); 46 delayMicroseconds(10); 47 48 digitalWrite(trigPin, LOW); 49 50 duration=pulseIn(echoPin, HIGH); 51 52 53 distance=(duration/2)/29.1; //Calculation of distance 54 if(distance<10) 55 56 { 57 sm.write(80); 58 } 59 else { 60 sm.write(0); 61} 62 63}
Program of Automated Rail Crossing System
arduino
1//the code is entirely created by: SHEEKAR BANERJEE (at December 2017) 2//Dept. 3 of CSE, IUBAT UNIVERSITY 4//AI-ML-IOT Solution Engineer and Researcher 5 6 7#include<Servo.h> 8 //This calls the Header of the repository containing the library files of Servo 9 Motor Driver Modules 10#define trigPin 9 //This initializes the Trig pin of HC-05 11 Ultrasonic Sensor to the pin no. 9 of Arduino Microcontroller 12#define echoPin 13 10 //This initializes the Echo pin of HC-05 Ultrasonic Sensor to the pin no. 10 14 of Arduino Microcontroller 15 16Servo sm; //Servo is a Class which is providing 17 an independent data type // sm is a variable which is representing the servo motor 18int 19 sound=250; 20 21 22void setup() { 23 Serial.begin(9600); //Streaming 9600 bits 24 of sensor data per second 25 pinMode(trigPin,OUTPUT); //Here, Trig pin triggers 26 the electrical impulses into the sensor as an output 27 pinMode(echoPin,INPUT); 28 //Here, Echo pin inputs the reflective signals into the sensor 29 sm.attach(3); 30 //The Coding Yellow Wire of the Servo motor is attached to the pin no. 31 3 of Arduino Microcontroller 32} 33 34void loop() { 35 long duration, distance; 36 37 digitalWrite(trigPin, LOW); 38 delayMicroseconds(2); // It will wait 39 for 2 microseconds after every single electrical implulse of Trig pin if it is sending 40 LOW(less than 1.6V) signal 41 digitalWrite(trigPin, HIGH); 42 delayMicroseconds(10); 43 //It will wait for 10 microseconds after every single electrical implulse 44 of Trig pin if it is sending HIGH(greater than 1.6V) signal 45 digitalWrite(trigPin, 46 LOW); 47 48 49 duration=pulseIn(echoPin, HIGH); //Sensor inputs the signal 50 through the Echo pin 51 distance=(duration/2)/29.1; //Calculation of distance 52 53 if(distance<10) //According to the reflection time calculation, if the distance 54 is less than 10 cm 55 { 56 57 sm.write(80); //than the Servo Motor 58 will rotate for 80 degrees 59 } 60 else { 61 62 sm.write(0); //Unless 63 this, the Servo motor will stand still 64 65} 66 67}
Downloadable files
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Circuit Diagram of Automated Rail Crossing System
Comments
Only logged in users can leave comments