Introducing the NEW HiTechnic Magnetic Sensor

HiTechnic recently released the Magnetic Sensor. This sensor is designed to detect the magnetic field of a magnet and return a value that corresponds to the polarity and strength of the field. In this post I will present a simple program to view the sensor value and give some explanation on what kind of values you can expect from the sensor.

The Magnetic Sensor, or perhaps it should be more accurately called the Magnetic Field Sensor, has a sensor element known as a Hall effect sensor. This sensor element is capable of measuring magnetic fields. If there is no magnet near the sensor, then the value will be close to zero. But if a magnet is near the sensor then the value will change depending on the relative orientation of the magnet.

To understand how the Magnetic Sensor gets its value, you need to understand a bit about magnets. Around a magnet there is a magnetic field that can be represented by field lines that run from the north pole of the magnet to the south pole. Where these lines are close together, the magnetic field is stronger and where they are more spaced out the field is weaker. When the Magnetic Sensor is close to a magnet, try to imagine these field lines passing through the sensor on their way from the north pole to the south pole of the magnet. When these lines pass through the sensor vertically, from top to bottom, then the sensor value will be positive.

In this diagram you can see how some of the field lines are going from the north pole to the south pole through the sensor. In this situation the sensor value will be positive.

If you were to reverse the magnet, then you would get a negative value instead.

To experiment with the Magnetic Sensor I create a simple NXT-G program to display the value on the NXT screen. If you want to try this program you will first need to download and install the Magnetic Sensor Block for Mindstorms NXT Software from the downloads page.

You can download a zip file that contains the program here.
Notice that the first thing in the program is that it reads the sensor and then it passes this initial value into the loop to another Magnetic sensor block and uses it as the offset. This is necessary to make the sensor accurate when there is no magnetic field present. If you don’t set the offset is a similar way, you will likely get a small positive or negative value from the sensor even when there is no magnet present.

You can also use the NXC program that you can copy from the bottom of the Magnet Sensor product page.

To give you an idea of what to expect from the sensor, I will give you the results of some simple testing that I did with the sensor. For this testing I used a 1″ rare earth cylinder magnet that I attached to some LEGO pieces using a rubber band. I oriented the magnet so that the north pole is marked with a red beam while the south pole is marked with a black beam. I also created a simple stand so that I could postion the magnet around the sensor.


Here you see the magnet placed similar to the diagram above. In this situation the value was a bit over 200. If I turned the magnet upside down:

Then I got value below -200. I can even put the magnet on either side of the sensor and the value will remain nearly the same since the field lines are still flowing through the sensor from top to bottom.

On the other hand, when I oriented the magnet on its side, like this:

then the value is nearly zero. The reason is that the field lines are now running through the sensor from the side. The sensor only measures the component of the magnetic field that flows vertically through the sensor.

Another way to get a clear and strong reading from the magnet is to place it entirely above like this:

In this situation I still got a value that was well above 200. This orientation is useful because if you move the magnet away from the sensor then the value will still be positive though it will get less as you move it away. When I tested it the value went from about 230 right above the sensor to around 35 when I moved it 2cm away. If I moved it to 4 cm away then the value was nearly zero.

You can also position the magnet entirely below the sensor but the value will be slightly less because internally the sensor element is closer to the top of the sensor than the bottom.

I think you will find the Magnetic Sensor to be a useful addition to our sensor lineup. Use it to find hidden objects or make your robot respond to a magnet that moves under a surface. Or use it as a marker that is easy to detect. Or simply use it to experiment with magnetic fields.

As an additional bonus, the Magnetic Sensor has a low introductory price of $22.95. We are offering the sensor at this price to support the teams participating in FTC. Not involved with FTC? That’s okay. This price is available right now to everyone! After the FTC season is over the price will go up.

Enjoy!

Tags: , ,

9 Responses to “Introducing the NEW HiTechnic Magnetic Sensor”

  1. Matt Schildknecht says:

    HI,

    I’m a coach on one of the FTC teams (Roboboogie 3540). We use LabView programming language. Is there a vi for the magnetic sensor in LabView?

    Thanks
    Matt

  2. Gus says:

    You can download from Tetrix Robotics the HiTechnicLV2009-FTCUpdate which will give you a VI for the Magnetic sensor as well as for the Gyro and Acceleration Sensor. There are also new VIs for the Compass and IR Seeker included.
    Tetrix Robotics Download

  3. Bobby C says:

    I am a programmer on an FTC team, and I’m curious how close and far you can be from the magnet for it to still work. These pictures make it seem as though unless your right on it you won’t be able to read the magnet, which renders it almost useless in FTC considering the magnet is surrounded by wood and the baton, plus any parts of your robot holding the baton. So my question is, does anyone know how far away you can be from the magnet and still get an accurate reading?

  4. Gus says:

    I believe that FTC is using the same type of magnet that I am using. The magnetic field will not be affected by the wood or plastic so the material in between the sensor and the magnet should not be an issue. Regarding distance, I would think that 5cm is probably the limit to how far away you can get and still have a reasonable chance of detecting the magnet. At 5cm I get a value of about 7, this goes up to 10 at 4cm. You will want to experiment with orientation of the sensor to maximize ability to detect the hidden magnet. Also note that the value may be negative so you will want to check for above a threshold as well as below the negative of the threshold.

  5. Alexander says:

    Is this Sensor a Magnetic Sensor or a Magnetic Field Sensor?

  6. Bill Brierly says:

    I purchased the Magnetic Sensor for my grandson to use in a Robotic contest (not FLL) in his area in Florida. All we wanted it to do was for a robot to stop when it sensed a magnetic field. It works great and will make a great robot for him to use in his competition. I found anon easy way to test the sensor. Select a wait block and choose Magnetic Sensor from the list. Then place a sound block after it saying anything you want like “Goodmorning”. When the sensor crosses the field of the magnet it says “Goodmorning”. Gus, I am glad to hear you say it will read through plastic because my grandson wants to use mega blocks to hide the magnet in and lego magnetic blocks as the magnet to find. So now, since it works so well I have to buy anoter one for him. I appreciate the cheaper price it is selling for right now. I own most all of the Hitechnic sensors and more than one of several of them. Keep up the good work creating new sensors and new sample robots to build. It is great fun!

  7. NA High School says:

    Hi
    Our high school class is trying to create a program for this sensor using RobotC and can’t find any resources or examples to base our program off of. Is there anything that we can use to help us with this program.

  8. Gus says:

    There should be support for the Magnetic Sensor in the RobotC drivers pack downloadable from HiTechnic.

  9. Laura P says:

    Does anyone know where i can actually find another sample program for the magnetic field sensor? i appreciate the ones that come with the driver pack, but i dont understand half of the code. I admit I am a novice programmer but our team is doing FTC this year, and figuring out the magnetic field sensor as soon as possible would be great. If someone could just find a breakdown of how to program the sensor using RobotC, that would really be awesome.

Leave a Reply