Skip to main content

Hall Effect Sensor - Detecting magnetic presence with Qwiic digital sensor

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

Qwiic Digital output example

#include "Hall-Effect-SOLDERED.h"

HallEffect_Digital_EasyC hall;

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

// Initialize sensor via EasyC (required!)
hall.begin();
}

void loop()
{
// Read sensor
bool hallReading = hall.getReading();

// Print sensor value to serial
Serial.print("Digital Hall Effect Sensor reading: ");
Serial.println(hallReading);

// Print a string depending on the measurement result
if(hallReading)
{
Serial.println("Magnet detected!\n");
}
else
{
Serial.println("No magnet detected.\n");
}

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

HallEffect_Digital_EasyC hall()

Creates digital sensor object

Returns value: none

hall.begin()

Initialises digital sensor object

Returns value: Returns true if initialization is successful, false otherwise.

Function parameters:

TypeNameDescription
uint16_taddressOptional, used for changing breakout address, default is 0x30

hall.getReading()

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

Returns value: Returns bool value, true if magnet is detected and false for no magnet detected.

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 detects presence of magnetic object.

digitalReadEasyC.ino

Example file for using Digital Hall effect sensor with easyC/Qwiic/I2C