how to detect a metal using magnetic sensor in android phone? -


  1. i want detect metal using magnetic sensor values. getting values continuously x=30.00 ,y=-20.00 ,z=-13.00

  2. now want know how use these values detecting metal(mathameticalcalu,formulas)

code is

sensormanager = (sensormanager) getsystemservice(sensor_service); // compass sensor (ie magnetic field) mycompasssensor = sensormanager.getdefaultsensor(sensor.type_magnetic_field);  float azimuth = math.round(event.values[0]); float pitch = math.round(event.values[1]); float roll = math.round(event.values[2]); 

to detect metal, have check intensity of magnetic field, i.e. magnitude of magnetic field vector.

float mag = math.sqrt(x^2 + y^2 + z^2); 

then need compare value expected value of magnetic field @ location on earth. luckily, android provides functions so. @ geomagneticfield, reference here https://developer.android.com/reference/android/hardware/geomagneticfield.html

then if value reading out of sensors quite far expected value, there's "something" (you guessed it, metal) disturbing earth magnetic field in vicinity of sensor. test implement instance following:

if (mag > 1.4*expectedmag || mag < 0.6*expectedmag) {     //there high probability metal close sensor } else {     //everything normal } 

you should experiment bit 1.4 , 0.6 values fits application. note never going work 100% of time because magnetic sensors on smartphone quite cheap , nasty.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -