PIR L298 motor control

Newbie. I want the PIR sensor to turn the motor on three seconds. I've edited the sketch every which way but the right way. Would appreciate help. Thank you.

void setup()
{
  pinMode(2, INPUT);  // pir
  pinMode(3, OUTPUT); // enable pin
  pinMode(4, OUTPUT); // output1
  pinMode(5, OUTPUT); // output2
  digitalWrite(3, HIGH); // enabling
  digitalWrite(2, LOW); // putting PIR into LOW 
  digitalWrite(4, LOW); // default pin HIGH
  digitalWrite(5, LOW); 
  delay(1500); //calibration time for pir
}

void loop()
{
  if (digitalRead(2) == HIGH){
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    delay(15000);
  }
  else{
    digitalWrite(5, LOW);
    digitalWrite(4, LOW);
  }
  delay(1500);
}

what circuit are you using to control the motor?
doesn't the enable pin need to be set HIGH and the pins 4 and 5 set oppositely to control direction?

You forgot to say what the code is doing now, if anything.

If it does nothing, take the if/else out and see if the motor switches on then off. That will tell you if the L298N and motor are wired and powered correctly.

Steve

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