Arduino Air Bonsai Levitation




Introduction: Arduino Air Bonsai Levitation

It's been a long time since my previous tutorial, my work is quite busy and I spend less time on Instructables. This time is a project that I like very much since my first saw it on Kickstarter: Air Bonsai. I was really surprised at how the Japanese made it, really a beautiful and mysterious piece.

Any mystery can be explained by looking inside, where it works. I have learn a lot about air bonsai more than a month ago and it was actually a magnetic levitation. I have also seen many tutorials on how to make magnetic leviation and all of them are making an object levitating from above where there is an electromagnet controlled by the circuit. There are no instructions on how to make a circuit similar to air bonsai.

Take a look at my steps below to make your own bonsai air with Arduino.

Pls note English isn't my native language, be generous with any grammatical errors. :D

Update #1: Dec 09 2018

Step 1: Instruction Video

Take a look at the video above for a quick look at how to make a magnetic levitation.

Pls note the instructions in the video are very simple and do not fully tips to start. Just take a look at the video and follow all of steps below to make sure you can make your own air-bonsai successfully.

Step 2: How It Works

I find out and realized that the circuit of kickstarter air-bonsai version was quite complex, without any microcontroller, I didn't have any knowledge of its analog circuit, there seems to be no way to do it. After looking careful, I realized its principle is quite simple, that is to make a magnet piece floating above another magnet piece. All of my rest work is make the floating magnet not falling down.

I think to do this with the Arduino actually a lot easier than calculating the analog circuit. And I succeeded in this way, really a lot simpler.

A magnetic levitation consists of two parts, the base piece and floating piece.

  1. Base piece
  • This part is at the bottom, which consists of a magnet to create a round magnetic field and electromagnets to control that magnetic field.
  • Each magnet has two poles: the north and the south. Experiments show that opposites attract and same-poles repel. Four cylindrical magnets are placed in a square and have the same polarity, forming a round magnetic field upward to push any magnet, which has a same pole and in between of them.
  • There are four electromagnets at all, they are placed in a square, two symmetric magnets is a pair and their magnetic field is always opposite.
  • The hall sensors and drive circuits control the electromagnets. Create opposing poles on the electromagnets by diverting the current through them.

2. Floating piece

  • Include a magnet floating above the base piece, which can carry a small pot.

How it works?

The magnet on top is raised by the magnetic field of the bottom magnets because they are the same poles. It however tends to turn over to fall down and attract in each other.

To prevent the top magnet piece from turning upside down and falling, electromagnets will create magnetic fields to push or pull to balance it, thanks to hall sensors.

Electromagnets are controlled in two X and Y axes, resulting in the upper magnet being kept balanced and floating.

Controlling electromagnets is not easy, this requires you to have knowledge of the PID controller, which is discussed in detail in the next step.

Step 3: PID Controller

What Is PID?
From Wikipedia: "A proportional–integral–derivative controller (PID controller or three term controller) is a control loop feedback mechanism widely used in industrial control systems and a variety of other applications requiring continuously modulated control. A PID controller continuously calculates an error value {\displaystyle e(t)} as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively) which give the controller its name."

In a simple way to understand: "A PID controller calculates an 'error' value as the difference between a measured [Input] and a desired setpoint. The controller attempts to minimize the error by adjusting [an Output]."

So, you tell the PID what to measure (the "Input",) Where you want that measurement to be (the "Setpoint",) and the variable to adjust that can make that happen (the "Output".)

Get understanding about PID easy in Youtube:

The PID then adjusts the output trying to make the input equal the setpoint. For reference, in a car, the Input, Setpoint, and Output would be the speed, desired speed, and gas pedal angle respectively.

In this project:

1. The Input is the current realtime value from hall sensor, which are updated continuously because the position of the floating magnet will change in real time.

2. Setpoint is the value from hall sensor, which is measured when the floating magnet is in the balance position, at the center of the magnets base. This index is fixed and doesn't change over time.

3. Output would be the speed to control electromagnets.

Thanks to Arduino community to write PID library and it really easy to use.

More info about Arduino PID at

We need to use a couple of PID controller in Arduino, one for X axis and other for Y axis.

Now is the time to start buying the necessary components.

Step 4: Materials List

Below is the list of the components you need to buy for this project, make sure you have them all before starting.

Some of the components are very popular and I believe you are already available in your own stock.

The components come with a quantity and a suggested link. Most of the suggested links come from Aliexpress where you can buy cheap and free shipping. You can buy in other places as long as you can buy them in the easiest way.

  • 5.6K ohm resistor - X2
  • 180K ohm resistor - X2
  • 47K ohm resistor - X2

  • 10K ohm potentiometer - X2

  • Acrylic sheet A5 size - X1

  • Wooden pot - X1

  • PCB Breadboard - X1

  • 3mm screw - X8

  • Wire

  • Mini plan such as succulent, cactus, mini bonsai

Step 5: Tools

Here is a list of tools, most commonly used by anyone.

  • Soldering iron
  • Hand saw
  • Multimeter
  • Scew drivers
  • Osilloscope (optinal, you can use multimeter instead)
  • Table drilling
  • Hot glue gun
  • Electronic plier

Step 6: LM324 Opamp and L298N Driver and SS495a

LM324 Op-amp

Operational amplifiers (op-amps) are some of the most important, widely used, and versatile circuits in use today.

We use the opamp to amplify the signal from the hall sensor, the purpose is to increase the sensitivity so that arduino easily recognize the change of magnetic field. When only change a few mV at the output of the hall sensor, after passing the amplifier can change several hundred units in the Arduino. This is necessary to keep the PID controller smooth and stable.

Learn more about how op-amp works in this tutorial.

A common opamp IC that I choose is the LM324, it's very cheap and you can buy it at any electronics store. The LM324 has 4 internal amplifiers, which allow you to use flexibly, however in this project I only need two amplifiers, one for the X axis and the other for the Y axis.

You can find how to assemble the LM324 in the follow step.

L298N module

Dual H-Bridge L298N are typically used in controlling motors speed and direction of two DC motors, or control one bipolar stepper motor with ease. The L298N H-bridge module can be used with motors that have a voltage of between 5 and 35V DC.

There is also an onboard 5V regulator, so if your supply voltage is up to 12V you can also source 5V from the board.

In this project I used L298N to control two pair of electromagnet coils and use 5V output to power to Arduino and hall sensor.

Module pinouts:

  • Out 2: pair of electromagnet X
  • Out 3: pair of electromagnet Y
  • Input power supply: DC 12V input
  • GND: Ground
  • 5v: 5v output to Arduino and hall sensors
  • EnA: Enables PWM signal for Out 2
  • In1: Enable for Out 2
  • In2: Enable for Out 2
  • In3: Enable for Out 3
  • In4: Enable for Out 3
  • EnB: Enables PWM signal for Out3

Wiring to Arduino: we need to remove 2 of jumpers in EnA and EnB pin, then connect 6 pins In1, In2, In3, In4, EnA, EnB to Arduino. Detail in the follow step.

Learn more about L298N module in this instructions.

SS495a Hall sensor

SS495a is a Linear Hall Sensor with analog output.

Notice the difference between analog output and digital output, you can't use a sensor with digital output in this project, it only has two states of 1 or 0, so you can't measure the output of magnetic fields.

An analog sensor will result in a voltage range of 250mV to Vcc, which you can read with Arduino's Analog Input.

Two hall sensors are required to measure the magnetic field in both the X and Y axes.

Step 7: Neodymium Ndfeb Magnets

Wikipedia: "Neodymium is a metal which is ferromagnetic (more specifically it shows antiferromagnetic properties), meaning that like iron it can be magnetized to become a magnet, but its Curie temperature is 19 K (−254 °C), so in pure form its magnetism only appears at extremely low temperatures. However, compounds of neodymium with transition metals such as iron can have Curie temperatures well above room temperature, and these are used to make neodymium magnets."

STRONG, that's the word I use to describe the Neodymium magnet. You can not use ferrite magnets because their magnetism is too weak. Neodymium magnets are much more expensive than ferrite magnets.

Small magnets are used to make the base piece, large magnets to make the floating piece.

Caution: You need to be careful about using neodymium magnets, since their strong magnetism can hurt you, or it can break the data of your hard drive or other electronic devices that are affected by magnetic fields.

Tips: You can only separate the two pieces of the magnet by pulling them sliding to the horizontal, you can not separate them in the opposite direction because their magnetic field is too strong. They are also very brittle and easy broken.

Step 8: Prepare the Cover for the Base Piece

I use a small terracotta pot with diameter of 3 3/4 ", which is usually used to grow succulent or cactus. You can also use a ceramic pot or wooden pot, as long as they fit perfectly.

Use a 8mm drill to create a hole near the bottom of the pot, which is used to hold the DC jack.

Tips: You should use a flat wood bit to drill into the terracotta pot, I used an iron drill and it almost burned, really not effective.

Also you can use water to cooling down the drill, avoid making it overheat.

Step 9: 3D Printing Floating Magnet Holder and Acrylic Laser Cut

3D Printing

Printing the floating magnet holder with the STL file that I have attached.

If you have a 3D printer available, this is really great. Congratulations, you have the opportunity to make everything with this machine. If not, don't be disappointed because you can use a cheap 3D printing service, which is very popular now.

Tips: You only need about 20 minutes to complete this part and infill only 30%.

Laser cut

You should use a local laser cutting service to cut two acrylic pieces with the file, which I have attached as AcrylicLaserCut.dwg. This is an autocad file.

An acrylic piece is used to support the magnets and electromagnets, the rest to cover the surface of the terracotta pot.

Step 10: Prepare SS495a Hall Sensor Module

Cut the pcb breadboard into two pieces, one piece to attach the hall sensor and the other to make the LM324 circuit.

Attach two magnetic sensors perpendicular to the pcb. Note the two sides are engraved of the sensors rotate to each other, fixed welding.

Use the thin wires to connect two VCC pins of sensors together, do the same with the GND pins. The output pins are separate.

Step 11: Opamp Circuit

Solder the socket and the resistors to the pcb following the schematic, paying attention to put two potentiometers in the same direction for easy calibration later.

Attach the LM324 to the socket, then connect the two outputs of the hall sensors module to the op-amp circuit.

Wiring two LM324 output wires to connect to Arduino. The 12V input should be shared with the 12V input of the L298N module, the 5V output of the L298N module connected to the 5V of the potentiometers.

Step 12: Assembly the Electromagnets

Assemble the electromagnets onto the acrylic sheet, noting that fixed at four holes near the center.

Tighten the screws to avoid moving.

Because the electromagnets are symmetric across the center, they are always in poles opposite, so that the wires on the inside of the electromagnets are connected together, the wires on the outside of the electromagnets being connected to the H-driver L298N.

Pull down the wires under the acrylic sheet through the nearby holes to connect to the L298N.

Tips: The copper wire is coated with a insulated layer, so you must remove it with a knife before you can solder them together, remember to use Heat Shrinkable Tube after welding.

Step 13: Attach the Sensor Module and Magnets

Use hot glue to fix the sensor module between the electromagnets, pay attention that each sensor must be square with two electromagnets, one on the front and the other on the back.

Try to calibrate the two sensors as centrally as possible so they do not overlap, which will make the sensor the most effective.

The next step is to assemble the magnets on the acrylic base. Combining two D15*4mm magnets and a D15*3mm magnet together to form a cylinder, this will cause the magnets and electromagnets to have the same height.

Assemble the magnets between the pairs of electromagnets, note the poles of the upward magnets must be the same.

Step 14: DC Power Jack and L298N 5V Output

Solder the DC power jack with two wires and use a heat shrink tubing. Connected DC power jack to the input of the L298N module, its 5V output will power the Arduino.

Step 15: L298N and Arduino

Connect the L298N module to the Arduino following to the schematic above.

L298N ===> Arduino

Out 5V ===> VCC

GND ===> GND

EnA ===> 7

In1 ===> 6

In2 ===> 5

In3 ===> 4

In4 ===> 3

EnB ===> 2

Step 16: Arduino Pro Mini Progamming

Since Arduino pro mini don't have any usb to serial port, you need to connect an external programmer.

The FTDI Basic will be used to program (and power) the Pro Mini.

Follow this Sparkfun instruction to get more info.

Step 17: Preparation of the Floating Piece

Attach two D35 * 5 magnets together to increase magnetism.

Step 18: Calibration Setpoint Value

Load program ReadSetpoint.ino to Arduino, which I have attached. This program will read the values of the hall sensor and send it to the computer via the serial port. Open COM port to see it.

Plug the 12V DC to the DC power jack, you also use osilloscope to readout the sensor value.

Observe the values on the screen, make adjustments by adjusting the two potentiometer. The best value is 560, at which point the output of the sensor is about 2.5V.

After setting the setpoint, place the floating magnet piece above the base piece and shake it to see the change of the setpoint on the screen.

Tips: Mark the pair of electromagnets and potentiometers respectively in the X and Y axes so that you can easily correct them later.

Step 19: Load the Main Program

After calibrate the Setpoint value, now is the time to enjoy the results.

Load the Levitation.ino main program, which I have attached below.

Use the super glue to fix the magnet piece and the magnet holder, which was 3D printed before.

Tips: After loading the main program, you can make small adjustments on the potentiometers to make the floating piece fixed in the center.

Step 20: Put All Together

First attach the DC power jack to the pot, then put the remaining parts into the pot.

Finally, use the remaining acrylic sheet to make the surface of the pot.

Step 21: Prepare the Plant

Attach the wooden pot to the floating magnet piece.
I used a small cactus to plant. You can use cactus or succulent or any mini bonsai that is symmetrical or small and lightweight.

Step 22: Finish and Enjoy

Enjoy your results, your efforts will be met with a bonsai air pot on your own desk, which is made by yourself.

Microcontroller Contest

Grand Prize in the
Microcontroller Contest

Be the First to Share


    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    140 Discussions


    2 months ago on Step 15

    The connection between nano and Hbridge shown in the diagram is not correct. Arduino out put is IN1 D4, IN2 D3, IN3 D7, IN4 D8, ENA D6, ENB D5.


    6 months ago

    Hi friends this will not work don't try.i wasted so much money and time. Finally I purchased ready made one.


    Reply 2 months ago

    Hi friend. I could not also finish this project. The magnetic cold not float, it was not in center.


    Reply 5 months ago

    what exactly was the problem?


    Question 5 months ago

    Hello dear . I want to make this project but i didnt see arduino code. Could you pls give me the arduino code ? My mail adresses is ;


    6 months ago


    Just one quick Q, has anyone finished this project successfully ? I´m really looking forward to start, but I have read that in most of the comments there are some serious issues with the code and other setups. Please let me know if it is worthless to buy and start with everything

    Best regards,


    Question 6 months ago

    Hello. I will use Arduino Uno instead of mini. How should be the changes on circuit? Should i make any power connection from arduino to l298n or just connection to arduino's 2-3-4-...? Thanks for helping


    Question 8 months ago

    Everything seems to be doing their job. Got readings from hall sensors. Pin outputs to L298N turn on and off based on floating magnet position. Unfortunately the magnet just won’t stay but got pulled to one of the magnet columns. It seems like the electromagnets are not providing balancing forces as expected. I have checked and am positive that all wires are connected properly. It is disappointing as I cannot see what is wrong.


    Question 11 months ago

    Hello, I am currently working on making a levitation device with my partner and we are having a lot of trouble with opening the Acrylic Laser Cutting file on Adobe Illustrator. When we open the file, it gives us dimensions that are not accurate. How big are the pieces that we need to laser cut?


    Question 1 year ago on Step 11

    Hi my dear friend
    Thank you very much for this great post
    I have a very important question
    Please answer me about it
    Where are these diodes located and what is their function?

    Praneeth naralasetty
    Praneeth naralasetty

    Question 1 year ago

    Did any one achieved it? if yes please help me.


    Question 1 year ago

    ME DA ESTE ERROR: Levitation:20: error: 'PID' does not name a type
    Levitation:21: error: 'PID' does not name a type
    Levitation.ino: In function 'void setup()':
    Levitation:77: error: 'PID_X' was not declared in this scope
    Levitation:78: error: 'PID_Y' was not declared in this scope
    Levitation:83: error: 'AUTOMATIC' was not declared in this scope
    Levitation.ino: In function 'void loop()':
    Levitation:92: error: 'PID_X' was not declared in this scope
    Levitation:93: error: 'PID_Y' was not declared in this scope


    Question 1 year ago

    Hello! thank you very much for the information you share on the page and I intend to make it come soon, I just want to know a little more about the levitation coils since the inductance (Henry) is important to know, how much are we talking about? :D Please please, answer our questions, we will aprecciate a lot!


    Question 1 year ago on Step 17

    Hello, very good work. There are two different magnets attached to each other in the first picture, why? The link has a single D35 * 5mm magnet. Why is the upper magnet larger?

    Ekran Görüntüsü (4).pngEkran Görüntüsü (5).png

    Question 1 year ago on Introduction

    Hello,and thank you for such an excellent and inspiring instruction.
    what is the resistance of the coils and what gauge of wire are you using.
    Finally can this be achieved using a 741 or 358 op amps?


    1 year ago

    Hi, it's beautiful ...
    I need one help from you...
    I have 8 coils and 4 hall sensors.
    11 neodymium magnets for surrounding circle..(20mm*6mm)
    I have code for the project..
    But don't know how to define values of PID.
    Can you please help me to make it ?


    1 year ago

    Hi Funelab:

    Thanks for sharing this project.

    I try to follow you instructions, but my prototype don't work. Is impossible center the magnet, probabily because my magnets are differents to yours,

    Please look my prototype:

    In fact, one problem is adjust the potentiometers X & Y to you suggested level of 560...never exact.

    Short Example:

    Setpoint_X: 559 Setpoint_Y: 563
    Setpoint_X: 562 Setpoint_Y: 560
    Setpoint_X: 562 Setpoint_Y: 559
    Setpoint_X: 569 Setpoint_Y: 562
    Setpoint_X: 557 Setpoint_Y: 561
    Setpoint_X: 559 Setpoint_Y: 562
    Setpoint_X: 559 Setpoint_Y: 562
    Setpoint_X: 560 Setpoint_Y: 561
    Setpoint_X: 559 Setpoint_Y: 562
    Setpoint_X: 562 Setpoint_Y: 561
    Setpoint_X: 559 Setpoint_Y: 562
    Setpoint_X: 559 Setpoint_Y: 561
    Setpoint_X: 557 Setpoint_Y: 561

    Other problem are the weigth of my floating magnets. If I use a pair like you images, is too heavy. If use the minor diameter, is too light.

    Because this problem, I try to use more magnets around the table (8 in total, 2 for each location), for more magnetic field.

    Finally, I put 2 Leds, one in each sensor in parallel to zener diode (not in you diagram, but in the video), of the Opamp Circuit, ligth on when te electromagnets are working.

    I'm frustrated because don't see the problem.

    Please helpme.

    Best Regads

    Alexis López Tapia
    Altern Energy TV Show
    BioBio TV - Radio BioBio


    Tip 1 year ago

    Hey there, engineering student here!
    I'm making one these days and I clearly see the issues this design has, the first thing i would try is adding a 10 ohm resistor in series to each coil pair. It will:
    1) Lower the current, thus avoiding melting stuff around :)
    2) Reduce the time constant (L/R) of the coil circuit, making it respond much quicker to the pwm signal, helping stabilize the system
    3) Unluckily, it will also lower the magnetic field generated by the coils, which is directly proprtional to the current. I'm confident, though, that it's not much of an issue as these coils are the same ones used in pre-built ready to use boards to make floating stuff, which have a current rating of 0.2A

    The MAX power draw from the supply should be around 17 watts with the resistor.
    Without it it's way higher, I've checked with a tester and the coil windings roughly have a 3.5 ohm resistance.. so it would be 42 watts, higher than the supply rating used in the project (that's why some people burned it)
    The downside is that a power resistor (rated at least 5w) is needed, common ones can't handle so much power, and it will heat up as well.

    A simpler solution would be to limit the PWM duty cycle in order to limit the average voltage
    fed to the coils. It would for sure help with point 1). It can easily be done by changing the two lines in the setup function to PID_X.SetOutputLimits(-127,127) and PID_Y.SetOutputLimits(-127,127). Why 127? Because it would roughly draw the same current as if you added the resistor.

    I could have explained more in depth about how I did my maths but I think it's getting quite a long comment and I don't even know if anyone will read this :)

    Anyway, for now I'm following the second option. If you try it, feedback is appreciated! :D

    UPDATE: I've made some thermal calculations, If you limit the current to 0.4A (-> Max pwm output: 102, on my setup) the coils will heat up to about 68°C (I've later tested this one, it's correct). If you're willing to go higher, 0.5A heats to 85°C, 0.6A to 108°C.

    UPDATE 2: After playing around with the H bridge I found that its output current is way more predictable by leaving the jumpers on ENA and ENB, and applying pwm directly to the IN pins: (eg: If the output value from the pid is positive, IN1 is low, and IN2 is fed the pwm wave. If the output is negative, IN2 is low, and IN1 is fed the pwm wave). This is the "braking mode" when the bridge is used to drive dc motors, so the coil ends are short circuited between the pwm pulses instead of being at high impedance.


    Reply 1 year ago

    Handy engineer here.
    Read and agree.
    I was about to ask wether we would have lower power consumption if coils were connected directly in parallel thus to lower the resistance . Obviously one coil should be inverted to maintain opposite polarities.
    Voltage output would need to be further limited to a avoid heat up.
    Will try to make it work first and then make this adjustment.

    Awaiting comments.
    Awesome project.


    Reply 1 year ago

    Unrelated question: what's your floating magnet size? Mine is 35x10 mm and I have a feeling it's too big/heavy..