Stufin
Home Quick Cart Profile

HMC5983 3-Axis 3DOF Compass Magnetometer Module

Buy Now on Stufin

Sensitivity

0.5 mGauss/LSB

Dynamic Range

8 Gauss

Resolution

14-bit

Output Data Rate

Up to 30 Hz

Power Supply

3.3V or 5V

Communication Protocol

I2C (up to 400 kHz)

Operating Temperature Range

-40C to 85C

Storage Temperature Range

-50C to 150C

Dimensions

12mm x 12mm

Application Ideas

Electronic compasses and navigation systems

Robotics and autonomous systems

Industrial automation and process control

Geomagnetic field measurement and monitoring

Medical devices and diagnostic equipment

Conclusion

The HMC5983 3-Axis 3DOF Compass Magnetometer Module is a highly accurate and compact magnetic sensor module suitable for a wide range of applications. Its low power consumption, high sensitivity, and digital output make it an ideal component for designers and engineers working on projects that require accurate magnetic field measurements.

Pin Configuration

  • HMC5983 3-Axis 3DOF Compass Magnetometer Module Pinout
  • The HMC5983 3-Axis 3DOF Compass Magnetometer Module is a popular IoT component used for detecting the strength of magnetic fields in three dimensions. The module has 8 pins, which are explained below:
  • Pin 1: VCC
  • Description: Power supply pin
  • Function: Connect to a 3.3V to 5V power source
  • Notes: Ensure the power supply is stable and regulated to avoid affecting the module's performance
  • Pin 2: GND
  • Description: Ground pin
  • Function: Connect to the ground of the microcontroller or system
  • Notes: Provide a solid ground connection to ensure the module's stability and accuracy
  • Pin 3: SCL
  • Description: Clock pin for I2C communication
  • Function: Connect to the clock pin of the microcontroller's I2C interface
  • Notes: Ensure the SCL pin is connected to the correct clock pin on the microcontroller, usually labeled as SCL or SCK
  • Pin 4: SDA
  • Description: Data pin for I2C communication
  • Function: Connect to the data pin of the microcontroller's I2C interface
  • Notes: Ensure the SDA pin is connected to the correct data pin on the microcontroller, usually labeled as SDA or MOSI
  • Pin 5: DRDY
  • Description: Data ready pin
  • Function: Indicates when data is ready to be read from the module
  • Notes: Connect to an interrupt pin on the microcontroller to trigger data collection when the DRDY pin goes low
  • Pin 6: No Connection
  • Description: No internal connection
  • Function: Leave unconnected
  • Notes: This pin is reserved and has no internal connection, so it's essential to leave it unconnected to avoid any potential issues
  • Pin 7: No Connection
  • Description: No internal connection
  • Function: Leave unconnected
  • Notes: This pin is reserved and has no internal connection, so it's essential to leave it unconnected to avoid any potential issues
  • Pin 8: No Connection
  • Description: No internal connection
  • Function: Leave unconnected
  • Notes: This pin is reserved and has no internal connection, so it's essential to leave it unconnected to avoid any potential issues
  • Connection Structure:
  • When connecting the HMC5983 module to a microcontroller, follow the structure below:
  • VCC (Pin 1) 3.3V to 5V power source
  • GND (Pin 2) Ground of the microcontroller or system
  • SCL (Pin 3) Clock pin of the microcontroller's I2C interface (e.g., SCL or SCK)
  • SDA (Pin 4) Data pin of the microcontroller's I2C interface (e.g., SDA or MOSI)
  • DRDY (Pin 5) Interrupt pin on the microcontroller (optional)
  • Leave Pins 6, 7, and 8 unconnected
  • Important Notes:
  • Ensure the power supply is stable and regulated to avoid affecting the module's performance.
  • Use a suitable communication protocol (I2C) and address the module correctly to avoid any issues during data transmission.
  • Consult the datasheet and application notes for specific instructions on how to calibrate and use the HMC5983 module in your project.

Code Examples

HMC5983 3-Axis 3DOF Compass Magnetometer Module Documentation
Overview
The HMC5983 is a 3-axis, 3 degrees of freedom (3DOF) compass magnetometer module designed to provide accurate and reliable magnetic field measurements. This module is suitable for a wide range of applications, including robotics, navigation, and IoT devices.
Technical Specifications
Operating voltage: 3.0V to 5.5V
 Communication protocol: I2C
 Measurement range: 8.1 Gauss (x, y, z axes)
 Resolution: 14 bits (0.2 mGauss/LSB)
 Sensitivity: 1300 LSB/Gauss
 Operating temperature: -40C to 85C
Pinout
The HMC5983 module has a standard 5-pin interface:
VCC: Power supply (3.0V to 5.5V)
 GND: Ground
 SCL: I2C clock line
 SDA: I2C data line
 DRDY: Data ready interrupt pin (active low)
Code Examples
### Example 1: Basic I2C Communication using Arduino
This example demonstrates how to read the magnetic field values from the HMC5983 module using an Arduino board.
```c
#include <Wire.h>
#define HMC5983_ADDRESS 0x1E // default I2C address
void setup() {
  Wire.begin();
  Serial.begin(9600);
}
void loop() {
  uint8_t xData, yData, zData;
// Read magnetic field values
  Wire.beginTransmission(HMC5983_ADDRESS);
  Wire.write(0x03); // Register address for magnetic field values
  Wire.endTransmission();
  Wire.requestFrom(HMC5983_ADDRESS, 6);
xData = Wire.read() << 8;
  xData |= Wire.read();
  yData = Wire.read() << 8;
  yData |= Wire.read();
  zData = Wire.read() << 8;
  zData |= Wire.read();
// Print magnetic field values
  Serial.print("X: ");
  Serial.print(xData, DEC);
  Serial.print(" uT, Y: ");
  Serial.print(yData, DEC);
  Serial.print(" uT, Z: ");
  Serial.print(zData, DEC);
  Serial.println(" uT");
delay(500);
}
```
### Example 2: Calculating Heading using Python and Raspberry Pi
This example demonstrates how to calculate the heading angle from the magnetic field values using a Raspberry Pi and Python.
```python
import smbus
import math
# Define I2C bus and HMC5983 address
bus = smbus.SMBus(1)
address = 0x1E
def read_mag_data():
    # Read magnetic field values
    data = bus.read_i2c_block_data(address, 0x03, 6)
    x = (data[0] << 8) | data[1]
    y = (data[2] << 8) | data[3]
    z = (data[4] << 8) | data[5]
    return x, y, z
def calculate_heading(x, y, z):
    # Calculate heading angle in radians
    heading_rad = math.atan2(y, x)
    # Convert to degrees
    heading_deg = math.degrees(heading_rad)
    return heading_deg
while True:
    x, y, z = read_mag_data()
    heading = calculate_heading(x, y, z)
    print("Heading: {:.2f} degrees".format(heading))
    time.sleep(0.5)
```
### Example 3: Using the HMC5983 with ESP32 and MicroPython
This example demonstrates how to read the magnetic field values from the HMC5983 module using an ESP32 board and MicroPython.
```python
import machine
import utime
# Define I2C pins and HMC5983 address
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
address = 0x1E
def read_mag_data():
    # Read magnetic field values
    data = i2c.readfrom_mem(address, 0x03, 6)
    x = (data[0] << 8) | data[1]
    y = (data[2] << 8) | data[3]
    z = (data[4] << 8) | data[5]
    return x, y, z
while True:
    x, y, z = read_mag_data()
    print("X: {}, Y: {}, Z: {}".format(x, y, z))
    utime.sleep_ms(500)
```
These code examples demonstrate the basic I2C communication and magnetic field value reading from the HMC5983 module. You can modify and extend these examples to suit your specific application requirements.