A modern, rapid and simple investigation of Ampère’s law

Classical physics results are often taught purely from the theoretical side. Key results, especially in electromagnetism, are typically not explored experimentally, and in applications students are then expected to leap straight into more complex scenarios that make use of these principles in electronics, sensors and instrumentation. This is unfortunate because not all individuals are equally able to learn well purely from the mathematical angle, and even those who do are not exposed to exploring the magnitude of competing effects, for example isolating a particular magnetic field signal from the background of the Earth’s field. An experiment is presented here to test Ampère’s law with a setup that can be assembled out of everyday materials with minimal components—a smartphone, a DC power supply, wires—in a procedure that can be completed in just a few hours. The data from the three magnetic field sensors of the phones, together with the gyroscope sensors providing position, are recorded and numerically integrated. The experiment is also demonstrated using sensors collected by an Arduino board instead of a smartphone. The experiment allows to measure the net current carried by wires inside the closed path over which the magnetic field is integrated, i.e. Ampère’s law. This experimental approach to exploring Ampère’s Law can be adapted towards high school or university demonstrations, depending on the level of accuracy and detail that one aims to pursue.


Introduction
What we know today as 'Ampère's law' arises from the work of Maxwell, Ampère and others in the mid 19th century, and states that the circulation of the magnetic field B along any closed path Γ is equal to the algebraic sum of all the currents I i passing through a surface whose contour is Γ, times the magnetic permittivity µ 0 .It can be written as: Students often are presented with this result at the end of high school or in the first year of university science degrees.It is a common experience, among teachers, that students often have difficulties in understanding and applying Ampère's Law correctly.It is not always obvious why a given concept or law appears to be difficult to understand.A few studies [1,2] have tried to identify these difficulties with Ampère's Law.In particular, [3] finds evidence that students do not think of the integral ¸B • ds as representing a sum along a path.
After a comparative study [4] of the students' difficulties in understanding Ampère's and Gauss Laws, the authors suggest that including 'active learning activities where the students have the opportunity to reflect on the application of Gauss's and Ampère's laws' is important.
Believing that experiments can provide support to conceptual learning of basic physics [5], we designed an activity aiming at measuring the circulation of the magnetic field produced by a distribution of currents, and to an experimental verification of Ampère's Law.The activity makes use of a smartphone equipped with phyphox [6], an open source App that provides access to the many sensors present in the device, or of an Arduino [7] board connected to a digital magnetometer and gyroscope.Apart from these sensors, the materials needed for the experiment can be easily be found in local stores, and can be purchased for a budget lower than 10 euros.The paper is presented as a step by step description of how to carry out the activity, including simple scripts for data acquisition and analysis [8].

Method
To measure the circulation of B, we measure the three components B x , B y and B z of the field in the reference frame of the sensor, which is moved around the currents in a series of finite, but small, displacements ∆s = (∆x, ∆y, ∆z).
By choosing a circular path Γ, of length L, each elementary contribution to the circulation is simply B || ∆s, where ∆s = L N represents the length of the elementary step along Γ, which is divided in N steps, and B || is the projection of the magnetic field on the direction tangent to Γ.
The way in which the measurement of the circulation is done makes it clear that the integral in equation ( 1) is, in fact, a sum, to which only the component of the B field along the displacement gives a non-null contribution, i.e. ( Moreover ∆s = r∆α = rω∆t, where r is the radius of the circular path Γ, and ∆α is the angular displacement of the sensor along the path in a single step, lasting ∆t, during which it is supposed to move at constant angular velocity ω, such that The angular velocity ω can be measured by means of a gyroscope.The sensor is sensitive to the Earth's magnetic field and other possible sources, too.These need not be uniform over space but need to remain constant on the timescale of the experiment.
The experimental procedure consists, then, in  The experiment is repeated with different values of the current crossing the surface whose border is Γ.

The experimental apparatus
By design, the apparatus has been built out of materials commonly available in local stores.We intend to suggest this activity as a possible 'smart laboratory' practical that should be possible even at home.
For the measurement of Ampère's law, we need to displace the sensor around a current distribution; the result is expected to be insensitive to their precise location, and insensitive to the speed of motion along the path.The apparatus has been built using two polystyrene discs as supports, connected axially by a cardboard tube from paper towel rolls.Such polystyrene discs are used for the preparation of cakes, pizza, and other circular shaped foods, and can be found in kitchenware stores (see figure 1).We found these convenient as they are easily cut and shaped, but they could be replaced by cardboard or other supports such as circular shaped cake boxes.
The upper disc can rotate around the central tube, whose diameter has been measured to be ϕ = 4.50 ± 0.03 cm.The three upside-down plastic cups visible in figure 1 are taped to the bottom disk and serve as supports.Marks have been drawn on the side of the upper disc, at a few important angles, to guide the experimenter.Two sticks protruding from the top surface of the disk, near the edge, help to push it so that it rotates relatively smoothly.Of note, it is not important to maintain a constant angular velocity, and neither is it important to achieve exactly one turn, since the position data corresponding to each magnetic field value are obtained from the gyroscope sensors.The central tube is needed to let currents go throughout the surface defined by Γ.
A window has been opened on its lateral surface, through which it is possible to pass one or more times a wire, emerging from the top, as shown in the schematic of figure 1.
The current to the wire is provided by a common smartphone charger power supply, capable of delivering up to 2 A. In order to limit the circulating current, the necessary resistance was provided by the bulb for the headlights of a car.Given that the voltage of the power supply is V = 5 V, in order to have I = 1 A, an incandescent bulb of is needed (common values are 21 W and 24 W).
As an alternative, one can use resistors (as we did when we broke the bulb, that fell on the floor during one of the experiments).In this case, it is important to pick resistors with enough power rating to avoid burning them.We used a ceramic 7 Ω resistor.We measured the current using a multimeter as a cross check, and found i = 0.71 ± 0.01 A, consistent with the expectations from Ohm's Law.Looping three times as in figure 1 the current enclosed within the path Γ is thus Either a smartphone or an Arduino board with magnetic and gyroscopic sensors can be accommodated on the upper disc, which, then, can be rotated manually, acting on the sticks, to make at least one complete turn.The smartphones used here are a Google Pixel 4a (x) and Asus ZenFone Pro Max M2 (y).
The magnetic sensors in the current generation of smartphones have been characterised extensively by others.For example Odenwald has shown that they have a sensitivity of around ±150 nT, but exhibit a variety of systematic effects including apparently uncontrollable glitches and 'dc' baseline changes that have amplitudes of ±2000 nT during long-term measurement operations [9].These glitches and changes are fortunately fairly sparse, and baseline offsets can be compensated for, as we show later.Note smartphones have already been used in the teaching lab, for example to probe the fields from coils in Helmholtz and anti-Helmholtz configurations [10].
Using the Arduino external sensor, whose form factor is rather small, it is possible to align quite precisely the axes of the device to the direction of the displacement.

Measurements with smartphones
We made a first test using smartphones with a magnetometer and a gyroscope.The latter is used to measure the displacement of the point on the path Γ.
To acquire datasets more efficiently, but also to verify consistency between different phones, we took measurements using two smartphones at the same time, labelled x and y as above.
Both phones used phyphox in the configuration in which it collects data from both the magnetometer and the gyroscope (the socalled simple experiment).With this configuration, phyphox collects data continuously, until it is stopped, while the upper disc is continuously rotated (though not really matters, we tried to keep the angular velocity as constant as possible).

Geometry of the experiment with smartphones
Figure 2 shows the positioning of the smartphone on the upper rotating disc, with the indication of the relevant quotes.The magnetic field sensor is represented as a black dot in the top left corner of the smartphone.Its position inside the smartphone is not known, and is indicated by r.When the disc rotates, it follows a trajectory marked as the dashed arc in figure 2. In the figure, α is the rotation angle of the disc with respect to an arbitrary axis taken as the origin, while θ is the angle between the direction of the sensor's velocity v and the smartphone's y-axis.
We used two configurations: in configuration A, the bottom right corner of the smartphone touches the circumference; in configuration B (shown in the figure) the smartphone touches the circumference with the top right corner.This gives two well defined and easy to reproduce conditions of orientation and radius r.
Measurements made with a smartphone are expressed in a reference frame shown in figure 3. To locate the sensor as precisely as possible within the smartphone body, we measured the component of the magnetic field perpendicular to the phone's display, keeping the phone aligned with a long wire in which a known current I = 3.0 ± 0.1 A was flowing, for a range of distances  from the wire, exploiting the Biot-Savart Law, according to which By measuring B as a function of R we were able to determine the distances of the sensor from the left and top sides of each smartphone.This procedure is described in detail in the 'Biot-Savart's Law' experiment on SmartPhysicsLab [5].Therefore, we obtained the distances of the sensor from the axis of rotation with the help of figure 4.

Calibration of sensors
Before starting the measurements, both phones were calibrated performing the classical ∞shaped figure.The result for local field was still different for the two phones: While the x-phone consistently reported an average value of |B| ≃ 46 ± 1 µT, the y one were fluctuating between 29 and 35 µT.The NOAA website [11] gives an average field of |B| = 46.8µT in our location.We assumed that these differences could be treated as an offset, and collected data.Magnetic field and angular velocity data were collected while rotating the system over more than a complete circle.

Analysing smartphone data
Data is saved by the phyphox app as a text file with columns for time, magnetic field components and gyroscope components (all with physical units).Firstly, neglecting the possible misalignment, it is possible to recover the angle at which the system has rotated at time t from the gyroscope data, integrating the angular velocity ω (in practice, we integrate just its z-component, since the smartphones rotate around an axis perpendicular to their displays): Here, ω i is the angular velocity as measured by the gyroscope at timestep i, and ∆t i is the time interval between two successive measurements ∆t i = t i − t i−1 .N is the number of measurements during one turn, which actually is large: N ≃ 1 500, allowing for a precise estimation of α(t).
Knowing the angles, we could then select the portion of data in the time interval [t i , t f ] such that α(t i ) = α min and α(t f ) = α min + 2π, i.e. a precise full circle for the sensor.α min can be chosen arbitrarily, and we fixed it at α min = 0.05.Separately, we checked that this integration of the angular velocity from the gyroscope values was as accurate as the degree to which we could make an exact single rotation with our setup, and independent of how uniformly we carried out the turn.
Figure 2 shows that the displacement of the sensor makes an angle θ with the y-axis of the phone.The elementary contribution to the circulation is therefore For convenience, we define the pseudocirculation C such that This quantity is convenient, because it is independent on the particular geometry of the experiment (θ and r), and calculable directly from the raw data provided by the instruments.
Figure 5 shows, respectively, the values of ω and α as a function of time, and those of B y and C as a function of angle, in an experiment in which I = 0.
Table 1 shows the values of the pseudocirculations (a quantity defined in equation ( 8)) measured in different experiments, integrated over a complete turn of the smartphones.Each run comprises two measurements, and the corresponding data is presented in two rows of the table: one with I = 0 and one with I ̸ = 0.The first two runs were used to derive a rough estimation of the accuracy and precision of the instruments.The third runs has been taken with a different configuration (see above), while the fourth run has been taken with a different current I = 3 × 0.37 ≃ 1.11 A.
Using the first row of each run we get C i at I = 0, which is expected to be null, and is thus subtracted to C i in the second row, to take into account the (possibly large) inaccuracy of smartphones' sensors.In the table, we show both the raw pseudo-circulation C i and the net pseudocirculation In fact, C 1 is much smaller than C 2 ; correspondingly, the differences between the measured and predicted magnetic field intensity of the Earth is small in the first case, and rather large in the second.

Accuracy and precision of smartphones' data
Assuming that ¸B • ds = 0, when I = 0, sets the order of magnitude of the accuracy of the magnetometers, while the fluctuations between the various measurements in the same conditions sets their precision.
From the rows of table 1 with I = 0, the accuracy of the smartphone x has been estimated to be 4 µT rad, while the one of the smartphone y is about 35 µT rad.The precision, estimated as the standard deviation of the pseudo-circulations measured in the experiments with I = 0, is thus of the order of 0.6 and 2 µT rad, respectively.
There is no attempt here to make a large data collection nor a rigorous statistical analysis of data, since the aim of this report is to show that it is possible to measure the circulation of the magnetic field with enough precision to test the validity of the Ampère's Law, however it is possible to make a few considerations.Firstly, the number of data collected during each experiment set is about N = 1500.The uncertainty on pseudocirculation is Neglecting the uncertainty on ω and ∆t, one can estimate an upper limit for the relative uncertainty on the measurement of B, which is for x and 0.05 for y.
As a cross check, we compared the fluctuations of the magnetic field as measured with the smartphone at rest, illustrated in section 3.2.We found for x, which is consistent with the σ B estimated above.Similarly, for y, we found |B| = 32 ± 2 µT, also consistent with the above estimation of σB B .

Results with smartphones
Given the pseudo-circulation y ω i ∆t, the circulation is given by just multiplying the latter by the geometrical factor r cos θ .The distance r i and cos θ, are obtained as shown in figure 4. Table 2 shows the value of r i and cos θ found in the two configurations, for the two smartphones.
From data in table 1 one can compute the circulations in the various configurations as Results are shown in table 3, where the predicted circulations are computed as µ 0 I. Table 3 also shows C avg computed as the average of the circulation obtained with phone x and that with phone y.The uncertainty of C avg has been estimated as the difference between the two measurements divided by √ 12, and is consistent with that predicted from the relative uncertainties of C NET i , r i and cos θ i .The two determinations of the circulation with I = 2.13 A in configuration A are consistent with each other within 2 standard deviations.In fact, the circulation is predicted to be insensitive to the configuration, depending only on the currents enclosed in the path.From the third row in table 3 one can see that the circulation in configuration B is consistent with that in configuration A.
The mean value of the circulations measured for I = 2.13 A, irrespective of the configuration, is 3.0 ± 0.2 µTm, to be compared with the predicted value 2.68 ± 0.04 µTm.They agree within 1.6 standard deviations.Also the value of the circulation for I = 1.11A agrees with the expectations by 2 standard deviations.
Being C = µ 0 I, the ratio between the circulations measured with different currents, is expected to be equal to the ratio of the currents: 1.92 ± 0.06.Experimental results agree with the expectations within less than two standard deviations, being 2.5 ± 0.3.The main results are summarised in table 4.
The fact that the ratio between the measured circulations does not agree better with expectations, with respect to their absolute values suggests that there are, indeed, some systematics that do not cancel in the ratio.We ascribe most of the systematics to the inaccuracies of the smartphones' sensors.In particular, phone y exhibits large fluctuations and a non-negligible offset.Using phone x only, results for I = 2.13 A (those for which the uncertainty is small enough) agree much better.In fact, the average circulation measured using phone x is C avg 1 = 2.6 ± 0.3 µT rad, which agree with the predicted one within 0.3 standard deviations.
Results show that a proper calibration of the magnetic sensor must be assessed in order to obtain results in agreement with the expectations.However, despite phone y exhibited a large inaccuracy and a poor precision, the final figures are Table Summary of the results obtained with smartphones.The current in given in A, the expected value of the circulation C = µ 0 I and its experimental determination Cavg are given in µTm.t is the distance between the latter in units of standard deviations: , σ i being the uncertainties on the predicted and measured circulations.meaningful and agree with expectations within two standard deviations.The activity, therefore, can also be significant for an in-depth discussion of the roles of systematic and statistical uncertainties in the measurement of a physical quantity, and how to asses them.

Measurements with Arduino
The experiment was repeated using an Arduino board interfaced to an HMC5883 magnetic field sensor, and an MPU6050 gyroscope.With this setup it is easy to align the HMC5883 such that, as the disk rotates, the sensor moves along the direction of one of its axes.In this case, therefore, the geometry is much simpler: the sensor can be easily located on the board, and its axes can be precisely aligned with v, such that θ = 0. On the other hand, data collection is more complex, because it involves Arduino programming and interfacing with sensors.Data were analysed in the same way as described for the phone setup: first we computed the pseudo-circulation C, then we obtained C as rC, r being the distance of the sensor from the axis of rotation.
In this case, we measured the pseudocirculation for I = 0, I = 2.13 ± 0.03 A, and I = 1.05 ± 0.03 A. For each measurement, we took two runs.The central value of the pseudocirculation is taken to be the average of those measured in the two runs, while the uncertainty has been estimated as Data are summarised in table 5.
The Arduino sensor inaccuracy, estimated from the measurement at I = 0, is similar to that of a good smartphone's sensor, while the precision is rather good, and measurements are reproducible.

Results with Arduino
Once r ≃ 4.4 ± 0.3 cm is known, the evaluation of the circulation is straightforward: C = rC.Taking C from the last column of table 5, we find that, for I = 2.13 A, to be compared with the predicted value (2.68 ± 0.04) × 10 −6 Tm, which is more than three standard deviations apart.From this figure one can estimate the value of to be compared with the expected value µ 0 = 4π × 10 −7 ≃ 1.3 × 10 −6 H m −1 .Though large, the discrepancy can well be explained by the limited statistics, as well as by the roughness of the setup.
At least part of the discrepancy can also be ascribed to the limited precision and accuracy of the cheap sensors used in these experiments.If present, some systematics cancel in the ratio of the circulations measured with different currents, which is expected to be equal to the ratio of the currents:  consistent with expectations within less than two standard deviations.Again, the fact that in the ratio uncertainties do not cancel means that at least part of them have to be ascribed to the inaccuracy.
It is worth noting that our experiments were designed such that they could be easily reproduced in an educational environment, and do not pretend to be neither precise, nor accurate.We deliberately made the experiments without much dedication to the suppression of systematic uncertainties, to evaluate the level of precision that can be reached with a cheap, quick-and-dirty apparatus.

Suggested educational activities
Given the results of the previous sections, we suggest a possible activity to be conducted in a class or at home, for students.
After building the rotating support, and having connected a power supply to the wire, they can take a measurement of the pseudo-circulation with and without current, for at least two values of current.
The measurement can be repeated with different distances of the detector from the axis of rotation.Using a smartphone, the sensor can be located by measuring the z-component of the magnetic field generated by a straight current at various distances (it is worth noting that this also offers the opportunity to explore the Biot-Savart Law from the experimental point of view).Knowing the sensor's location, it is possible to compute the circulation in the various configurations.
Observations are likely to show the following: • the circulation of the magnetic field is, as a matter of fact, a sum of scalars, each obtained as the projection of the magnetic field onto the path Γ, weighted for the length of Γ. • In performing experiments, it is often useful to define quantities proportional (or otherwise closely related) to those of interest, that are easy to evaluate from the raw data, without detailed data analysis, in order to allow direct and immediate observations.For this purpose we define the pseudo-circulation y ω i ∆t i (explained further at equation ( 8)).
• The pseudo-circulation taken at I = 0 is always small.If it is not consistent with zero, as expected, it means that the sensor exhibit systematic errors that can, however, be taken into account in the following.A possible inaccuracy of the sensor can be revealed comparing the measurement of the intensity of the magnetic field as measured by the device with the one given by the NOAA website.• The ratio between pseudo-circulations, corrected, if needed, for the non-zero result above, is consistent with the ratio of the currents in the various configurations, if the sensor's inaccuracy is low enough.• The circulation is independent on the distance of the sensor from the currents.It only depends on the currents enclosed by the path.• The values of the circulations can be compared with the expected values µ 0 I. • A measurement of µ 0 is made possible, if the current is known, or, vice versa, one can measure I taking for µ 0 its value µ 0 = 4π × 10 −7 in SI units.• The circulation is independent on the geometrical configuration.
Our experience suggests that the magnetometers in smartphones can be largely inaccurate.However, the inaccuracy often results in a constant offset the value of the measured magnetic field, which mostly cancels when computing the pseudo-circulations and circulations as suggested above.However, it is important to assess the inaccuracy of the sensors by taking a measurement of the magnetic field in static conditions.Despite large differences in the sensitivity and accuracy of the sensors, results are comparable across devices and with theoretical expectations, even if with large The effects are large enough to show that the Ampère's Law predictions are satisfied without the need to perform a very detailed error analysis.On the other hand, repeating the measurement a number of times, and in different conditions, would allow students to appreciate the power of statistical data analysis, and offer an opportunity to discuss the role of statistical and systematic uncertainties.

Discussion
We have presented a simple experiment that is accessible for high school or university students.The aims were firstly to show that Ampère's Law can be verified convincingly using a simple experimental setup, with either the sensors in a smartphone or sensors with an Arduino board.Secondly, to encourage students to test the conditions and validity of Ampère's Law, and gain a feel for the strength of the field generated by a known current, versus other fields present in a typical environment.Thirdly, to promote a familiarity with modern forms of data structures and interpolation using Python.
The results of our own exploration are very positive with respect to those three aims: A cheap setup is described, allowing to move a magnetic sensor in a closed loop, and to recover its position at every timestep using the simultaneous measurement from a gyroscope-both these sensors are present in most smartphones and are cheap components that can be connected to an Arduino board.We have then tested Ampère's Law by showing proportionality of the integrated field to the current in the wire, and showing the details of the closed path taken by the sensor and the speed of movement do not matter.Following various calibration steps, we get quantitative agreement with the theoretical result.The data acquisition in smartphones is handled by the very useful open app phyphox; on the Arduino it is handled by a Python script.Python scripts have been developed and are released here to carry out the integrations, averages and interpolations described in the data analysis.
The computation of the experimentally measured circulation makes it clear that ¸B • ds is nothing but a sum of the component of the magnetic field tangent to the path, addressing the issues described in [3].
Overall we think this experiment can be useful in a variety of ways-from the relatively simple demonstration at the level of detail and analysis followed here, or using the ideas here as the beginning of more sophisticated explorations for example of the sensors or of the statistics of data.

Figure 1 .
Figure 1.A very cheap, easy to assemble and simple setup is sufficient to carry out the experiment.Schematic drawing (left) of the apparatus in cross section, and photo (right) of the apparatus used to measure the circulation of the magnetic field.The top polystyrene disk is free to rotate and supports the sensors.In this figure, three loops of wire are shown; we discuss in the paper that this is one of the parameters that can be easily varied.

Figure 2 .
Figure 2. Schematic of the top (rotating) disk, showing the geometry of the system used to take measurements with smartphones and variables as used in the main text.A fairly accurate knowledge of the phone's orientation and radial position, and of the position of the magnetic field sensor within the phone, are required for a quantitative measurement of values of the current.

Figure 3 .
Figure 3.The coordinate system in the smartphone reference frame.

Figure 4 .
Figure 4. Once the distances of the sensor from the left and top sides of the phone are known, its location with respect to the axis of rotation can be obtained by measuring the distance D and the diameter of the tube.

Figure 5 .
Figure5.sensors are remarkably precise for angular velocity and magnetic field strength.Left: Despite some uneven rotation, visible in the angular velocity, the angular position is recovered accurately as a function of time, using the smartphone's gyroscope.Right: In the absence of a current in the wire, the component of the magnetic field, measured using the smartphone's magnetometer, and its pseudo-circulation C (see equation (8) for definition), can then be plotted along the displacement of smartphone.These are individual traces of data obtained from phone 1. Units on the vertical axes are given in the legend of the plots.
Collect the measured values of B x , B y and B z from which to obtain B 1. Moving a magnetic field sensor and a gyroscope such that it describes a circular path Γ of radius r (L = 2π r); 2.

Table Pseudo -
circulations (see equation (8)) measured in different experiments, after a complete turn of the smartphone.Currents are expressed in A, while pseudo-circulations in µT rad.

Table 2 .
distances r i , and the cosine of the angles θ i in the two configurations.Distances are expressed in cm.The circulation of the magnetic field measured in the various experiments.The circulation is given in µT m; current in A. Cavg is the average between the smartphones.

Table 5 .
measured in different experiments with Arduino, after a complete turn of the device.Currents are expressed in A, while pseudo-circulations in µT rad.