Connecting Hall effect sensors to your microcontroller (MCU) is straightforward, but depends on whether you're using a digital or analog Hall sensor.
Step 1: Determine Your Sensor Type
Step 2: Wiring Diagram
Digital Hall Effect Sensor (e.g., A3144)
Pins:
- Vcc: Connect to 3.3V or 5V (check sensor datasheet)
- GND: Ground
- OUT: Connect to digital GPIO input
Circuit:
- Add a pull-up resistor (~10kΩ) between OUT and Vcc (if not already onboard).
- OUT will go LOW when a magnet is detected, HIGH otherwise.
plaintext
[ A3144 Sensor ]
Vcc --- 3.3V or 5V
GND --- GND
OUT --- GPIO (with 10kΩ pull-up to Vcc)
MCU Code (Polling Example in C):
c
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0) == GPIO_PIN_RESET) {
// Magnet detected
}
Analog Hall Sensor (e.g., SS49E)
Pins:
- Vcc: 3.3V or 5V
- GND: Ground
- OUT: Analog voltage (connect to ADC pin)
Circuit:
- No pull-up needed.
- Output voltage is typically mid-scale (e.g., ~2.5V) when no magnetic field is present.
- Varies higher or lower depending on magnetic field direction and strength.
plaintext
[ SS49E Sensor ]
Vcc --- 3.3V or 5V
GND --- GND
OUT --- ADC pin (e.g., PA0)
MCU Code (STM32 ADC Example):
c
uint32_t adc_val = HAL_ADC_GetValue(&hadc1);
// Convert to voltage
float voltage = (adc_val * 3.3) / 4095.0;
Step 3: Setup in STM32CubeMX (If using STM32)
- Digital Sensor: Configure GPIO as input, optionally with interrupt.
- Analog Sensor: Enable ADC, select correct pin, and configure sampling time.
Tips
- Check your Hall sensor's operating voltage before connecting to a 3.3V or 5V MCU.
- Use decoupling capacitors (0.1µF) near the sensor for noise filtering.
- For multiple sensors, assign each to a separate GPIO or ADC channel.
- Use interrupts for real-time edge detection with digital sensors.
Top comments (0)