How to make the electromagnet of a magnetic-levitator?
We are talking here for DC bar electromagnet. 
Briefly there are two tasks in design of electromagnets. First is to obtain a specific magnetic force, and second to avoid overheating of the coil. 

The basic necessary equations for magnetic properties of the electromagnets are


Magnetic flux density





Magnetic flux





Magnetic field strength





Magnetomotive force in the air-gap




First try

The diameter of the core that can suspend a 30 gr. battery at a distance of -lets say- 17 mm from the pole of electromagnet, must not less than 7mm in diameter (at saturation). So a core with diameter of  10mm it is a safe choice. This core have a holding force ability of about 4,5 Kgr when it is saturated (i.e 1.6T).

The best material for core is the “wrought iron” or “magnet iron”. They have high permeability and no residual magnetism. If you don’t have access to this materials, you can use series 400 steel bolts. And even better you can cook them at their Curie point (at least 10min) and  let them cool at very slow rate. A 10 mm bolt have a head (pole) of around 15mm. The length of our core (and the coil consequently) plays two roles: first extends the magnetic lines away (ok becomes very weak before returns to the other pole) and second increase the outer surface, helping convection and those avoid coil overheating.  Lets select an 8 cm length.

The pole cross section is 1.767 cm^2 and the mass to levitate is around 0,3N. So the magnetic flux density required is 0.0650Wb/m^2 (far from saturation!). 
The total magnetic flux in the core area will be 0.0000114Wb, which is the same for the gap, and the magnetic field strength will be around 51,500AT/m. Therefore the mmf in the 17mm gap is around 875 AT. So the final lifting power of this electromagnet will be 0.45Kgr.

Now if we fill a spool 8cm long with 0.8cm depth of winding, and set the final temperature of the coil less than 60oC, using magnet wire AWG 24 (around 2,000 turns in 14 leyers) then we will have an electromagnet with mmf around 960 AT  and all this produced by a current of about 500mA.

I’m leaving to you the optimization of this electromagnet as well as the calculation of the inductance and resistance of the coil, the length of the wire (known the mean turn length), the weight of the wire and finally the cost.