Docs

RL-HSB-001 · Sensors · Hall Sensor Breakout

Example code

Reference snippets for STM32 HAL, Arduino, and MicroPython ADC integrations.

Published May 4, 2026Updated May 8, 2026Reading time ~12 min

01STM32 HAL, 12-bit ADC#

// 12-bit ADC where the ADC reference equals the board VCC.
uint16_t raw = HAL_ADC_GetValue(&hadc1);
float vcc         = 3.3f;
float sensitivity = 0.030f;  // V/mT for DRV5055A2 at 3.3 V

float vout    = (raw / 4095.0f) * vcc;
float field_mT = (vout - (vcc / 2.0f)) / sensitivity;
c

02Arduino, 10-bit ADC, 5 V supply#

const int   PIN_OUT     = A0;
const float VCC         = 5.0;
const float SENSITIVITY = 0.050;  // V/mT at 5 V

void setup() { Serial.begin(115200); }

void loop() {
  int   raw      = analogRead(PIN_OUT);
  float vout     = (raw / 1023.0) * VCC;
  float field_mT = (vout - VCC / 2.0) / SENSITIVITY;
  Serial.println(field_mT, 3);
  delay(10);
}
cpp

03MicroPython, ESP32, 3.3 V supply#

from machine import ADC, Pin
import time

adc = ADC(Pin(34))
adc.atten(ADC.ATTN_11DB)   # full 0-3.3 V range
adc.width(ADC.WIDTH_12BIT)

VCC, SENS = 3.3, 0.030

while True:
    vout     = adc.read() / 4095 * VCC
    field_mT = (vout - VCC/2) / SENS
    print("{:+.2f} mT".format(field_mT))
    time.sleep_ms(20)
python
Was this page helpful?Send feedback
Back to top