A low-cost Arduino microcontroller for measuring magnetic fields in a solenoid

This work aims to introduce a low-cost experimental set up using an Arduino board for studying the magnetic induction concept. We use a Hall Effect sensor to detect the magnetic fields inside a long solenoid applied the DC current. The results revealed that for the DC current varied from 20 to 160 mA, the Arduino sensor processed the magnetic fields in a range of 0.77 to 5.27 mT. Collected data between the currents and the magnetic fields were straight plotted with R2 = 0.99. We applied the Ampere’s law to estimate the amount of coil turn used as 1,016 rounds, with 1.6% error. This apparatus is inexpensive, easy to build and obviously demonstrates Physics variables on the Arduino board. The experiment, along with the discussion of the electricity and magnetism, will be of benefit to students in Physics class.


Introduction
Teaching and learning materials integrated with a proper instructional approach can support student learning and increase student success. Such materials are significantly important in both Physics lecture classes and laboratories for promoting students to comprehend properties of matter and natural phenomena. However, an equipment required for real-time data acquisition is often high-priced and its maintenance must be done by specialized technicians [1,2]. A study to develop instructional instruments based on low-cost materials exists and become more popular.
Nowadays, there is a rapid growth of electronic technologies and microcontroller-based named Arduino, which a large number of sensors can be attached to measure several physical parameters such as distance, time, force, voltage, current, resistance, magnetic fields, and so on [3,4]. An Arduino is an open-source electronics platform that allows to monitor and control different analog-digital signals. Arduino microcontroller can be combined with sensors and other more powerful data processing equipment to obtain the optimal configuration [5]. Arduino board and its utilization in Physics education research have been reported as cheap devices and accuracy data processing in many works, for example, developing an Arduino-based project to investigate the simple harmonic motion of a mass on a spring [6], using the Arduino and its computer interface to examine the characteristic of photovoltaic cells [7], applying to a measurement of magnetic flux densities [8].
In this paper, we present the applications of Arduino board and its sensor in an electromagnetic experiment by using the Ampere's Law to investigate the magnetic fields inside a solenoid. The magnetic fields can be detected by the Hall Effect sensor when the DC currents are applied to the solenoid by a variable DC power supply. Its data are processed by Arduino board and shown on the LCD displays. The relationship between the magnetic fields and the DC currents applied to a solenoid can be monitored. In addition, a number of turn in the coil used can also be investigated.

Apparatus and method 2.1. Arduino board
Arduino (UNO) is a microcontroller board based on the ATmega328P. It consists of 14 digital input/output pins (6 of them can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. It contains necessary components to support the microcontroller and is easy to connect to a computer via a USB cable or power it with an AC to DC adapter (or battery) to start. The Arduino (UNO) can be programmed with the Arduino Software (IDE).

Hall Effect sensor
A linear Hall Effect sensor is a small versatile transistor device, which its dimension is 3.00 × 4.00 mm 2 as shown in figure 1(a). It is operated by the magnetic fields from a permanent magnet or an electromagnet. The linear source output voltage is set up by the supply voltage and varied in the proportion of the strength of the magnetic fields. The linear Hall Effect sensor operates voltage 3 to 6 DCV, and associates with the strength of the magnetic fields -150 to 150 mT with sensitivity is 18 mV/mT.

Solenoid coil and experimental setup
One thousand turns of a solenoid copper coil in the air core are used in this experiment, the length of the solenoid is 3.840 ± 0.005 cm, and its diameter is 5.910 ± 0.005 cm. The inside diameter of the solenoid (air core) is 2.120 ± 0.005 cm, as shown in figure 1(b). The magnetic fields inside the solenoid are estimated by the Ampere's law as shown in equations (1) and (2): so the magnetic fields inside the solenoid as: where I is the DC current inside the solenoid, N is a number of the coil turn, L is a length of the solenoid and µ 0 is a magnetic permeability, respectively. As shown in figure 1(c), the experimental setup comprises the DC current, varied from 20 to 160 mA, which generated by DC power supply through 100 Ohms resistor and applied into a solenoid coil, in order to vary the magnetic fields inside the solenoid. The magnetic fields were detected from the linear Hall sensor by locating the sensor at the center edge of the solenoid coil diameter or inside the solenoid as shown in figure 2(a). In addition, the Hall sensor is able to be applied for measuring the fringe field of the solenoid. For Vcc (Supply voltage), GND (Ground) and Data (Signals) of the Hall sensor, which were connected with 5V, GND and A3 (Analog input channel 3) of Arduino board, respectively. The Arduino board reads the raw voltage of analog input channel 3 received from the linear Hall Effect sensor. The voltage data were calculated and converted to the magnetic field values. The flow chart was shown in figure 2(b). The control sequence was programmed with the Arduino Software (IDE) and displayed the results via the LCD monitor.

Results and discussion
Experimental results were shown in figure 3. We applied DC currents in a range of 20 to 160 mA (± 1 mA) and obtained the magnitude of magnetic fields in a range of 0.77 to 5.27 mT (± 0.01 mT). The theoretical magnetic fields inside the used solenoid, which obtain from equation (2) when considering DC currents at 160 mA, is 5.24 mT. It displays about 0.6% difference between the experimental and theoretical magnitudes of the magnetic fields. This indicates a high accuracy for measuring the magnetic fields inside a solenoid of this low-cost experimental set up using an Arduino board. Moreover, the increasing of magnetic field values when the applied current increases were linearly plotted and explained by equation (2). In this experiment, we simply obtained a linear relationship between the magnetic field (B) and the applied current (I) as B = 33.24I mT with R 2 = 0.99. A number of the coil turn was calculated from the slope of the B-I graph and found as 1,016 turns. It is approximate 1.6% error of the data calculation since there are 1,000 actual turns of the coil used. This may effect from the self-induction of the sensor, and the noise in measuring the magnetic fields at different regions.

Conclusion
This paper suggests an application of the Arduino board and its Hall Effect sensor to investigate the magnetic fields inside a solenoid. It real-time displays the data via the LCD screen with a few percent errors. Moreover, it is low-cost components and easy to design. Physics teachers can develop as teaching and learning materials to support students to learn about the electricity and magnetism, in particular, the Ampere's law. It can be a beneficial optional apparatus for Physics lecture classes and laboratories in both high schools and university levels.