  The spatial dependence of magnetic fields in simple configurations is an
usual topic in introductory electromagnetism lessons, both in high school and
in university courses. In typical experiments, magnetic fields are obtained
taking point-by-point values using a Hall sensor and distances are measured
using a ruler. Here, we show how to take advantage of the smartphone
capabilities to get simultaneous measures with the built-in accelerometer and
magnetometer and to obtain the spatial dependence of magnetic fields. We
consider a simple set up consisting of a smartphone mounted on a track whose
direction coincides with the axis of a coil. While the smartphone is smoothly
accelerated, both the magnetic field and the distance from the center of the
coil (integrated numerically from the acceleration values) are simultaneously
obtained. This methodology can be easily extended to more complicated setups.
