# Open-Source Magnetometer for Characterizing Magnetic Fields in Ultracold Experiments
## 2 General Considerations
### Field Measurement with Internal Offset Cancellation  
Nowadays, many magnetic field sensors are available for do-it-yourself projects, in particular as peripherals for Arduino and the like. Very commonly encountered technology is based on the Hall effect. The magnetic fields detected by such sensors are prone to temperature drifts because of an internal offset field inherent to the device. Some sensor models like MEMSIC MMC5983 MA [20] used in our design have a mechanism that effectively flips the magnetic sensing polarity of the sensing element. A simplified procedure determines the sensor's response to the external magnetic field by performing measurements for two polarizations of the sensor, \(\vec{B}_{\text{pol}+}=\vec{B}+\vec{B}_{\text{offset}}\) and \(\vec{B}_{\text{pol}-}=-\vec{B}+\vec{B}_{\text{offset}}\)[20]. As a result, from the above equations, one can obtain both the external field and the offset. The external field \(\vec{B}\) could be just stray magnetic field already present at the measurement location, usually Earth's magnetic field. To measure the field from a source, \(\vec{B}_{\text{source}}\), one needs to remember that the sensor's readout \(\vec{B}_{\text{sensor}}\) is composed of three fields (as already defined in this section), \(\vec{B}_{\text{sensor}}=\vec{B}_{\text{source}}+\vec{B}_{\text{stray}}+\vec{B}_{ \text{offset}}\). We can utilize polarization flipping feature to extract all needed fields with the following procedure:  
1. without the magnetic field source, measure the sensor's response at each location \(y_{i}\) along the planned measurement path for two polarizations of the sensor, \(\vec{B}_{\text{ns},+}^{i}=\vec{B}_{\text{stray}}^{i}+\vec{B}_{\text{offset}}^{i}\) and \(\vec{B}_{\text{ns},-}^{i}=-\vec{B}_{\text{stray}}^{i}+\vec{B}_{\text{offset}}^{i}\). 2. place the magnetic field source and repeat the measurement for the same locations \(y_{i}\) as before, for two polarizations of the sensor, \(\vec{B}_{\text{ws},+}^{i}=\vec{B}_{\text{source}}^{i}+\vec{B}_{\text{stray}}^{ i}+\vec{B}_{\text{offset}}^{i}\) and \(\vec{B}_{\text{ws},-}^{i}=-(\vec{B}_{\text{source}}^{i}+\vec{B}_{\text{stray}}^{ i})+\vec{B}_{\text{offset}}^{i}\),  
where \(\vec{B}_{\text{ns}/\text{ns},+/-}^{i}\) are sensor readouts with no source (ns) and with the source present (ws) for two polarities (\(+/-\)). In principle, the values marked with the prime symbol are not the same as the ones without the prime symbol because they are obtained many seconds apart. We assume here, however, that the stray fields are static on the time scale of the measurement and we do not distinguish between the two. We do not make this assumption about the offset field as this can be influenced by the fields the sensor has been exposed to. We have observed such variation in the sensor offset (see Section 4); therefore, the measurement of both \(\vec{B}_{\text{ws},+}^{i}\) and \(\vec{B}_{\text{ws},-}^{i}\) is necessary to reliably extract the field characterizing the source, the environment and the sensor:  
\[\vec{B}_{\text{source}}^{i} = \frac{\vec{B}_{\text{ws},+}^{i}-\vec{B}_{\text{ws},-}^{i}-\vec{ B}_{\text{ns},+}^{i}+\vec{B}_{\text{ns},-}^{i}}{2}, \tag{4a}\] \[\vec{B}_{\text{stray}}^{i} = \frac{\vec{B}_{\text{ns},+}^{i}-\vec{B}_{\text{ns},-}^{i}}{2},\] (4b) \[\vec{B}_{\text{offset}}^{i} = \frac{\vec{B}_{\text{ws},+}^{i}+\vec{B}_{\text{ws},-}^{i}}{2},\] (4c) \[\vec{B}_{\text{offset}}^{i} = \frac{\vec{B}_{\text{ns},+}^{i}+\vec{B}_{\text{ns},-}^{i}}{2}. \tag{4d}\]  
When dealing with coils, we can improve upon the procedure discussed above. This comes from the possibility of turning off the current and thus obtaining the stray field value within tens of milliseconds from the readout of the magnetic field when the coils are on. The overall procedure is very similar to the case of permanent magnets, and we use the same naming convention for the fields.