Projects

Defying Gravity

Prototyping Magnetic Suspension & Levitation

Luke Prior

Issue 54, January 2022

This article includes additional downloadable resources.
Please log in to access.

Log in

Experimenting with magnets and electromagnets to suspend or levitate objects.

BUILD TIME: AN AFTERNOON
DIFFICULTY RATING: Intermediate

THE BROAD OVERVIEW

In this project, we experiment with electromagnets, rare-earth magnets, and hall effect sensors to attempt magnetic suspension and levitation.

We document our experiments and learnings about the technology, which will help guide you in creating your own magnetic levitation device.

The basic concept for suspending an object using magnetic fields is the ability to determine the position of a magnet using its magnetic field and then use an electromagnet to manipulate the forces acting on the object to keep it in its desired position. The system needs to do this continuously acting against gravity and other external forces such as a gust of wind.

We started this project with the intention to create a magnetic suspension device that could suspend a magnet under an electromagnet, however, after creating a prototype with limited success, we ended up building an easier magnetic levitation system.

ELECTROMAGNETS

Electromagnets enable us to create and control magnetic fields. The basic concept for an electromagnet is to run an electric current through wire coiled around a magnetic core, which creates a concentrated magnetic field. The strength of this magnetic field can be controlled by reducing or increasing the amount of current in the coil as the magnetic field strength is proportional to the current.

The direction of the magnetic field from an electromagnet can also be controlled by reversing the direction of the current in the coils. This is the same technique that we use to drive motors forwards and backwards. The disadvantage of electromagnets compared to permanent magnets is that they require a constant electrical source to maintain their magnetic field.

Electromagnets are widely used in everyday devices including motors, speakers, hard drives, generators, and relays. You can construct your own electromagnet to meet specific criteria using a coil of wire and a magnetic core such as an iron rod (See our Kids’ Basics Issue 50), however, it’s much easier to source one from an electronics retailer. Store-bought ones usually come with useful information regarding magnetic field strength and energy consumption.

RARE EARTH MAGNETS

Rare-earth magnets are the strongest permanent magnets available and were developed in the 1970s and 1980s using alloys of rare-earth elements such as neodymium (Nd).

Neodymium magnets are the most common type of rare-earth magnets and consist of a mix of neodymium, iron, and boron. These other elements are required as pure neodymium only exhibits useful magnetic properties at very low temperatures.

These magnets quickly replaced traditional permanent magnets in a myriad of modern technologies which allowed their overall size and weight to drastically reduce. The reduced weight of these magnets makes them perfect for our application as the force of gravity exerted on them will be significantly less than a comparably sized traditional magnet. This will reduce the force needed to manipulate the magnet reducing the size of our electromagnet and its power consumption.

HALL EFFECT SENSORS

Hall Effect sensors utilise the Hall effect to detect and measure the presence of magnetic fields. The sensor consists of a thin strip of metal to which a current is applied. In the presence of a magnetic field perpendicular to the direction of the current, charge carries are detected, creating a measurable voltage proportional to the strength of the magnetic field.

The voltage produced by this phenomenon is too small to be used directly so the sensors feature integrated amplifiers and regulators to produce a measurable output. This value can then be read by an Arduino to determine the strength and direction of any present magnetic fields.

Initial Testing

Our first test was to experiment with the core components to get an understanding of how they worked.

The three main elements of our designs were the neodymium rare-earth magnets attached to the object we wanted to manipulate, the electromagnet to control the forces, and the Hall effect sensor to create a feedback loop by detecting the magnetic field strength of the neodymium magnet.

The rare-earth magnets we purchased feature a diameter of 4mm and a height of 3mm. They use a mixture of rare-earth elements including neodymium mixed with ferrite and are coated in a nickel jacket to protect the brittle magnetic material. We quickly discovered that these magnets were both extremely strong and brittle when we accidentally dropped one and chipped the casing, which revealed the raw materials.

The datasheet for these magnets reveals some interesting information, including that they feature a density of 7.4g/cm3, a maximum energy product of 263-279 kJ/m3, and a maximum operating temperature of 80°C. While it is possible to purchase magnets with a greater maximum energy product, these will be sufficient for our purposes.

The magnets shouldn’t be used near sensitive electronic devices such as a mobile phone or computer as they may cause damage. We noticed that the fans on our computer stopped operating when the magnets were brought close, and we weren’t interested in testing that further.

Once we had a suitable understanding of the strength of our neodymium magnets, we decided to test the electromagnet. The electromagnet we used is a 5V 3W design with a 35kg holding force. This value is significantly higher than the actual limit to how much the magnet can lift, which is closer to 7kg. This is the amount of weight the electromagnet could potentially carry if it has good contact. As we will be attempting to manipulate an object through the air, this value will be considerably lower.

Parts Required for EXPERIMENTS:JaycarAltronicsPakronics
1 x 5V Electromagnet--DF-DFR0802
1 x Rare Earth Magnet*LM1622T1466ADA9
1 x UGN3503UA Hall Effect SensorZD1902--
1 x Arduino Compatible Uno or equivalentXC4410Z6280ARD-A000066
1 x Motor Driver^ZK8880^Z2900^ADA2448
1 x Analog Rotation SensorXC3736-DF-DFR0054
1 x USB to 2.1mm Male Barrel Jack-P6701AADA2697
1 x 2.1mm DC Socket with Screw TerminalsPA3713P0610AADA368

Parts Required for EXPERIMENTS:

* Quantity required, may only be sold in packs. A breadboard and prototyping hardware is also required.

^ We used the Adafruit motor driver from Pakronics. Using other brands may require code modification

The electromagnet can be powered directly from a 5V supply as there is no digital circuitry to control the field on the device.

We decided to solder a set of breadboard male connectors to the electromagnet cables so we could easily switch the device to various power sources during testing. We found that a USB 3.0 connection could supply the required current using a simple adapter cable.

The electromagnet can also be controlled using a motor driver, which allows the direction and magnitude of the magnetic field to be controlled programmatically by reversing the direction and modifying the amount of power received. This can be used to allow the electromagnet to both attract and repel our neodymium magnet.

The final core component of our device was the UGN3503UA Hall effect sensor. This sensor is vital to the operation of our prototypes as it can determine the position of our neodymium magnet by measuring the magnetic field strength from it. The advantage of this specific sensor is that it outputs the raw value and can detect the direction of the field compared to other sensors that only output a binary detection value.

We can test the sensor by wiring it to an Arduino and running a simple script to log the measured voltage to the serial console. The sensor needs to be wired to the 5V output of the Arduino with the centre leg attached to ground, and the right leg on the flat side of the sensor going to 5V. We can then wire the remaining pin to A0 on the Arduino and upload this simple sketch.

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  int reading = analogRead(A0); 
  // Hall Effect sensor reading
  Serial.println(reading);
}

We can open the serial monitor and watch as the value changes when we bring a magnet towards the sensor. This also allowed us to gain an understanding of the sensor’s range of detection, distance, and resolution.

These findings contributed to our final design so that we could maximise the potential from the sensor.

Magnetic Suspension

We first intended to create a magnetic suspension device where an electromagnet would rapidly switch polarity to ensure that the neodymium magnet remained at a fixed position below. While we managed to levitate some specially weighted objects for very short periods, we often found that the magnet would stick to the electromagnet or not overcome the force of gravity.

We wouldn’t recommend directly duplicating this prototype unless you are an experienced maker willing to incorporate some of the potential improvements discussed at the end of this project.

The first step was to transition the electromagnet from being powered directly from a 5V power source to being driven by a motor driver.

We chose the Adafruit TB6612 driver as it could supply the required current (0.6A at 5V) and featured a modern efficient design, minimising wasted energy. We soldered the included pins to the TB6612 so that it could be used in a breadboard for prototyping.

We also needed an intuitive way to control and specify the required properties to achieve magnetic levitation. To do this, we implemented a simple potentiometer that could be used to control the threshold frequency for the electromagnet.

We decided to power the Arduino and the electromagnet from a single 5V power supply. We ran the broken-out connections to the breadboard where we could then power the individual devices.

The Arduino, motor driver, Hall effect sensor, and analog rotation sensor all required 5V power and were wired to this single source. The potentiometer, Hall effect sensor, and motor driver were all wired to the Arduino per the wiring diagram shown here.

The TB6612 motor driver requires two wires (INA1, INA2) to control a single motor without PWM speed control. We pull PWMA high by connecting it to 5V, disabling PWM control. INA1 can be wired to pin 5, while INA2 can be wired to pin 4. The Hall effect sensor and potentiometer each require just one cable to the Arduino to pins A0 and A1 respectively.

The hall effect sensor needed to be attached to the centre of the electromagnet so that it could detect the neodymium magnet directly below it.

The flat side of the sensor can be taped against the electromagnet. Due to the narrow field of detection, its magnetic field does not affect the readings enough to warrant a different solution.

We then worked on a program to test this fully assembled prototype before we created an enclosure for the device.

#include <Stepper.h>
void setup()
{
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
}
void loop()
{
  int reading = analogRead(A0); 
  // Hall Effect sensor reading
  int sensor = analogRead(A1); 
  // Potentiometer reading
  float setting = sensor/1023.0; 
  // Scale output to 0 - 1
  int threshold = 100 + (setting*400); 
  if (reading < (threshold-2)) { 
    // Outside threshold range enable electromagnet
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
  } else if (reading > (threshold+2)) { 
    // Outside threshold range enable electromagnet
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
  } else { 
    // Within threshold range disable electromagnet
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  }
}

THE CODE

The program we created initialises the pins required to interface with the motor driver and then enters a feedback loop. The program takes a reading from the Hall effect sensor and potentiometer at the beginning of each repetition. The reading from the potentiometer is scaled to between 0 and 1 and then used as a multiplier to generate the threshold frequency.

The Hall effect sensor reading is then compared against the threshold frequency. If it is above or below the allowable range, the electromagnet is activated with correct polarity to oppose or attract the magnet. This loop should, theoretically, allow the magnet to be suspended in a fixed position from the electromagnet. While we had some very limited success in getting the magnet to flutter, we couldn’t achieve reliable magnetic suspension. The reasons for this are explained in detail at the end of this project with ideas to improve the device in future. We believed that the general concept of magnetic manipulation could be possible with this setup, so we decided to try magnetic levitation.

THE RESULTS

To test this initial prototype, we secured one neodymium magnet to a 9V battery that we used as a weight so that the electromagnet could hold it in a stable position. We uploaded the code to the Arduino and began testing by holding the electromagnet above the magnet, and adjusting the threshold value using the potentiometer until the magnet and weight could overcome gravity.

Magnetic Levitation

The creation of a magnetic levitation prototype proved substantially easier than our previous attempts with suspension. We could utilise all our existing hardware and code with the addition of a new holding structure for the electromagnet and magnet.

The electromagnet was positioned on the ground, facing upwards towards the magnet and weight, which meant that the magnet naturally wanted to move towards the electromagnet, making levitation feasible.

We designed and 3D printed a simple friction mount for the electromagnet with provisions to secure it using a screw into the mounting hole. The mount also included 4 guide rods that are used to align the electromagnet, hall effect sensor, and magnet, ensuring that our readings and forces would be predictable.

We also had to design a plate for the neodymium magnet that could be fitted over the mounting rods. The addition of this plate negated the need for any additional weight so the 9V battery from our previous attempts could be removed. The 3D files used in this project can be found in the Resources section below.

THE RESULTS

This new design worked substantially better than our previous attempt with the plate levitating in place with its distance from the electromagnet configurable using the potentiometer. While we couldn’t achieve our initial intentions for magnetic suspension we were pleased with the final device and the knowledge gained throughout the development process.

WHERE TO FROM HERE?

As described, we encountered a range of difficulties in the development of our magnet suspension and levitation devices. This has led us to identify various improvements that could be incorporated to improve the reliability and practicality of these prototypes.

The UGN3503UA hall effect sensor we used in our prototypes appeared to have a rather narrow sensing range, resulting in the neodymium magnet often drifting outside the range and causing a failure. We could address this issue by switching to a different sensor with a wider range or combining multiple sensors.

The issue of poor detection can also be addressed by increasing the surface area of the neodymium magnets being sensed. We used the smallest magnets available in our testing but would suggest opting for a larger size for better results. Multiple magnets could be used alongside each other but securing them in place can be difficult.

To minimise the chances of losing detection, we can create a custom electromagnet customised to our specific needs so that the magnetic field is highly directional and only covers the area necessary. This would minimise the chances of the neodymium magnet drifting outside the sensor range allowing for more stable control. We could also create a custom structure from iron to focus the magnetic field from a commercial electromagnet like the one used in these prototypes.

We used a plastic support structure to align the electromagnet, sensor, and neodymium magnet in our levitation prototype, which while easy to manufacture, could sometimes introduce excessive friction. This could be minimised by using nylon string as a guide affixed to a central plate. This would both reduce the friction and improve the overall appearance of the device.

The final improvement that could be incorporated is a redesigned structure to hold the magnet with a lower weight, allowing heavier items to be placed on the plate. The structure could also be manufactured with a translucent material such as plexiglass to improve the overall appearance and emphasise the magnetic levitation.