An AVR Atmega based PID magnetic levitator

Summary of An AVR Atmega based PID magnetic levitator


This article describes a magnetic levitator using an Atmega8 microcontroller to suspend a magnet via electromagnetic fields. A Hall sensor measures the magnet's distance from a coil, which is driven by PWM impulses adjusted by a PID controller to balance gravity and magnetic pull. The system operates at 8MHz with a 1ms check cycle and a 1953Hz PWM frequency. Due to budget constraints, a small 12V coil limits lifting capacity, requiring the sensor to be placed close to the coil to prevent attraction to the ferrite core.

Parts used in the Magnetic Levitator:

  • Atmega8 microcontroller
  • Hall sensor (Allegro A1302)
  • Coil (ZYE1-P25/20, 12V 50N)
  • PID controller
  • Ferrite core

This is a magnetic levitator implemented using Atmega8 microcontroller.
Magnetic levitation is a method by which an object is suspended with no support other than magnetic fields.An AVR Atmega based PID magnetic levitator
To make a magnet levitate, an hall sensor is attached to a coil. The coil acts as an electromagnet, and the hall sensor measure the distance of the magnet from the coil.
The coil it is driven by PWM impulses, the closer the magnet is from the hall sensor, the bigger is the duty cycle and vice versa.
The coil works only if the magnet is in a certain range, out of this range no current flow through the coil, and the system is in is idle state.
The system has to mantain the equilibrium position of the magnet, the pull force of the coil has to be equal to the gravity force that pull the magnet to ground.
To stay on the budget, a small 12V 50N coil (ZYE1-P25/20) is used, with this coil the system can not lift heavy loads.
The hall sensor used it the Allegro A1302.
Because the heavy loads limitation, i’ve to put the hall sensor next to the coil, this solution produce a problem, the magnet can be pull even by the ferrite core of the coil, If it gets too close to the coil. To prevent this situation we have to emitting less current to the coil.
A bigger coil and a more sensible hall sensor can lift heavier load, and also the magnet can levitate far away from the coil.
To adjust PWM intensity, a PID controller is used.
A proportional-integral-derivative controller (PID controller) is a generic control loop feedback mechanism (controller) that calculates an “error” value as the difference between a measured process variable and a desired setpoint. The controller attempts to minimize the error by adjusting the process control inputs.
The micro runs at 8Mhz, every 1ms the hall sensor it is checked, and the PWM for the coil is adjusted. The PWM period is 1953Hz.Schematic An AVR Atmega based PID magnetic levitator
For more detail: An AVR Atmega based PID magnetic levitator

Quick Solutions to Questions related to Magnetic Levitator:

  • How does the coil function in this project?
    The coil acts as an electromagnet driven by PWM impulses where the duty cycle changes based on the magnet's distance.
  • What component measures the distance of the magnet?
    An Allegro A1302 Hall sensor attached to the coil measures the distance of the magnet.
  • Why was a specific small coil chosen for this build?
    A small 12V 50N coil was selected to keep the project on a budget, though it cannot lift heavy loads.
  • How is the equilibrium position maintained?
    A PID controller adjusts the PWM intensity so the coil's pull force equals the gravity force pulling the magnet down.
  • What problem arises when placing the Hall sensor next to the coil?
    Placing the sensor close causes the magnet to be pulled by the ferrite core if it gets too near, requiring reduced current emission.
  • How often is the Hall sensor checked during operation?
    The microcontroller checks the Hall sensor every 1ms while running at 8MHz.
  • What is the PWM period frequency used in the system?
    The PWM period is set to 1953Hz.
  • Can this system lift heavy loads?
    No, the system cannot lift heavy loads because a small coil was used to stay within budget.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top