I have been trying to replicate this but am having some difficulty. I have the circuit nominally working, but I can not get it tweaked to levitate the magnet. Either the magnet drops to the base, or slams into the electromagnet ( I am using the same electromagnet, permanent magnet, and code presented in the OP, the hall sensor might be slightly different as I am using the A1321). It is easy to see that the parameters depend critically on the specific permanent magnet being used, the characteristics of the hall sensor, and the electromagnet.
I have tried different magnets, and different settings without success. In trying to be methodical, I run into the complication that the hall sensor itself picks up the signal from the electromagnet. So, trying to turn the electromagnet off and map hall sensor reading to distance from permanent magnet to electromagnet does not help, because that mapping will be distorted depending on the signal to the electromagnet. Another complication is that the permanent magnet is attracted to the metallic parts of the electromagnet so there is an uncontrolled attractive element that increases as the gap decreases.
Can anyone suggest a methodical approach to tweaking the set point, P-gain, D-gain, and I-gain to get this thing floating? Given that there are 4 parameters, and no real equations to guide, I am sort of at a loss at this point.
Thanks!