DaveEvans:
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 [u]not[/u] 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.
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...
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;
for this part i've used a part of an arduino door project, all the values are to adjust opening and closing time, because of some light mechanical reasons the door closes minimal slower then it opens just about a second so I have all the delays to adjust them because I'm not using any switches.... (not yet in this stage of not understanding the programming language so well....)
delay(5000);
delay(6000);
delay(8000);
delay(500);
I will definitely try to separate the sensors, pointing in two directions...it works with one sensor, and with two it worked but sometimes it gets into a kind of infinite loop...
and the main problem is when i power it up, there is a unwanted movement, 2 sec left 3 sec right... and this is sth I really dont understand.....
but thank you for the first tipps....