I had been trying to make Arduino Fire Fighter Robot but facing several problems in interfacing 3 flame sensors and servo together. When I upload the following code( Which I had posted at the end of my writing) my robot goes backward and detects flame at the front sensor and displays " Flame on Front" on 16x2 LCD display and the 5v pump pumps out water and the red LED blinks. But my robot was supposed to work in the following way- Initially, my robot will be at rest. There are 3 sensors attached at the front part of the robot. And there is a SG90 servo for rotating the water tank( in this tank there is a 5v pump motor and the pump motor will pump out water from this tank). When any one of the three flame sensors will detect flame then the servo will rotate in that direction and when the front flame sensor detects fire , the servo will be in 90-degree angle. LCD will display the status of the flame sensors. But the robot is not working properly. I am not able to interface 3 flame sensors and servo altogether and I am also unable to understand what's the error in the code. Can anyone help me to solve the problem by editing the code? Onl one day is left for my project submission.
Here is the code:
#include <Servo.h>
Servo myservo;
int pos = 0;
boolean fire = false;
#include <LiquidCrystal.h>
int Contrast=20;// for adjusting the brightness of the LCD , 20 is selected for the contrast of LCD
LiquidCrystal lcd(30,31,32,33,34,35);
int buzz= 38; //for led or buzzer
#define Left_S 9 // left sensor
#define Right_S 8 // right sensor
#define Forward_S 23 //forward sensor
#define LM1 52 //for pump motor
#define LM2 53 //for pump motor
#define IN1 5 //for motor
#define IN2 4 // for motor
#define IN3 3 //for motor
#define IN4 22 // for motor
//int flame_pin1 = HIGH ;
int LEDR= 36; // for danger signal
int LEDB=37;// for safe signal
void setup ( ) {
analogWrite(6,Contrast);
lcd.begin(16, 2);
pinMode(Left_S, INPUT);
pinMode(Left_S, INPUT);
pinMode(Right_S, INPUT);
pinMode (Forward_S,OUTPUT);
pinMode (LEDB,OUTPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode( buzz,OUTPUT );
pinMode(LEDR,OUTPUT);
pinMode(LEDB, OUTPUT);
// pinMode ( flame_sensor_pinM , INPUT );
//Serial.begin ( 9600 );
myservo.attach(25);
myservo.write(90);
}
void put_off_fire()
{
delay (500);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
delay(500);
for (pos = 50; pos <= 130; pos += 1) {
myservo.write(pos);
delay(10);
}
for (pos = 130; pos >= 50; pos -= 1) {
myservo.write(pos);
delay(10);
}
digitalWrite(LM1,LOW);
digitalWrite(LM2,LOW);
myservo.write(90);
fire=false;
}
void loop ( ){
myservo.write(90); //Sweep_Servo();
if (digitalRead(Left_S) ==1 && digitalRead(Right_S)==1 && digitalRead(Forward_S) ==1) //If Fire not detected all sensors are zero
{
//Do not move the robot
lcd.setCursor(0, 1);
lcd.print("Flame on front");
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
digitalWrite(LEDR,LOW);
digitalWrite(LEDB,HIGH);
digitalWrite(buzz,LOW);
}
else if (digitalRead(Forward_S) ==0) //If Fire is straight ahead
{
//Move the robot forward
lcd.setCursor(0, 1);
lcd.print("Flame on front");
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,LOW);
digitalWrite(buzz,HIGH);
fire = true;
}
else if (digitalRead(Left_S) ==0) //If Fire is to the left
{
lcd.setCursor(0, 1);
lcd.print("Flame on left");
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,LOW);
digitalWrite(buzz,HIGH);
}
else if (digitalRead(Right_S) ==0) //If Fire is to the right
{
//Move the robot right
lcd.setCursor(0, 1);
lcd.print("Flame on Right");
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,LOW);
digitalWrite(buzz,HIGH);
}
delay(300); //Slow down the speed of robot
while (fire == true)
{
put_off_fire();
}
}