Automatic door with HC-SR04 and L298N Motor driver

You've included NewPing library, but you haven't used it. Suggest using its median method for more stable results. Look at its examples.

What is the following code supposed to be doing? The duration from the first pulseIn of the first sensor (the one with the desired information) is never used. And why four pulseIns? (All this goes away if you use NewPing, btw.)

  duration = pulseIn(echoPin, HIGH);
  duration = pulseIn(echoPin2, HIGH);
  distance = (duration/2) / 29.1;
  duration = duration + pulseIn(echoPin, HIGH);
  duration = duration + pulseIn(echoPin2, HIGH);
  distance2 = (duration/2) / 60;

Why bother with two conditions when they're the same? Looks like you left out a "2".

if (distance < 30 || distance < 30)

Suggest you read up on how to not use delays. See the sticky "using millis() for timing" at the top of the programming section of this forum.

delay(5000);
delay(6000);
delay(8000);
delay(500);

Suggest also reading "Planning and implementing a program" in the "useful links" post in the programming section.