Maze solving tank with ultrasonic sensors too close to wall and zig zags

Hi I have been tasked with building and coding an autonomous tank maze solver, I have no previous coding experience so have been having to constantly research each part of my code. I have the tank functioning the sensors work and the tank responds as expected in each scenario (to a certain degree). My problems are that it doesn’t matter what distance I set the parameters at within my code my tank stays about 2cm from the wall, also when moving I can’t get it to run in a straight line, it basically zig zags. Any suggestions of how to remedy my problems would be greatly appreciated, thank you.

My code (apologies for the formatting I know its horrendous)

final_tank_solver_test.ino (10.2 KB)

The ultrasonic sensors I've dealt with can't measure a distance like 2cm. There's a minimum that makes it hard to use for wall detection that can be many times greater. Also, you're checking multiple sensors in rapid succession, which gives a risk of echoes from the prior one impacting the one you're reading now.

Do you have simpler code that verifies that your sensors are giving you good data?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I understand that you code will not go between code tags due to size, so thanks for attaching it.

As @wildbill has suggested, do you have code that you wrote during development to JUST prove the operation and response of the ultrasonics?
Can I suggest you use the NewPing library to simplify your ultrasonic measurements.

How wide is the maze and what are the dimensions of the tank?

Tom... :slight_smile: