Skip to main content

Hall Effect Sensor - Measuring strength of magnetic field with regular analog

This page contains a simple example with function documentation on how to take measurements using the SI7211-B-00-IV Hall effect sensor.

Analog output example

#include "Hall-Effect-SOLDERED.h"
#define HALL_EFFECT_PIN 12

// To change the reading, place a magnet in front of the sensor
// The sensor outputs a value approximately in the middle of your analogRead range
// A higher number indicates a stronger positive magnetic force
// A lower number indicates a stronger negative magnetic force

HallEffect_Analog hall(HALL_EFFECT_PIN);

void setup()
{
// Initialize serial communication
Serial.begin(115200);
}

void loop()
{
// Read sensor and store to variable
uint16_t hallReading = hall.getReading();
float hallMilliTeslas = hall.getMilliTeslas();

// Print sensor values to serial
Serial.print("Analog Hall Effect raw sensor reading: ");
Serial.println(hallReading);
Serial.print("Analog Hall Effect sensor reading in milli Teslas: ");
Serial.print(hallMilliTeslas);
Serial.println(" mT\n");

// Wait a bit until next measurement
delay(1000);
}

HallEffect_Analog hall()

Creates analog sensor object

Function parameters:

TypeNameDescription
uint16_tpinAnalog pin number for data communication

hall.getReading()

Requests a new reading from the SI7211-B-00-IV sensor.

Returns value: Returns int value from output pin

hall.getMilliTeslas()

Calculates the value of magnetic induction from current reading

Returns value: Returns float value that represents magnetic induction in milli Teslas

Sensor when magnet is not present
Sensor when magnet is not present
Serial Monitor output
Serial Monitor output
Sensor when magnet is present
Sensor when magnet is present
Serial Monitor output
Serial Monitor output

Full example

Try all of the above mentioned functions in this full example which measures the strenght of magnetic field.

analogRead.ino

Example file for using analog Hall effect sensor