Looking for a high level oveview of how to measure distance from magnet - Page 1
Forum section: electronics / beginners

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: August 08, 2013, 10:30:54 pm
content: Hi guys!I'm doing preliminary research for a project that will require measuring distance from a permanent magnet. Right now, everything is a bit fuzzy. I don't have any real specifications for a magnet, but it's supposed to come from a guitar pick-up and maximum distance should be around 10 cm. Exact distance isn't too important right now.So what kind of technologies should I look at? Linear hall effect ICs look like the right solution, but I can't find anyone who has them in stock in my country at the moment (switches are common, but they have Schmitt triggers inside), so that complicated the issue.Using a coil for measurement produces results while the coil is moving, but as far as I understand, the magnets are supposed to produce a constant field and that means pretty much no reading when the coil isn't moving.Any other ideas?Also how did old Gauss meters work?

author: Marco
author_rank: Super Contributor
timestamp: August 08, 2013, 11:50:31 pm
content: Quote from: AndrejaKo on August 08, 2013, 10:30:54 pmWith a magnetic core it can work, the external magnetic field shifts the B/H curve which can be measured in various ways (same principle as magnetic amplifiers). There's also AMR sensors.Some links pulled from Google describing both :http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/Magnetic__Literature_Technical_Article-documents/A_New_Perspective_on_Magnetic_Field_Sensing.pdfhttp://www51.honeywell.com/aero/common/documents/Applications-of-Magnetic-Position-Sensors.pdf

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 09, 2013, 07:49:43 am
content: How large, physically and magnetically, is the magnet you wish to detect the distance to?The reason I ask, is that at far field distances the magnetic field goes down as the distance qubed, r3!So if the magnet is 1 cm3, then at 10 cm distance, on axis, the field will be down 1000 times, more or less. This drop off is highly non-linear, of course. So with a strong rare Earth magnet, say 2000 Gauss, your field increase at 10 cm would be about 2 Gauss, roughly. At that level your test equipment is likely to be sensitive to stray magnetic fields from nearby electric conductors, not to mention the Earth's own magnetic field (about 0.5 Gauss). Meaning the setup will be positional and rotational sensitive.Old school Gauss meters are essentially very sensitive moving coil or moving magnet meters. They frequently use a mirror plus a light beam to achieve very high sensitivity.

author: woodchips
author_rank: Frequent Contributor
timestamp: August 09, 2013, 08:41:07 pm
content: You say you want to measure distance, not magnetic field strength, so why not use a ruler?

author: ejeffrey
author_rank: Super Contributor
timestamp: August 10, 2013, 12:04:12 am
content: The easy way to measure magnetic field is a hall effect sensor. You can get cheap 3-axis devices used in cell phone compasses. They have plenty of resolution (they can measure a small fraction of the earths 0.5 gauss field), I am not sure what the bandwidth is, or the dynamic range. Because of the 1/r^3, you may need a lot of dynamic range.Why does it have to be a magnetic field sensor? Can you use ultrasonic or optical rangefinding?

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: August 10, 2013, 02:19:34 pm
content: Sorry for not replying sooner! We're having a bit of bad weather here and it's killing me.Quote from: Marco on August 08, 2013, 11:50:31 pmThanks for the links! They give some interesting ideas.Quote from: ElectroIrradiator on August 09, 2013, 07:49:43 amWell physically it's about 68 mm x 17 mm x 5 mm, but unfortunately I don't have any information about it's magnetic properties and no measurement equipment available to measure the properties. Thanks for the r^3 info, for some reason I expected the field to drop with r^2, but then again magnetics weren't my strong point back when we did learn that.Quote from: woodchips on August 09, 2013, 08:41:07 pmThank you for this simple and commonly missed idea! Unfortunately, I am unable to easily obtain proper type of ruler for this task. Furthermore preliminary research shows that interfacing a ruler with the rest of the system is going to be less cost-effective than other available distance measuring solutions.Quote from: ejeffrey on August 10, 2013, 12:04:12 amA 3D compass would probably be the best solution I can get and they seem to be relatively cheap, but I'd have to go through trouble of importing some. Also, from what I can see, they usually come in small SMD packages that could complicate the issue a little bit. I'm not 100% sure of what you mean by bandwidth in this case. Can you please explain? Ultrasonic or optical systems seem to be a bit too large for this application.It seems that I missed to mention the main goal of the project in the first post, so I'll explain now. The idea is to investigate possibility of replacing a foot-pedal as a control instrument for various sound effect circuits with a magnetic field sensor. The sensor will probably end up being mounted somehow on the hand of the musician, so it should be relatively light and not depend too much on the line of sight. Musician playing an electric guitar would operate the sound effects unit by modifying the distance from the magnet in the guitar to the hand. I did take a infra-red rangefinder into consideration, but the model I have easily available is at the upper boundary of acceptable size.

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 10, 2013, 03:35:54 pm
content: Quick question: Do you intend to have some form of MCU in the 'pedal'/expression widget and if so, how much effort are you willing to spend on the software for this project?I *may* have a slightly nuts suggestion for a sufficiently sensitive detector for semi-static magnetic fields, built from inexpensive standard components. However the software would probably require a fair amount of experimentation and tweaking to get it to work reliably.

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: August 10, 2013, 04:21:56 pm
content: From the look of things, the chances of me using an MCU are around 95%.I don't have a set time limit for this, so spending some (or quite a bit) programming and tuning shouldn't be a problem. I'll be happy to give your idea a shot, if you feel comfortable sharing it.

author: hlavac
author_rank: Frequent Contributor
timestamp: August 10, 2013, 05:30:18 pm
content: Why not go for some sort of capacitive sensor? That would not require the poor rock star to be rigged with wires/pcbs... just put everything into/onto the guitar.

author: Marco
author_rank: Super Contributor
timestamp: August 10, 2013, 05:35:39 pm
content: So both the orientation of the magnet and the sensor can change in relation to each other and in relation to the earth magnetic field?This is going to be tricky to make robust, even if the field of the magnet is orders of magnitude higher than the earth magnetic field.

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: August 10, 2013, 06:03:43 pm
content: For now, it doesn't need to be robust, just to produce some output. Limitations in the sensor orientation are expected. As far as I understand it, the idea of wires on the musician is currently considered preferable to mounting the project on the guitar itself by the musician. Also could a "commonly available", simple and cheap capacitive sensor provide better results than a 3D compass in the centimeters range? From what I see, the answer is no, but then again, I'm not an expert in capacitive sensors.

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 10, 2013, 10:54:52 pm
content: Quote from: AndrejaKo on August 10, 2013, 04:21:56 pmOK then, this may or may not be worth your time.The basic idea here is that many magnetic materials, in particular the common ferrite and powdered iron cores used in RF circuits, change their magnetic properties (permeability) in the presence of exterior magnetic fields, static or otherwise.So what you can do, is build a free running LC tuned RF oscillator, where the main tuning coil is wound on some form of suitable magnetic material. If the coil is then subject to an external magnetic field, the coil changes inductance and the oscillator shifts in frequency. This effect can be quite pronounced, and magnetically tuned VCOs for the low RF range do exist, sometimes having 1:2 tuning ranges. The phenomenon also sometimes bites RF designers, when they attempt to build low noise oscillators in the presence of changing magnetic fields. Like mains transformers.More accurately: You need an MCU running off a high frequency crystal, and which can route the primary oscillator or a subharmonic thereof to an external CLK_OUT pin in some form. The MCU also need to have a serious timer/capture/counter module, the higher the maximum frequency (well above the external crystal frequency) and the higher the bit count, the better.Next, build an LC oscillator, which nominally runs at the same frequency as the MCU crystal/CLK_OUT signal. The inductor for the LC oscillator must have a ferrite or powdered iron core, I'd use some form of toroid core. After a bit of amplification, you then mix the LC oscillator signal with the MCU clock signal. Use a 74HC/AC74 dual D flip-flop. MCU_CLK on clock in, LC oscillator signal to data in. On Q/#Q you now have the live frequency difference between the two oscillators. Route this back to the MCU, to the timer/capture/compare/counter module. Depending on the MCU timer capabilities, you may want to consider running the difference frequency through the second '74 ff, cutting the frequency in half yet guaranteeing a 50/50% duty cycle.If the LC oscillator frequency is pretty close to the crystal oscillator, you can now directly measure and calculate the LC oscillator drift and deviations due to any source: Temperature, vibration and - external magnetic field.Potential problems:*) Finding a suitable source of toroidal cores, which are sufficiently sensitive. Cores used for EMI filtering of main supplies may be useful yet their high permeability almost guarantee problems with temperature drift.*) Adaptive frequency sensitivity algorithm. Due to production spread you probably cannot nail the LC oscillator frequency terribly close to the crystal. So your algorithm, which finds the current frequency change, must work with both very low (low audio) and fairly high (hundreds of KHz) frequency deviation signals. You probably have to switch around between capturing the length of a half period using, say, a 32 bit timer, and running a frequency counter off the deviation signal. Hybrid algorithms may be needed in an intermediate range. This will be the part, which makes or breaks the project. The deviations you are looking for will at any point in time be atinyfraction of the difference signal.*) If the LC oscillator is set too close to the crystal frequency, you can experience a 'zero crossing' problem when it drifts across the crystal frequency. Here you cannot know what side the LC oscillator is on, and what the exact frequency deviation is. Fun, fun, fun.*) Almost certainly need bandpass filtering of the deviation signal, to filter out both low frequency drift, and high frequency mains (~ 100 Hz) hum and vibrations.*) Will be 'interesting' to say the least, to figure out how to set the null point for your exterior magnetic field.*) Individual units may require some form of individual calibration, to set the LC oscillator close to the crystal. A trimmer capacitor may do the job, but is mechanically problematic in production and service. Rough unit calibration via a varactor diode may be an option if the MCU has an integrated DAC plus EEPROM for calibration data, yet suitable varactors may be difficult to source.*) Sensor head may need potting and electric field shielding. Potting with a RF benign substance (expanded polystyrene) to reduce vibration and increase mechanical strength, e-field shielding may be required if you want CE EMI certification.*) Inductor probably need individual, mechanical fastening to make the widget strong enough to survive on stage: Nylon screw plus bracket. (Brass also an option).But this does actually work. Ask any RF engineer, who has had his or her oscillator's phase noise ruined by a nearby mains wire or transformer.