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);

    void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(E1, HIGH);
  digitalWrite(E2, HIGH);
  digitalWrite(IN2Left, HIGH);
  digitalWrite(IN4Right, HIGH);
  digitalWrite(IN4Right, LOW);
  digitalWrite(IN3RevRight, LOW);
  digitalWrite(IN4Right, HIGH);
  digitalWrite(IN2Left, LOW);
  digitalWrite(IN1RevLeft, HIGH);
  digitalWrite(IN1RevLeft, LOW);
  digitalWrite(IN2Left, HIGH);

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.

  • If you load a blank sketch, like int main () { } does the pin in question start off high? – Nick Gammon Nov 15 '16 at 9:13
  • Are you sure there isn't something else connected to pin 10? – Gerben Nov 15 '16 at 11:11
  • @NickGammon No... Its very strange.. – YaddyVirus Nov 15 '16 at 14:35
  • @Gerben Too damn sure – YaddyVirus Nov 15 '16 at 14:35
  • 1
    I tried your amended code and the pin went low every 1 minute 40 seconds for half a second, which is what you told it to do. You have to watch closely to spot it. – Nick Gammon Nov 15 '16 at 20:37

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.

  • 1
    Beaten by 24 seconds. :) – Nick Gammon Nov 15 '16 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 Nov 15 '16 at 8:16
  digitalWrite(IN2Left, HIGH);
  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 Nov 15 '16 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 Nov 15 '16 at 8:52
  • 2
    if the LOW command is in an if - What are you talking about? There is no if in your code. – Nick Gammon Nov 15 '16 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 Nov 15 '16 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. – Nick Gammon Nov 15 '16 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.