Automatic door with HC-SR04 and L298N Motor driver

Chris2201:
OMG, this is all a little bit to much as a newbie =(...I found this code online and bought that i just ad everything for the second sensor...

Code you find online can be a good starting point but make sure you understand every single line and know what it does, and why it's there. Look up commands you don't know.

Delay() calls are best to be avoided. A finite state machine is in order here, combined with millis() based timing. This way you can continue to monitor the area, and as long as you detect something (presumably your dog rather than the neighbour's cat) the door stays open.

You should also add some safety device to prevent the door from closing on your dog. E.g. as push bar with switch on the edge of the door, when it touches something the door opens again.

Ultrasound sensors at times give false signals (too high or too low). If you measure say 10 times a second, only open the door after 1 second (10 measurements) that are < 2 ft. That should take care of strays. Or add a longer delay, of say 5 seconds, so the door won't open when the dog just walks by, only when he sits in front of it for that period of time. I suppose it will be pretty easy to teach your dog how to open its door.

If you don't use newPing, add a timeout to pulseIn or it sits there for a full second if there's nothing in range and no echo comes back to the sensor. Waiting for 30 ms is more than enough (that's about 5 meter distance - 10 meter round trip).