0
votes

I am attempting to move a stepper motor from the input of two IR flame detectors on my Arduino. Right now my code appears as if theoretically it should work but for some reason it is not working correctly. I think it may be just a simple syntax error, but I know for sure the Arduino is registering the signal coming from the IR sensor as the serial monitor is showing.

 #include <Stepper.h>  //Starts the stepper library

Stepper RoboticArm(4096, 5, 6, 7, 8);  //Sets the number of steps and the   interface connection ports

int IRDetector1Output = 10;  //IR Detector 1 set to Digital Pin 3
int IRDetector2Output = 11;  //IR Detector 2 set to Digital Pin 4




void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);  //Starting the monitor for computer telemetry scripts

  pinMode(IRDetector1Output, INPUT);
  pinMode(IRDetector2Output, INPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
      if (digitalRead(IRDetector1Output) == HIGH && digitalRead    (IRDetector2Output) == HIGH);  //When both IR detectors show vehicle centered, do not move tracking mount
  Serial.print("TRACKING ASCENT: CENTER");
  {
  RoboticArm.setSpeed(0);  //RPM set to zero on stepper motor
  RoboticArm.step(4096);  //Number of steps in stepper motor
  Serial.print("TRACKING ASCENT: CENTER");
  }
  if (digitalRead(IRDetector1Output) == HIGH);
  {
  RoboticArm.setSpeed(3);  //RPM set to 3 upwards to track vehicle
  RoboticArm.step(4096);  //Number of steps in stepper motor
  Serial.print("TRACKING ASCENT: UPWARDS COURSE CORRECTION");
  }
  if (digitalRead(IRDetector1Output) == LOW);
  {
  RoboticArm.setSpeed(-3);  //RPM set to -3 downwards to track vehicle
  RoboticArm.step(4096);  //Number of steps in stepper motor
  Serial.print("TRACKING ASCENT: DOWNWARDS COURSE CORRECTION");
  }
} 
1
The semi-colons at the end of your if statements mean that nothing is executed inside the if. Try removing them.Hans Kilian
I did attempt that but I am still running into the same issue. The detector is picking up flame for sure but the Arduino just isn't carrying out the function as it should be. I did check to make sure the motor was working correctly along with the driver and the wiring is correct.Alex Polimeni

1 Answers

0
votes

Although I'm not familiar with stepper motors, there appears to be a syntax error at:

    if (digitalRead(IRDetector1Output) == HIGH && digitalRead    (IRDetector2Output) == HIGH);  //When both IR detectors show vehicle centered, do not move tracking mount
  Serial.print("TRACKING ASCENT: CENTER");
  {
  RoboticArm.setSpeed(0);  //RPM set to zero on stepper motor
  RoboticArm.step(4096);  //Number of steps in stepper motor
  Serial.print("TRACKING ASCENT: CENTER");
  }

I think that you meant to do this:

if (digitalRead(IRDetector1Output) == HIGH && digitalRead(IRDetector2Output) == HIGH)  //When both IR detectors show vehicle centered, do not move tracking mount
  {
  Serial.print("TRACKING ASCENT: CENTER");
  RoboticArm.setSpeed(0);  //RPM set to zero on stepper motor
  RoboticArm.step(4096);  //Number of steps in stepper motor
  Serial.print("TRACKING ASCENT: CENTER");
  }

(You said to write to the serial port outside of the curly brackets.)