Im using the standard protocol for getting distance on the sonar sensor, however, im using this on a project with multiple other sensors. When the sonar sensor is unable to receive a signal from the echo, it corrupts the serial output making time "slow down". This has caused my serial outputs to just crash on the imu im working on. Does anyone know how to prevent these values from crashing the serial screen? I have filtered them out but was unsuccessful at getting the serial monitor to not freeze time.
Maybe! Post a schematic, not a frizzy picture. Show all interconnections, power, etc. With the copious amount of code posted I have no clue as to how you are doing it. Post links to technical data on each of the sensors you are using. What is making time "slow down" tell us?
You could try changing the timeout for pulseIn from the default (one second) to something shorter and more appropriate for your project, so it doesn't block as long waiting for an echo. Or use the timer-based method in the NewPing library. And/or design a more robust serial communication system.
Indeed, add a timeout. 20,000 µs is more than enough, no need to wait a full second.
Do wait a bit between triggering individual sensors, as otherwise they may hear the echo of a previous sensor's ping and give a wrong reading. Typical something to the tune of 10-100 ms, depending on the environment you're in (longer time for more echo-y places).
DaveEvans:
You could try changing the timeout for pulseIn from the default (one second) to something shorter and more appropriate for your project, so it doesn't block as long waiting for an echo. Or use the timer-based method in the NewPing library. And/or design a more robust serial communication system.
The new ping library works perfectly, I combined that with some basic filtering and it works great!