Problem with magnetic sensor !

Hey everyone I have some questions first does anyone know why my total magnetic field changes? In my city is 0.47 gauss , but it keeps changing doesn't stay constant, any idea why this happens?
Second I wanna measure field changes that are caused from electric wires, but sensor doesn't detect those changes even though I'm measuring at 2G,does anyone know why is that?
For calibration I used Mag Master , but I tried using magneto v1.2 too but same results, I couldn't get constant output and can't detect EMF!
I'm using chinese version of hmc5883l (qmc5883l) and this is my code :

#include <QMC5883LCompass.h>


QMC5883LCompass compass;
int x, y, z;
float calibrated_values[3];  
 float M; 
void transformation(float uncalibrated_values[3])    
{
  double calibration_matrix[3][3] = 
  {
    {1.207, 0.017, 0.081},
    {-0.025, 1.195, -0.101},
    {-0.053, 0.109, 1.223}  
  };
  double bias[3] = 
  {
    17.838,
    879.807,
    -600.048
  };  
 
  for (int i=0; i<3; ++i) uncalibrated_values[i] = uncalibrated_values[i] - bias[i];
  float result[3] = {0, 0, 0};
  for (int i=0; i<3; ++i)
    for (int j=0; j<3; ++j)
      result[i] += calibration_matrix[i][j] * uncalibrated_values[j];
  for (int i=0; i<3; ++i) calibrated_values[i] = result[i];
}
void setup() {
  Serial.begin(9600);
  Wire.begin();
  setQMCup();
}


void loop() {
  
  float values_from_magnetometer[3];
  // Read compass values
  getdata();
  values_from_magnetometer[0] = x;
  values_from_magnetometer[1] = y;
  values_from_magnetometer[2] = z;
  transformation(values_from_magnetometer);
  calibrated_values[0]/=12000;
  calibrated_values[1]/=12000;
  calibrated_values[2]/=12000;
  M=sqrt(calibrated_values[0]*calibrated_values[0]+calibrated_values[1]*calibrated_values[1]+calibrated_values[2]*calibrated_values[2]);
  Serial.flush(); 
  Serial.print(calibrated_values[0]); 
  Serial.print(",");
  Serial.print(calibrated_values[1]);
  Serial.print(",");
  Serial.print(calibrated_values[2]);
  Serial.print(",");
  Serial.print(M);
  Serial.println();


  delay(250); 
}
void setQMCup()
{
  compass.setADDR(0x0D);
  compass.init();
  compass.setMode(0x01,0x04,0x00,0xC0); // (Mode_continues,50ODR,2G,64OSR)
}
void getdata(){
  
   compass.read();


  // Return XYZ readings
  x = compass.getX();
  y = compass.getY();
  z = compass.getZ();
}

The output I get :

-0.54,0.16,-0.19,0.60
-0.55,0.16,-0.19,0.60
-0.54,0.18,-0.18,0.60
-0.55,0.17,-0.18,0.61
-0.53,0.18,-0.18,0.59
-0.54,0.18,-0.18,0.60
-0.54,0.17,-0.18,0.59
-0.55,0.17,-0.19,0.61
-0.54,0.18,-0.20,0.60
-0.53,0.15,-0.21,0.59
-0.56,0.17,-0.20,0.62
-0.53,0.16,-0.20,0.59
-0.56,0.15,-0.20,0.61
-0.55,0.17,-0.20,0.60
-0.55,0.18,-0.20,0.62
-0.54,0.17,-0.19,0.60
-0.55,0.16,-0.21,0.61
-0.56,0.16,-0.19,0.61
-0.55,0.17,-0.19,0.60
-0.55,0.17,-0.19,0.61
-0.54,0.17,-0.20,0.60
-0.56,0.17,-0.21,0.63
-0.56,0.16,-0.20,0.61
-0.39,0.50,-0.23,0.68
-0.38,0.50,-0.23,0.67
-0.38,0.50,-0.25,0.68
-0.39,0.51,-0.23,0.68
-0.39,0.48,-0.24,0.66
-0.39,0.50,-0.24,0.68
-0.38,0.51,-0.24,0.68
-0.39,0.51,-0.24,0.69
-0.38,0.49,-0.24,0.67
-0.38,0.49,-0.23,0.66
-0.39,0.50,-0.23,0.68
-0.39,0.50,-0.24,0.68
-0.38,0.51,-0.22,0.67
-0.39,0.50,-0.23,0.68
-0.40,0.49,-0.23,0.67
-0.40,0.50,-0.24,0.68
-0.39,0.49,-0.24,0.67
-0.39,0.50,-0.24,0.68
-0.39,0.51,-0.24,0.68

even though I'm measuring at 2G

You need to explain your acronyms. What does the G stand for? Gauss? Gravity (g)?

The mag field can very easily be disturbed by magnets, ferrous metals or currents flowing in the vicininty

johnerrington:
You need to explain your acronyms. What does the G stand for? Gauss? Gravity (g)?

The mag field can very easily be disturbed by magnets, ferrous metals or currents flowing in the vicininty

It's for Gauss!

measure field changes that are caused from electric wires, but sensor doesn't detect those changes

Of course it does, for DC or very low frequency AC currents.

johnerrington:
You need to explain your acronyms. What does the G stand for? Gauss? Gravity (g)?

G is the standard symbol for gauss as well as the symbol for the universal
gravitation constant, but given the subject of the thread its not hard to figure it out!

If you are measuring low level magnetic fields like the earth's field you have to
remove all sources of competing magnetic field, ie anything made from iron, steel,
nickel, cobalt, gadolinium, ferrite etc, to a suitable distance. Most electronics
components have steel parts in them, note, such as resistor and capacitor end-caps,
so any PCB is likely to have a small effect on a compass.

Any permanent magnets are a much bigger problem and may need to be moved
a metre or more away as modern magnets are thousands of times stronger than
the earth's field.

If the compass chip isn't well calibrated it will not be isotropic in sensitivity, as
electronic compasses rely on a former of mu-metal to concentrate the earth's field
so its easier to detect and measure.

magnetic sensors are best placed away from other parts of the device that uses it, far from any
ferromagnetic parts.

The kind of current that will make a detectable magnetic field is measured in amps, not
milliamps - 10A is a good starting point, and try to place the wire carrying the current
within a few mm of the detector. Its way way easier to detect the field from a coil
as the currents add up with each turn.

given the subject of the thread its not hard to figure it out!

Its good practise to ALWAYS define terms when you first use them. G is NOT only the symbol for Gauss or univesal gravitation, we are pretty much limited in single characters to caps, miniscules and similarly for greek letters. Thats about a hundred at best.
Covering the whole field of science and engineering ONLY how many variables do we have?
Also people tend not to discriminate properly between caps & miniscules.
I've seen a weather forecast giving the air pressure as 1015MPa (megapascals.) Well, maybe on Jupiter?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.