0% found this document useful (0 votes)
7 views8 pages

FireFighting CodeExplanationLineByLine

The document provides a detailed line-by-line explanation of Arduino code for a fire-fighting robot, aimed at a Class 8 CBSE student. It covers pin definitions, sensor and actuator setup, motor control, and fire detection logic. The explanation is designed to be simple yet technically accurate, enabling students to understand and explain the code in a viva setting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

FireFighting CodeExplanationLineByLine

The document provides a detailed line-by-line explanation of Arduino code for a fire-fighting robot, aimed at a Class 8 CBSE student. It covers pin definitions, sensor and actuator setup, motor control, and fire detection logic. The explanation is designed to be simple yet technically accurate, enabling students to understand and explain the code in a viva setting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

I’ll explain the entire Arduino code from the PDF line by line, in a way that a Class 8

CBSE student can understand and also explain in a viva.


I’ll keep the language simple, but technically correct.

I’ll go top to bottom, exactly as in the PDF.

LINE-BY-LINE EXPLANATION OF THE


CODE
(Fire Fighting Robot – Arduino)

HEADER SECTION (PIN DEFINITIONS)


#define enA 10

enA is the Enable pin for Motor A in the L298 motor driver.
This pin controls the speed of the motor using PWM.

#define in1 9
#define in2 8

These pins control the direction of Motor 1 (right side motors).

 in1 HIGH + in2 LOW → motor moves forward


 in1 LOW + in2 HIGH → motor moves backward

#define in3 7
#define in4 6

These pins control the direction of Motor 2 (left side motors).

#define enB 5

enB is the Enable pin for Motor B (speed control for left motors).
SENSOR & ACTUATOR PINS
#define ir_R A0
#define ir_F A1
#define ir_L A2

These are flame sensor pins:

 ir_R → Right flame sensor


 ir_F → Front flame sensor
 ir_L → Left flame sensor

They are connected to analog pins so we can read flame intensity.

#define servo A4

This pin controls the servo motor, which rotates the water pipe.

#define pump A5

This pin controls the water pump using a TIP122 transistor.

VARIABLE DECLARATION
int Speed = 160;

Motor speed value (range 0–255).


160 is a medium safe speed.

int s1, s2, s3;

Variables to store flame sensor readings:

 s1 → right sensor
 s2 → front sensor
 s3 → left sensor

SETUP FUNCTION (RUNS ONCE)


void setup(){

setup() runs only once when Arduino is powered ON.

[Link](9600);

Starts serial communication to see sensor values on the computer.

pinMode(ir_R, INPUT);
pinMode(ir_F, INPUT);
pinMode(ir_L, INPUT);

Flame sensors are inputs (Arduino reads data from them).

pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(enB, OUTPUT);

Motor driver pins are outputs (Arduino controls motors).

pinMode(servo, OUTPUT);
pinMode(pump, OUTPUT);

Servo motor and pump are controlled by Arduino → OUTPUT.

SERVO INITIAL MOVEMENT


for (int angle = 90; angle <= 140; angle += 5) {
servoPulse(servo, angle);
}

Moves servo right side slowly to check movement.

for (int angle = 140; angle >= 40; angle -= 5) {


servoPulse(servo, angle);
}

Moves servo left side fully.


for (int angle = 40; angle <= 95; angle += 5) {
servoPulse(servo, angle);
}

Brings servo back to center position.

MOTOR SPEED SETTING


analogWrite(enA, Speed);
analogWrite(enB, Speed);

Sets speed for both motors using PWM.

delay(500);
}

Waits for half a second.


setup() ends here.

LOOP FUNCTION (RUNS CONTINUOUSLY)


void loop(){

This runs again and again as long as Arduino is ON.

s1 = analogRead(ir_R);
s2 = analogRead(ir_F);
s3 = analogRead(ir_L);

Reads flame intensity values from sensors.

Lower value = stronger fire

[Link](s1);
[Link]("\t");
[Link](s2);
[Link]("\t");
[Link](s3);

Prints sensor values on Serial Monitor for testing.


delay(50);

Small delay for stability.

FIRE DETECTION LOGIC


if(s1 < 250){

Fire detected on right side.

Stop();
digitalWrite(pump, 1);

Robot stops and water pump ON.

for(int angle = 90; angle >= 40; angle -= 3){


servoPulse(servo, angle);
}

Servo sprays water towards right.

for(int angle = 40; angle <= 90; angle += 3){


servoPulse(servo, angle);
}

Servo returns to center.

FRONT FIRE
else if(s2 < 350){

Fire detected in front.

Robot stops, pump ON, servo moves left-right fully to spray water.
LEFT FIRE
else if(s3 < 250){

Fire detected on left side.

Stops robot, turns servo left, sprays water.

SEARCHING FOR FIRE


else if(s1>=251 && s1<=700){

Fire is far on right → robot turns right slowly.

else if(s2>=251 && s2<=800){

Fire far in front → robot moves forward.

else if(s3>=251 && s3<=700){

Fire far on left → robot turns left.

else{
digitalWrite(pump, 0);
Stop();
}

No fire → robot stops and pump OFF.

SERVO FUNCTION
void servoPulse (int pin, int angle){

Function to rotate servo to a specific angle.

int pwm = (angle*11) + 500;


Converts angle into PWM signal.

digitalWrite(pin, HIGH);
delayMicroseconds(pwm);
digitalWrite(pin, LOW);

Sends pulse to servo.

delay(50);
}

Refresh delay.

MOTOR MOVEMENT FUNCTIONS


void forword(){

Moves robot forward.

void backword(){

Moves robot backward.

void turnRight(){

Robot turns right.

void turnLeft(){

Robot turns left.

void Stop(){

Stops all motors.

✅HOW TO EXPLAIN IN VIVA (1 LINE)


“The Arduino reads flame sensors, decides the fire direction, moves the robot using motors,
and sprays water automatically using a pump and servo motor.”

If you want next, I can:


1 ⃣ Convert this into student-friendly viva Q&A
2 ⃣ Highlight important lines to memorize
3 ⃣ Simplify code explanation into 1-page notes

Just reply 1, 2, or 3

You might also like