接收来自传感器的输入以移动步进电机Arduino

时间:2015-10-19 03:12:04

标签: arduino

我试图从我的Arduino上的两个红外火焰探测器的输入端移动一个步进电机。现在我的代码看起来似乎理论上它应该工作但由于某种原因它不能正常工作。我认为这可能只是一个简单的语法错误,但我确信Arduino正在注册来自IR传感器的信号,因为串行监视器正在显示。

 #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 个答案:

答案 0 :(得分:0)

虽然我不熟悉步进电机,但似乎存在语法错误:

    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 && 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");
  }

(你说要写在大括号外的串口。)