hi, after successfully running this program with the proper electronics (i.e. i used a power supply tester with the proper voltage and current settings), i've come to the conlusion that something in my code may not be cycling properly.
basically my elevation motor is listed in the loop first that spins clockwise and it briefly spun couterclockwise. however, when i cover up the other photoresistors the results show up in the serial monitor but they azimuth motor never spins and the elevation motor only spins clockwise.
any thoughts?
/ Special thanks to Geo Bruce on instructables.com for his version of the code.
// Enable A and Enable B pins on dual motors h-bridge must be connected to two pwm (pulse width modulation) pins on arduino uno/micro/pro mini: 3,5,6,9,10,11.
int enA = 3; int in1 = 4; int in2 = 5; // motor azimuth adjustment
int enB = 9; int in3 = 7; int in4 = 8; // motor elevation adjustment
void setup()
{
Serial.begin(9600); // initialize the serial port
pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(enB, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); // set all the motor control pins to outputs
}
void loop()
{
// LIGHT SENSOR (in this case a Light Dependent Resistor) pin connections and analog pin on respective arduino board
int tr = analogRead(0); // top right
int br = analogRead(1); // bottom right
int tl = analogRead(2); // top left
int bl = analogRead(3); // bottom left
int delaytime = analogRead(A7)*2; // control delay time in milliseconds of LIGHT SENSOR readings
int tolerance = analogRead(A6)/4; // set range of tolerance between LIGHT SENSOR readings
//print LIGHT SENSOR values to serial monitor for debugging
Serial.println(tl); Serial.println(bl); Serial.println(tr); Serial.println(br); Serial.println(delaytime); Serial.println(tolerance); Serial.println();
int count = 0; //start millisecond count of LIGHT SENSOR readings
count++; //incremental count increase, continues to show LIGHT SENSOR results
int avt = (tr + tl) / 2; // average value top
int avd = (bl + br) / 2; // average value down
int avl = (tl + bl) / 2; // average value left
int avr = (tr + br) / 2; // average value right
int dv = avt - avd; // average difference of top and bottom LIGHT SENSORS
int dh = avl - avr;// average difference of left and right LIGHT SENSORS
if (-1*tolerance > dv || dv > tolerance) // check if the difference in top/bottom LIGHT SENSORS is greater than tolerance
{
if (avt > avd) // if average LIGHT SENSOR values on top side are greater than on bottom side then elevation motor rotates CLOCKWISE
{
digitalWrite(in3, LOW); digitalWrite(in4, HIGH); analogWrite(enB, 200); // set speed out of possible range 0~255
}
else // if average LIGHT SENSOR values on bottom side are greater than on top side then elevation motor rotates COUNTERCLOCKWISE
{
digitalWrite(in3, HIGH); digitalWrite(in4, LOW); analogWrite(enB, 200);
}
}
else if (-1*tolerance < dv || dv < tolerance) // if difference is smaller than tolerance, STOP elevation motor
{
digitalWrite(in3, LOW); digitalWrite(in4, LOW);
}
if (-1*tolerance > dh || dh > tolerance) // check if the difference in left and right LIGHT SENSORS is within tolerance range
{
if (avl > avr) // if average LIGHT SENSOR values on left side are greater than right side, azimuth motor rotates CLOCKWISE
{
digitalWrite(in1, HIGH); digitalWrite(in2, LOW); analogWrite(enA, 200);
}
else // if average LIGHT SENSOR values on right side are greater than on left side, azimuth motor rotates COUNTERCLOCKWISE
{
digitalWrite(in1, LOW); digitalWrite(in2, HIGH); analogWrite(enA, 200);
}
}
else if (-1*tolerance < dh || dh < tolerance) //if difference is smaller than tolerance, STOP azimuth motor
{
digitalWrite(in1, LOW); digitalWrite(in2, LOW);
}
delay(delaytime);
}

