Introduction: Magnetic flux Measurement Using HMC5883 and Arduino Nano

The HMC5883 is a digital compass designed for low-field magnetic sensing. This device has a wide flux range of +/-8 Oe and an output rate of 160 Hz. The HMC5883 sensor includes automatic degaussing strap drivers, offset cancellation, and a 12-tur ADC that enables 1° to 2° compass heading accuracy. All I²C Mini Modules are designed to operate at 5VDC.

In this tutorial, we are going to explain the detailed working of HMC5883 with Arduino nano.

Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following ironware components:

1. HMC5883

2. Arduino Nano

3. I2C Cable

4. I2C Shield For Arduino Nano

Step 2: Hardware Hookup:

The hardware hookup subdivision in essence explains the wiring connections required between the sensor and the arduino nano. Ensuring correct connections is the basic necessity spell working on some system for the sought after output. So, the requisite connections are as follows:

The HMC5883 bequeath work over I2C . Hither is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you're otherwise agnostic. All you require is quaternary wires!

Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the supporte of I2C cable.

These connections are demonstrated in the pictures supra.

Step 3: Arduino Code to Measure Magnetic flux Intensity level:

Let us set out with the Arduino code now.

Spell using the sensor module with the Arduino, we admit Wire.h library. "Telegraph" library contains the functions which alleviate the i2c communicating 'tween the sensor and the Arduino board.

The intact Arduino code is inclined under for the convenience of the user:

<p>#admit<Wire.h></p><p>// HMC5883 I2C address is 0x1E(30)</p><p>#specify Addr 0x1E void apparatus()</p><p>{  </p><p>// Initialize I2C communication arsenic MASTER  </p><p>Wire.begin();  </p><p>// Initialise Serial Communicating, set baud = 9600  </p><p>Serial.begin(9600);    </p><p>// Start I2C Transmission  </p><p>Wire.beginTransmission(Addr);  </p><p>// Select configure register A  </p><p>Wire.write(0x00);  </p><p>// Determine perpendicular measurement configuration, data output rate = 0.75Hz  </p><p>Wire.write(0x60);  </p><p>// Plosive speech sound I2C Transmission  </p><p>Wire.endTransmission();</p><p>// Start I2C Transmission  </p><p>Wire.beginTransmission(Addr);  </p><p>// Prime Mode read  </p><p>Wire.write(0x02);  </p><p>// Set continuous measurement  </p><p>Wire.write(0x00);  </p><p>// Stop I2C Transmission  </p><p>Wire.endTransmission();  </p><p>delay(300);</p><p>} void loop()</p><p>{  </p><p>unsigned int data[6];  </p><p>// Start I2C Transmitting  </p><p>Wire.beginTransmission(Addr);  </p><p>// Select data register  </p><p>Telegraph.write(0x03);  </p><p>// Stop I2C Infection  </p><p>Telegram.endTransmission();</p><p>// Request 6 bytes of data  </p><p>Wire.requestFrom(Addr, 6);    </p><p>// Read 6 bytes of data  </p><p>// xMag msb, xMag lsb, zMag msb, zMag lsb, yMag msb, yMag lsb  </p><p>if(Electrify.available() == 6)  </p><p>{    </p><p>data[0] = Electrify.read();    </p><p>information[1] = Electrify.say();    </p><p>data[2] = Telegram.read();    </p><p>data[3] = Wire.read();   </p><p>data[4] = Wire.read();    </p><p>data[5] = Wire.read();  </p><p>}  </p><p>postponement(300);          </p><p>// Convert the information   </p><p>int xMag = ((data[0] * 256) + data[1]);  </p><p>int zMag = ((data[2] * 256) + data[3]);  </p><p>int yMag = ((data[4] * 256) + data[5]);    </p><p>// Output data to serial monitor  </p><p>Serial.print("Magnetic flux in X-Axis : ");  </p><p>Serial.println(xMag);  </p><p>Serial.print("Flux in Y-Axis : ");  </p><p>Successive.println(yMag);  </p><p>Serial.print("Magnetized Field in Z-Axis : ");  </p><p>Serial.println(zMag);  </p><p>delay(300);</p><p>}</p>

In telegraph program library Telegram.write() and Wire.read() is wont to write the commands and take the detector output. Favorable part of the cipher illustrates the reading of sensor output.

<p>// Read 6 bytes of information  <br>// xMag msb, xMag lsb, zMag msb, zMag lsb, yMag msb, yMag lsb   if(Wire.uncommitted() == 6)   {     information[0] = Wire.read();     data[1] = Wire.read();     data[2] = Wire.show();     information[3] = Wire.read();    data[4] = Wire.read();     data[5] = Cable.read();   }</p>

Serial.photographic print() and Sequent.println() is used to display the output of the sensor on the consecutive monitor of the Arduino IDE.

The output of the detector is shown in the picture above.

Step 4: Applications:

HMC5883 is a turn up-mount, multi-chip module designed for low-field magnetic sensing with a member interface for applications such As modest cost compassing and magnetometry. Its one to cardinal degree high level truth and preciseness enables Pedestrian Pilotage and LBS Applications.

Be the First to Dea

Recommendations

  • Anything Goes Contest 2022

    Anything Goes Contest 2022