Solar tracker (full size w/ 10 panels) with L298n

Can someone tell me why this seemingly simple code won't run a DC motor back and forth using the "if" statement.

int westLimit = 10; // momentary limit switch
int eastLimit = 11; // momentary limit switch
int westLED = 3; // LED with 220 resistor
int eastLED = 6; // LEd with 220 resistor
int westLimitVal = 0; // defined in LOOP
int eastLimitVal = 0; // defined in LOOP
int in1 = 8; // jumper wire to L298n
int in2 = 9; // jumper wire to L298n

void setup() {
Serial.begin(9600);
pinMode(westLimit, INPUT);
pinMode(eastLimit, INPUT);
pinMode(westLED, OUTPUT);
pinMode(eastLED, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop() {
int westLimitVal = digitalRead(westLimit);
Serial.print("westLimtVal = "); // prints zeros & ones in Serial monitor
Serial.println(westLimitVal); // prints zeros & ones in serial monitor

int eastLimitVal = digitalRead(eastLimit);
Serial.print("eastLimtVal = "); // prints zeros & ones in serial monitor
Serial.println(eastLimitVal); // prints zeros & ones in serial monitor

if (eastLimitVal == 1) {
digitalWrite(eastLED, HIGH); // uses the same jumpers(in1 & in2)
digitalWrite(in1, HIGH); // does not turn on
digitalWrite(in2, LOW); // has worked wit different configeration
} else {
digitalWrite(eastLED, LOW); // has worked with different configeration
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
if (westLimitVal == 1) {
digitalWrite(westLED, HIGH); // works fine
digitalWrite(in1, HIGH); // works fine
digitalWrite(in2, LOW); // works fine
} else {
digitalWrite(westLED, LOW); // works fine
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
}

Please post code, not text. All according to: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum
Schematics, links to the datasheet for the motors, data for the need of torque.......

but, I did post code

No. That's text, not code. Use the link given, section "Code problems".

Please edit your post to add code tags.

The code is completely meaningless without an accurate wiring diagram (hand drawn is fine), plus links to the motors and the motor power supply.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.