1 of 34

Unit 5�Magnetism

UCLA Physics Department

University of California, Los Angeles

Department of Physics and Astronomy

Physics 4BL

Fall 2025

2 of 34

Outline of Unit 5

  • Magnetism
    • Magnetic Dipoles: Earth’s Field, Dipole Approximation
    • Ampere’s Law - magnetic field inside a solenoid
    • Force between two magnets (NOT DONE IN WINTER 2026)
    • No Group Report, Individual Postlabs Due Friday, May 8th

  • Python Programming and Arduino
    • Continued application of general equation fitting
    • Advanced arduino sensor modules

UCLA Physics Department

3 of 34

Lab 5A: Magnetic Dipoles- Earth and Ferrite Fields

4 of 34

Magnetic Dipoles

  • Since there are no magnetic point charges, the most “fundamental” field in magnetism is a dipole
  • The magnetic field is
    • proportional to the dipole magnetic moment
    • Field drops off as r^3 and does depend on relative orientation

5 of 34

Magnetization

For a magnetic dipole field, the dipole moment (m) determines the strength of the field. The dipole moment is proportional to the magnetization (M) integrated over total volume.

Our permanent magnets can be assumed to have a constant magnetization (M), yielding:

Due to the orientation of our magnetometer to the dipole axis of our cylindrical magnet the previous magnetic dipole equation simplifies to:

Note mu_0 is the vacuum magnetic permeability

6 of 34

Experimental Setup - Electrical Schematic

Equipment:

  1. ESP 32
  2. GY-511 Magnetic Sensor
  3. Cylindrical Magnet

SCL → 22

SDA → 21

Insert magnetometer into solenoid slit

7 of 34

Using the GY-511 Magnetic Sensor

  1. Before using the GY-511 magnetic sensor, you need to install a library in the Arduino IDE called: LSM303DLH Mag by Adafruit Industries.
    1. Open the Arduino IDE
    2. Go to Tools → Manage Libraries
    3. Search “LSM303DLH Mag”, “Adafruit Unified Sensor”, & “Adafruit BusIO”
    4. Install the latest versions
    5. Once Installed, download this ESP32 code to run the GY-511 Sensor
  2. Compile and upload the Arduino code.
  3. Open Serial Monitor to view magnetic field measurements
    • Tools → Serial Monitor
    • Shortcuts Windows: “ctrl+shift+m” or Mac: “cmd+shift+m”

Correct Output

*If your data stops streaming/the magnetometer is disconnected, you need to re-upload the code before collecting data again*

8 of 34

Earth as a Magnetic Field

Earth’s magnetic field is approximately a magnetic dipole field

Line up your GY-511 sensor so x is facing North or South, y is facing East or West, and z is facing up or down

Collect a few seconds of data and with trigonometry, calculate Earth’s total magnetic field strength and our latitude

9 of 34

Cylindrical Magnet

Make sure the distance from magnet to magnetometer is AT LEAST 5 centimeters away

If not data will be saturated and unusable

Collect at least 5 different datasets at different distances

Maintain the shown fixed magnet orientation

NO CLOSER THAN THIS

10 of 34

Analysis for 5A

Line up x, with North/South, y with East/West and z with up/down

Calculate Earth’s Total Magnetic Field and Our Latitude

Collect 5 Datasets of B vs R for the cylindrical magnet

Measure cylindrical Magnet dimensions

Fit B vs R using equation on slide 5

Assume uniform magnetization, calculate magnetic dipole moment and magnetization of dipole using fit result and magnetization equation on slide 5

11 of 34

Lab 5B: Ampere’s Law - Magnetic Field Inside a Solenoid

12 of 34

Magnetic Fields of Moving Charged Particles

  • The movement of charged particles (particularly electrons in wire), causes a magnetic field to be generated.
  • The magnetic field is
    • proportional to the electric current
    • Inversely proportional to the radial distance from the wire

13 of 34

Magnetic Fields Inside Solenoids

  • In special cases where the charge particles movement is circularly symmetric, we can apply Ampere’s law to derive the magnetic field.

14 of 34

Applying Ampere’s Law

15 of 34

Experimental Setup - Electrical Schematic

Equipment:

  • ESP 32
  • x5 10-Ohm Resistors 1W,�X1 100 Ohm Resistor
    • Make sure this 100 Ohm resistor is the last one in the series, i.e. just before the solenoid
  • Ammeter
  • GY-511 Magnetic Sensor
  • Long Dupont Wires
  • N = 100 Solenoid,�L=? (measure it!)

SCL → 22

SDA → 21

From Multimeter (GND)

To Multimeter

Insert magnetometer into solenoid slit

10 Ω

100 Ω

16 of 34

A note about your multimeters

Make sure your multimeter is in the “10A” port, and set to read Amps (instead of mA)

Otherwise, you will blow the multimeter fuse and break it!

17 of 34

Experimental Setup - Physical Picture

Make sure your resistors are all aligned!

*Make sure your multimeter is in the “10A” or “A” port, and set to read Amps (instead of mA as shown here)*

18 of 34

Using the GY-511 Magnetic Sensor

  • Same code from 5A
  • Compile and upload the Arduino code.
  • Open Serial Monitor to view magnetic field measurements
    • Tools → Serial Monitor
    • Shortcuts Windows: “ctrl+shift+m” or Mac: “cmd+shift+m”

Correct Output

*If your data stops streaming/the magnetometer is disconnected, you need to re-upload the code before collecting data again*

19 of 34

Using the GY-511 Magnetometer

  • To Collect Data, insert the GY-511 Magnetometer into the center slot of the solenoid

  • The magnetometer is VERY sensitive to small movements. For best results, hold the magnetometer stable as shown

  • The magnetometer collects B field data in the x, y, and z directions shown on the module

20 of 34

Experimental Procedure: B-Field vs Current

  1. Measure the magnetic field inside the solenoid without any applied current.
  2. Place the 3.3V supply wire at the 1st resistor place.
  3. Measure the magnetic field by placing the GY-511 magnetic sensor inside the solenoid opening.
    1. Be sure to include XYZ magnitudes
  4. Measure the current using the ammeter. Make sure to use 5 10 Ohm resistor and at the end have the 100 Ohm, the 100 OHM SHOULD ALWAYS BE IN CIRCUIT
  5. Move the supply wire 1 place down the resistor chain to the 5th resistor place.
    • Less resistors results in higher current through the solenoid → I = V/R
  6. Repeat steps 3-5 until you reach the last (100 Ohm) resistor.
    • Do not go past this position as the resistor will get really hot due to the high currents.
  7. Do 2 more rounds of measurements for a total of 3 measurements per resistor stage (100 Ohm Resistors).

21 of 34

Selecting The Field Strength

Moving the wire changes the amount of resistance in the circuit, and (by Ohm’s law) the current traveling through the solenoid

22 of 34

Python Analysis

  1. Create a theoretical plot for the magnetic field inside the solenoid of 100 turns
  2. Plot your magnetic field strength vs current data.
    1. Include error margins on each point
    2. Add least squares fit to your data
  3. Plot all 3, theoretical, experimental data, and experimental fit on a single plot.
  4. From your fit parameters, extract your experimental value of vacuum permittivity μ0. Propagate your uncertainty from your current and magnetic field values to this new measurement
  5. Compare your experimental vacuum permittivity with the theoretical value, and report your results as a percent error:

23 of 34

END OF UNIT 5 WINTER 2026

There is NO REPORT for Unit 5, just a postlab. The postlab must include:

  • Earth’s Magnetic Field Magnitude
  • Latitude of LA
  • Fit of dipole approximation B vs R
  • Cylindrical Magnet Magnetization and Magnetic Dipole Moment
  • Fit of Ampere’s Law B vs I
  • Calculated vacuum magnetic permeability

24 of 34

Lab 5C: Force Between Two Cylindrical Magnets

NOT FOR WINTER 2026

25 of 34

Magnetic Field Models

  • In Nature, magnetic monopoles do not exist as is the case with electric monopoles.
  • Instead, magnetic dipoles are the approximate view of how magnetic charge is handled in the universe.
  • Magnetic dipoles can be modeled by tiny loops of electric currents.

  • When many of these magnetic dipoles are aligned with one another, they produce magnets at a large scale.

26 of 34

Magnetic Forces

  • The force between two magnetic monopoles is:

  • Which is identical is form the force equation between two electric monopoles.
  • The force experience between two magnetized surfaces can be expressed as:

  • Where A is the area of the surfaces, H is the magnetization field, 𝝻0 is the permeability of free space, and B is the magnetic flux density.
  • Finally, the expression for the force between two cylindrical magnets is:

  • Where, B0 is the field strength close to the magnet, L is the length of the magnet, R is the radius and x is the separation between them

Attractive

Repulsive

27 of 34

High B-Field Magnetic Sensor

28 of 34

Measuring B-Field of Magnets

  1. Before continuing to the experiment, measure the magnetic field strength of the magnets you will be using.
    1. Your magnet stack should be 3 cylindrical magnets.
    2. Your magnetic field measurements should be ~110 mT.
    3. Ignore the x,y components and only use the z magnetic component for your experiment.
  2. Attach the high B-field magnetic sensor to your arduino as described in the previous slide.
  3. Download the TLV493D-A1B6 v1.0.3 by Infineon Tech library to operate your sensor module
    • Open the Arduino IDE
    • Go to Tools → Manage Libraries
    • Search TLV493D-A1B6
    • Install
  4. Upload the following code to your arduino and open serial monitor to view the B field measurements.
    • Note: Units are in mT.

29 of 34

Experimental Setup

30 of 34

Electrical Schematic of Scale Sensor

NOTE: You only have to wire the RED wires to the arduino. The rest are prewired!

31 of 34

Scale Sensor Instructions

  1. Before continuing to the experiment, you will need to activate your arduino controlled scale.
  2. Attach the scale sensor to your arduino as described in the previous slide.
  3. Download the HX711 Arduino Library v0.7.5 by Bogdan Necula library to operate your sensor module
    1. Open the Arduino IDE
    2. Go to Tools → Manage Libraries
    3. Search HX711
    4. Install HX711 Arduino Library v0.7.5 by Bogdan Necula
  4. Upload the following code to your arduino and open serial monitor to view the scale measurements.
    • Note: Units are in grams.

32 of 34

Experimental Procedure

  1. Once you have your scale operational, place your magnet on top of the scale. Close any serial monitor that might be open.
  2. Move your second magnet with on the translatable stage as far away as possible from the first magnet.
  3. Without touching or disturbing too much your working space and scale, open up serial monitor once more.
    1. This process will zero, or “tare”, your scale such that the mass of the magnet is neglected.
    2. You scale should now read zero grams
  4. Bring your second magnet on the translatable stage to be directly in line with the magnet on the scale.
  5. Conduct the following distance measurements between 2 magnets:
    • 10, 9, 8, 7, 6, 5, 4, 3, and 2 cm separations
  6. At each distance separation, measure the apparent weight, “force.”
  7. Repeat steps 5-6, 4 more times for a total of 5 measurements at each distance separation.

33 of 34

Unit 4: Group Report

34 of 34

Unit 4: Group Report

  • Complete a report up summarizing your work in Unit 4
    • Title, Authors, Abstract
    • Introduction: Scientific background, Hypothesis
    • Methods: Experimental setup, Procedure
    • Results: Data analysis with several graphs
    • Discussion, Conclusion
    • References and Python Code Appendix
  • Make sure to include about the following:
    • Theoretical and experimental plots of:
      • Magnetic field inside the solenoid for all currents
      • Force between 2 magnets