Hi,
I am doing a Arduino Robot car ref. to:
https://youtu.be/4CFO0MiSlM8
my question is how to measure and control the Avoidance car's turn angle when the Ultrasonic sensor detected an Obstacle?
I don't think the HMC5883L kind of compass or even GPS module can work if in-room.
Thanks
Adam
Why do you think a compass (that uses magnetic field of the Earth) wouldn't work indoors? Of course it would.
However, getting a magnetometer calibrated and compensating for all kinds of errors that could occur (e.g. from pieces of metal nearby) is a highly non-trivial task. Moreover, magnetometer alone is not suitable for measuring the orientation/turning rate of a vehicle. For that you need a gyroscope or, ideally, a full IMU system including a gyro that actually does the measurement your control system uses, magnetometer for compensating the gyro's drift in the yaw axis and an accelerometer for compensating drift in roll/pitch axes. Magnetometer and accelerometers are rarely used for this kind of job directly because they are noisy sensors, prone to picking up a lot of error caused e.g. by movement of the vehicle (accelerometer) or surrounding environment (magnetometer).
Now whether or not you need such closed loop control where you actually measure the turning rate like this instead of just going with the assumption Marco mentioned depends on your needs. For your toy robot a full IMU would be a massive overkill because you don't really care about the
exact amount the robot has turned (but it likely would be a very good learning experience).
Concerning a GPS module - that wouldn't work indoors, indeed. However, even if it did (or you used it outdoors), GPS is not suitable for tracking small and rapid position changes. Even the best GPS modules have accuracy in meters (+-3m being typical) and slow update rate (1Hz being typical). That's OK for navigating a car or flying a drone into the general vicinity of some waypoint but not for what you want to do.