When you want to detect the Yaw of a robot, you want to use an IMU.
An IMU is an Inertial Measurement Unit. A standard IMU consists of an accelerometer, gyroscope, and magnetometer, each with 3 degrees of measurement (XYZ). A standard IMU contains these 3 sensors, together, such that the combined sensor data can be fused together to create an accurate estimate of the RPY (Roll Pitch Yaw) of the robot's frame.
Now, why does this matter?
Well, in your question, you are asking to find the robot's Yaw from only the accelerometer. This is generally bad practice because you can only measure the second derivative of linear position, whereas Yaw is (0th derivative? - bad notation) the original, non-differentiated function, which is a measurement of orientation, not translation. This means that, in summary, you cannot measure Yaw with an accelerometer.
TL;DR => You don't
@holmeski is correct