Control and measurement of a magnetic field using Arduino

Hi guys,

this small project that I have is kind of difficult for me so I would really appreciate your help.

The Arduino (leonardo or Yún, I don't know which works better...) should control:

1) a magnetic field generated by 2 air coils (winding N =800, max current = 0,75A, inductivity = 12mH, effective resistance = 8Ohm) using a power adapter to ensure maximum safety. The field needs to be somehow variable in it's direction and power. Maybe I could use some kind of a potentiometer?

2) a hall sensor that measures the magnetic filed. I voted for Allegro A1301/1302 because it allows ratiometric linear hall effect sensinc and is pretty easy to use.

The measurement output needs to be visualized on the computer. I found a basic code for that but have no idea if this is enough

The whole project is about showing students the secrets to magnetic fields while using different kind of materials that are in contact with the field.

It would be great if you can help me to get this project started.

Thanks and Regards,


You can start by sharing the code otherwise nobody will have an idea wether it may work or not. If there are any related links, schemas with it, share them too.

Also you may consider a cheap magnetometer module like HMC5883L that has three axes XYZ sensors and a range of +/-8Gauss, vs these halls that are less sensitive and may need amplification to read meaningful data - that depends on how much a field the air coil can generate.

at a max scale of 12x earth's magnetic field , you will not need much of a coil to sense it with 5883 or other digital compass chips


thanks for the quick response.

the How-To for building a Hall effect sensor circuit is described here:

The code looks like this:

Code for Hall Effect Sensor Circuit

//initializes/defines pin connections int outputpin= 0; //sets ground pin to LOW and input pin to HIGH void setup() { Serial.begin(9600); }

//main loop- Reads the raw value from the output pin and prints it out void loop() { int rawvalue= analogRead(outputpin); Serialprintln(rawvalue); delay(5000); }

Why do you think that these allegro sensors are not sensitive enough? The magnetic field generated by the coils should be strong but the electric currents/voltages must not be dangerous to the students.

Found the board that you mentioned here:

Looks good!

Well I don't know if the linear sensors are not sufficient, I just found they-re specified with a sensitive of 2.5mV/Gauss, with 2.5V neutral.

That linked directly to an analog input gives you a range -/+1000 gaus, with 10 bits it means you can read with a 2Gauss acuracy, 1000 steps betweem -1000 and +1000Gauss

The 5883 can measure 4000 steps between -8 and +8Gauss (and further down to 1Gauss scale but then you-ll have greater bias from the Earth's 0.7Gauss field.

I don't know what field is produced by a coil the size you mentioned, but I bet you can either calculate it yourself or find a calculator online. Amperes, turns, area that kind of stuff

If your equations show a hall sensor is good enough for your project without extra amplification then you-re fine. For education purposes I guess a down-to-basics approach is more interesting. You can measure it with a voltmeter and show how the analog pin does what the voltmeter does, it makes more sense in a electromagnetism class than giberish about I2C programming.

Or you can use both to show how one sensor needs to be placed in the center of the coil while the other senses same current or a small magnet movement a couple feet away

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

If you use the forum search facility in the top right hand of this page and search for magnetic levitation

you will find other adruino projects that have been posted on this forum.

Hope it helps.. Tom.. :)

Hi, again
This one is interesting.

Tom… :slight_smile: