Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1074

Pump is always on even when fire is not detected

$
0
0

I am making a fire fighting robot for my school project. I am using arduino nano with flame sensors. Even when the flame is not detected the pump is on. The pump is powered through a relay module. Please help me . Sorry if I have made any mistake in choosing the catagory for the post. This is my first post. Here's the code:

#include <Wire.h>
#include <Servo.h>

Servo myservo;

#define Left A2
#define Right A1
#define Forward A0
#define LM1 2
#define LM2 3
#define RM1 4
#define RM2 5
#define pump 7

void setup() {
  pinMode(Left, INPUT);
  pinMode(Right, INPUT);
  pinMode(Forward, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
  pinMode(pump, OUTPUT);

  myservo.attach(11);
  myservo.write(90);

  digitalWrite(pump, HIGH); // Initialize pump pin to LOW
}

void sweepServo() {
  for (int pos = 50; pos <= 130; pos += 1) {
    myservo.write(pos);
    delay(10);
  }
  for (int pos = 130; pos >= 50; pos -= 1) {
    myservo.write(pos);
    delay(10);
  }
}

void put_off_fire() {
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
  digitalWrite(pump, HIGH);
  sweepServo();  
  digitalWrite(pump, LOW); // Turn off the pump after sweeping
}

void loop() {
  int leftSensor = digitalRead(Left);
  int rightSensor = digitalRead(Right);
  int forwardSensor = digitalRead(Forward);

  if (leftSensor && rightSensor && forwardSensor) {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, HIGH);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  } else {
    // Stop the motors
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);

    // Adjust movement based on sensor inputs
    if(forwardSensor == HIGH) {
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, HIGH);
      digitalWrite(RM2, LOW);
    }

    if (leftSensor == HIGH) {
      // Turn left
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, LOW);
    }

    if (rightSensor == HIGH) {
      // Turn right
      digitalWrite(LM1, HIGH);
      digitalWrite(LM2, HIGH);
      digitalWrite(RM1, LOW);
      digitalWrite(RM2, HIGH);
    }
  }

  // Check for fire detection (TO DO: implement fire detection logic)
  // If fire is detected, call put_off_fire() function
  // put_off_fire();
}

Here's the circuit diagram:


Hey guys we recently found a loophole in our project which is when we connect the signal pin of the relay to any digital pins the relay turns on the arduino nano is mounted on a breadboard is that the cause ?
Please help us we are out of time.

Thanks,

10 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 1074

Trending Articles