How to measure and control the robot car turning angle when avoidance?

Hi,
I am doing a GPS toy car following the project online:

when a HC-SR04 detected a obstacle, the Arduino controlled the car turn a angle to avoidance.
my question is how to decide the turning angle is good? are there any angle sensor to do feedback or use Encoder?
right now it is used the delay time to control the car turning which some time too less, some time too much.
Thanks for help.
Adam

@lladam Welcome to the RobotShop Community. Normally encoders work provided the robot’s wheels don’t lose traction. Magnetic compasses however are ideal and give you an angle based on the earth’s magnetic field (like a real compass) which gives an absolute measurement (rather than just something relative to your last position):
https://www.robotshop.com/en/catalogsearch/result/?q=compass&order=relevance&dir=desc

Ex: Tilt Compensated Magnetic Compass (CMPS12) - RobotShop

For a bit more money, get even more sensors included:

Another option can be GY-87
https://www.gmelectronic.com/gy-87-gyroscope-accelerometer-compass-pressure