Project: RAILWAY TRACK CRACK DETECTION ROBOT
I). Existing Problem Statement
Railway accidents due to undetected track cracks or breaks have caused thousands
of injuries and deaths globally. Manual inspection is time-consuming,
inefficient, and prone to human error, especially across remote or long
stretches of tracks. Delayed detection can lead to catastrophic derailments and
loss of human life and property.
II). Need for This Project
The Railway Track Crack Detection Robot aims to provide an automated solution
for early crack detection on railway tracks. This project helps railway
maintenance teams to:
Continuously monitor railway tracks.
Detect cracks in real-time using IR sensors.
Alert authorities or operators instantly.
Prevent derailments and save lives.
III). List of All Components Details, Variant and Number Count
1. Arduino Uno (1 piece) — microcontroller to process sensor data.
2. IR Sensor Module (2 pieces) — to detect cracks in the rail track.
3. L298N Motor Driver Module (1 piece) — to control the DC motors.
4. BO Motors (2 pieces) — for robot movement.
5. Robot chassis with wheels (1 kit) — for mounting all parts.
6. 9V Battery or 12V battery pack (1 piece) — for power supply.
7. Jumper Wires (20+ pieces) — for connections.
8. Buzzer Module (1 piece) — to alert when crack is detected.
9. Switch (1 piece) — to turn robot on/off.
10. LED (optional, 1 piece) — for visual indication.
11. Breadboard (1 piece) — for quick connections if needed.
IV). All Connection Details (Arrow Mark Format)
IR Sensor 1 OUT ---------> Arduino Digital Pin 8
IR Sensor 2 OUT ---------> Arduino Digital Pin 9
IR Sensor 1 VCC ---------> Arduino 5V
IR Sensor 2 VCC ---------> Arduino 5V
IR Sensor 1 GND ---------> Arduino GND
IR Sensor 2 GND ---------> Arduino GND
Arduino Digital Pin 2 -----> L298N IN1
Arduino Digital Pin 3 -----> L298N IN2
Arduino Digital Pin 4 -----> L298N IN3
Arduino Digital Pin 5 -----> L298N IN4
Arduino GND ---------> L298N GND
Arduino 5V ---------> L298N 5V (if jumper removed, else power from
12V)
L298N OUT1 ---------> Motor Left +
L298N OUT2 ---------> Motor Left –
L298N OUT3 ---------> Motor Right +
L298N OUT4 ---------> Motor Right –
Buzzer + ----------> Arduino Digital Pin 6
Buzzer – ----------> Arduino GND
Battery + ----------> L298N 12V
Battery – ----------> Arduino GND and L298N GND
V). Arduino Program Code (No Error, Fully Functional)
#define irSensorLeft 8
#define irSensorRight 9
#define motor1Pin1 2
#define motor1Pin2 3
#define motor2Pin1 4
#define motor2Pin2 5
#define buzzerPin 6
void setup() {
pinMode(irSensorLeft, INPUT);
pinMode(irSensorRight, INPUT);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int leftIR = digitalRead(irSensorLeft);
int rightIR = digitalRead(irSensorRight);
// When both sensors detect surface, no crack
if (leftIR == HIGH && rightIR == HIGH) {
moveForward();
digitalWrite(buzzerPin, LOW);
Serial.println("Track OK");
} else {
stopMotors();
digitalWrite(buzzerPin, HIGH);
Serial.println("Crack Detected!");
delay(3000); // Stop for 3 seconds after detecting crack
}
}
void moveForward() {
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
}
void stopMotors() {
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
}
VI). Line-by-Line Code Explanation
#define irSensorLeft 8
#define irSensorRight 9
Defines digital pins 8 and 9 as the inputs for the two IR sensors (left and
right).
#define motor1Pin1 2
#define motor1Pin2 3
#define motor2Pin1 4
#define motor2Pin2 5
Defines motor control pins connected to the L298N motor driver. Two pins per
motor to control direction.
#define buzzerPin 6
Defines pin 6 to control the buzzer for alert.
void setup() {
pinMode(irSensorLeft, INPUT);
pinMode(irSensorRight, INPUT);
Sets the IR sensor pins as input to read HIGH/LOW values.
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
Sets motor control pins as output to drive motors.
pinMode(buzzerPin, OUTPUT);
Sets buzzer pin as output.
Serial.begin(9600);
Starts serial communication to show status in serial monitor (debugging).
void loop() {
int leftIR = digitalRead(irSensorLeft);
int rightIR = digitalRead(irSensorRight);
Reads the values from both IR sensors (either HIGH or LOW).
if (leftIR == HIGH && rightIR == HIGH) {
moveForward();
digitalWrite(buzzerPin, LOW);
Serial.println("Track OK");
} else {
stopMotors();
digitalWrite(buzzerPin, HIGH);
Serial.println("Crack Detected!");
delay(3000);
}
If both sensors detect the surface (no crack), the robot moves forward. If
either sensor detects a crack (returns LOW), motors stop, buzzer alerts, and a
message is displayed.
void moveForward() {
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
}
Moves both motors forward by applying HIGH and LOW signals in the correct
direction.
void stopMotors() {
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
}
Stops both motors by cutting off power.