I am trying to program a simple obstacle avoidance robot with a stationary ultrasonic sensor(will add more) and two motors. I am using the NewPing.h library for ease of use, but the ultrasonic sensor is giving back a 0cm value randomly, with my simple code, it calls the wrong command. Is there a resource that I can use as a reference for doing something this simple? Most robots use a servo attached to the ultrasonic sensor, which I can not do for many reasons. If you want to look at the mess that is my code, I have attached it. Should I use the “no library” approach so then I can do a constrain() or am I doing something wrong?
Test_1.ino (1.8 KB)