Arduino Duemilanove and Hmc5883l

The problem is, your x axis is always 0, so atan2(0, y) will always return PI/2 or -PI/2. The rest is correction function. Is it possible that you mounted your sensor so that the x axis is always 0 and the movement axis are y and z? If so, you have to change your code:

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2( scaled.ZAxis,scaled.YAxis);

It's possible that you have to swap the two axis again depending on your mount position.

already ? use z and y axis thank you so much . but ? wonder why x axis usually 0 ?

As far as I know you're using the sensor on a robot. Robots usually are rolling around on a flat surface (horizontally), which means in one plane. One axis isn't used and stays on the same value. A value of zero shows that your mount seems to be quite exact (assuming the sensor is working correctly).