I am controlling 2 motors from my Arduino Pro Mini and L293D motor driver module. Problem is, I have to set a pin high and after 1 second set it to LOW. But that doesn't happen... The pin just stays HIGH and is never LOW.
Here's my Code -
int IN2Left = 10;
int E1 = 12;
int E2 = 7;
int IN3RevRight = 6;
int trigPin1 = A0;
int echoPin1 = A1;
int distance1 = 0;
int IN4Right = 5;
int IN1RevLeft = 11;
void setup()
{
pinMode(IN2Left, OUTPUT);
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
pinMode(IN3RevRight, OUTPUT);
pinMode(IN4Right, OUTPUT);
pinMode(IN1RevLeft, OUTPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(13, HIGH);
digitalWrite(E1, HIGH);
digitalWrite(E2, HIGH);
digitalWrite(IN2Left, HIGH);
digitalWrite(IN4Right, HIGH);
delay(3000);
digitalWrite(IN4Right, LOW);
digitalWrite(IN3RevRight,HIGH);
delay(500);
digitalWrite(IN3RevRight, LOW);
digitalWrite(IN4Right, HIGH);
delay(1500);
digitalWrite(IN2Left, LOW);
digitalWrite(IN1RevLeft, HIGH);
delay(500);
digitalWrite(IN1RevLeft, LOW);
digitalWrite(IN2Left, HIGH);
delay(100000);
}
The IN2Left
Pin never goes LOW... I am assuming a faulty Arduino but my Arduino seems to be working just fine as it runs other stuff (tested blink and reading an Ultrasonic sensor) just fine.
My deadline is 2 hours from now...
EDIT: Here's the complete void loop function... Note the two pins on top which go HIGH? They Never go LOW again in the entire code.
2 Answers 2
Your code sets it high, delays for 1000ms, sets it low, and then... turns around and sets it high almost immediately after. Try delaying in between.
-
1Beaten by 24 seconds. :)2016年11月15日 07:16:07 +00:00Commented Nov 15, 2016 at 7:16
-
yeah it does... However, if the LOW command is in an if it never executes even when the if block runs.YaddyVirus– YaddyVirus2016年11月15日 08:16:35 +00:00Commented Nov 15, 2016 at 8:16
digitalWrite(IN2Left, HIGH);
delay(1000);
digitalWrite(IN2Left, LOW);
It would go LOW for a few microseconds. Maybe put a delay after going LOW?
-
yeah it does... However, if the LOW command is in an
if
it never executes even when the if block runs...YaddyVirus– YaddyVirus2016年11月15日 08:16:21 +00:00Commented Nov 15, 2016 at 8:16 -
@YaddyVirus Maybe you are trying to pull down something stronger than output driver. How about using LEDs with series resistors to confirm it (with everything else disconnected)?KIIV– KIIV2016年11月15日 08:52:31 +00:00Commented Nov 15, 2016 at 8:52
-
2if the LOW command is in an if - What are you talking about? There is no
if
in your code.2016年11月15日 09:05:59 +00:00Commented Nov 15, 2016 at 9:05 -
@NickGammon Actually I tried various ways of setting pins to LOW... One was to set a condition and accordingly set the pins to LOW.YaddyVirus– YaddyVirus2016年11月15日 14:37:04 +00:00Commented Nov 15, 2016 at 14:37
-
Try:
void setup() { pinMode(10, OUTPUT); digitalWrite (10, LOW); } void loop () {}
- is pin 10 low then? If so, you can't say that pin 10 "never" goes low.2016年11月15日 20:28:29 +00:00Commented Nov 15, 2016 at 20:28
Explore related questions
See similar questions with these tags.
int main () { }
does the pin in question start off high?