0

I want to implement a Metal Detector app which will react to a magnetic field in the phones surroundings.

How do I read the magnetic field readings from the magnetometer on the iPhone? Does anyone have sample code for accessing the magnetometer readings directly?

Thanks!

Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126
user-123
  • 874
  • 1
  • 13
  • 34

3 Answers3

2

No. You can't.

UPDATE : there is no metal detecting components in iPhone. However, there is a magnetometer available since iPhone 3GS. The Compass App makes use of the sensor to detect direction. It just reads magnetic North, but not reading magnetic fields surrounding. Therefore, you can't make a metal detector with it.

Physics Fact: Metal does not generate magnetic fields. Magnets do.

p.s. correct me if I am wrong.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • You might want to read this: http://en.wikipedia.org/wiki/Magnetometer. "Magnetometers can be used as metal detectors: they can detect only magnetic (ferrous) metals, but can detect such metals at a much larger depth than conventional metal detectors; they are capable of detecting large objects, such as cars, at tens of meters, while a metal detector's range is rarely more than 2 meters." – Cameron Lowell Palmer Dec 06 '12 at 12:06
  • 1
    It returns CLHeading values in terms of micro-teslas. So in theory, you could make determinations that an object is near. How well you could do it would have to be determined experimentally. I think you would need to implement it and see how it goes. – Cameron Lowell Palmer Dec 06 '12 at 16:00
  • agree with you. if the `CLHeading` value is changed suddenly, there is an interference with the magnetic field. Yet, there may not be presence of metal. Could be a strong electric flux (such as an electric cable). I think the App made can be treated as a reference only. Too many factors could affect the values. – Raptor Dec 07 '12 at 02:00
  • 2
    Isn't that all that any metal detector does? Tell you that you have possibly found something. A metal detector isn't saying, "I've found with 100% accuracy metal," it says, "something has interfered with my sensor and it might be metal." – Cameron Lowell Palmer Dec 07 '12 at 09:24
2

I would recommend you look at the O'Reilly book called iOS Sensor that is coming out. They have an entire chapter (6) on the magnetometer and a sample app.

iOS Sensor Programming

Apple Sample Code for Reading the Raw Values from the Magnetometer

Jim Witte
  • 19
  • 1
  • 6
Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126
1

There is already an app which does this. Check this and this blog.

This is what the description says,

The app has an adjustable sensitivity and makes an audible sound signal if the sensitivity reaches a medium level. The phone needs to be shook once to be calibrated if you intend to use the device again.

The app makes use of the magnetometer on the iPhone to find interference with the compass to detect metal objects. Just hover the backside of your mobile, the area under the camera, over the metal and the app should find the metal and there should be an increase in sensitivity.

However I am not sure if it is a fake app or it can be really done this way. Try downloading that and check it yourself. It is a free app.

Community
  • 1
  • 1
iDev
  • 23,310
  • 7
  • 60
  • 85