Code error

I am trying to write an Arduino code that can Rotate Camera Based on Sound sensor like the code showing , the problem that the stepper motor just Spain without stoping!!

int motorPin1 = 8; int motorPin2 = 10; int motorPin3 = 9; int motorPin4 = 11; int sound_sensor1 = A8; int sound_sensor2 = A9;

int delayTime = 20;

void setup() { pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); pinMode(sound_sensor1, INPUT); pinMode(sound_sensor2, INPUT);

}

void loop() { int sensor1 = analogRead(sensor1); int sensor2 = analogRead(sensor2); if (sensor1 >sensor2); { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); } if (sensor2 >sensor1); { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); } }

Try defining your pin variables with the word pin in it, like const byte  sound_sensor1_[color=Red][b]Pin[/b][/color] = A8; Instead of int sound_sensor1 = A8;

You'll see then that it makes writting analogRead() commands easier and more obvious to debug :)

  int sensor1 = analogRead(sensor1);
  int sensor2 = analogRead(sensor2);

(Hope the hint is big enough for you to find one of your bug)

Which Arduino board are you using ?

 if (status_sensor1 > status_sensor2);

Why are you comparing 2 variables that have not been declared ? Why is there a semicolon on the end of the comparison ?

sorry that after 1000 trying to fix the code :) the first one was declared all that the code now , iam using arduino mega

int motorPin1 = 8; int motorPin2 = 10; int motorPin3 = 9; int motorPin4 = 11; const byte sound_sensor1_Pin = A8; const byte sound_sensor2_Pin = A9;

int delayTime = 20;

void setup() { pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); pinMode(sound_sensor1_Pin, INPUT); pinMode(sound_sensor2_Pin, INPUT);

}

void loop() { int sensor1 = analogRead(sound_sensor1_Pin); int sensor2 = analogRead(sound_sensor2_Pin); if (sensor1 >sensor2) { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); } if (sensor2 >sensor1) { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); } }

J-M-L: Try defining your pin variables with the word pin in it, like const byte sound_sensor1_[color=Red][b]Pin[/b][/color] = A8; Instead of int sound_sensor1 = A8;

You'll see then that it makes writting analogRead() commands easier and more obvious to debug :)

 int sensor1 = analogRead(sensor1);
  int sensor2 = analogRead(sensor2);

(Hope the hint is big enough for you to find one of your bug)

Yeah now if sound is there the led on uln2003 light but stepper motor, not moving

Try first playing with your motor and understand how they work

J-M-L: Try first playing with your motor and understand how they work

J-M-L: Try first playing with your motor and understand how they work

Ok thanks, man :), but there is any other way to comd stepper to move like if sound1==1 step=left ? I mean stepper motor has name on direction?

What motor do you have ? What are the 4 pins Connected to?

J-M-L: What motor do you have ? What are the 4 pins Connected to?

i have stepper motor 28byj in1=8 in2 =10 in3=9 in4= 11

With a ULN2003?

J-M-L: With a ULN2003?

yes with ULN2003A I tested stepper with code from Arduino web and work fine