ESP32 KY-035 Analog Hall Magnetic Sensor Module
Overview
The KY-035 is an analog Hall magnetic sensor module based on the AH49E linear Hall-effect sensor. It provides an analog output voltage proportional to the detected magnetic field strength and polarity, making it ideal for applications in motor control, position sensing, and magnetic field detection.
About KY-035 Analog Hall Magnetic Sensor Module
The KY-035 Analog Hall Magnetic Sensor Module utilizes the AH49E linear Hall-effect sensor to detect magnetic fields. It outputs an analog voltage proportional to the magnetic field strength, allowing for the detection of both the presence and polarity of a magnetic field. This module is suitable for applications such as motor control, position sensing, and magnetic field detection.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
S (Signal):
Outputs an analog voltage corresponding to the magnetic field strength.Middle Pin (VCC):
Supplies power to the module, typically 3.3V to 5V.G (Ground):
Connects to the ground of the circuit.
Troubleshooting Guide
Common Issues
❌ No Output Signal
Issue: The sensor does not provide any output signal.
Solutions:
- Verify that the module is properly powered with the correct voltage (3.3V to 5V).
- Ensure all connections are secure and correctly wired.
- Check for any damage to the sensor or module components.
⚠️ Incorrect or Fluctuating Readings
Issue: The sensor outputs incorrect or unstable readings.
Solutions:
- Ensure that there are no external magnetic fields or electrical noise affecting the sensor.
- Use proper shielding and grounding techniques to minimize interference.
- Calibrate the sensor to account for any environmental factors.
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
Code Examples
Arduino Example
int sensorPin = A0; // The input pin for the sensor
void setup() {
Serial.begin(9600);
Serial.println("KY-035 Magnetic Field Detection");
}
void loop() {
int rawValue = analogRead(sensorPin);
float voltage = rawValue (5.0 / 1023.0) 1000; // Convert to millivolts
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println(" mV");
delay(1000);
}
This Arduino code initializes the serial communication and reads the analog value from the KY-035 sensor connected to pin A0. It converts the raw analog value to voltage in millivolts and prints it to the serial monitor every second.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#define SENSOR_CHANNEL ADC1_CHANNEL_6 // GPIO34
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(SENSOR_CHANNEL, ADC_ATTEN_DB_11);
printf("KY-035 Magnetic Field Detection\n");
while (1) {
int raw = adc1_get_raw(SENSOR_CHANNEL);
float voltage = raw (3.3 / 4095.0) 1000; // Convert to millivolts
printf("Voltage: %.2f mV\n", voltage);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
This ESP-IDF code configures ADC1 channel 6 (GPIO34) to read analog values from the KY-035 sensor. It converts the raw ADC value to voltage in millivolts and prints it to the console every second.
ESPHome Example
sensor:
- platform: adc
pin: GPIO34
name: "KY-035 Magnetic Field Sensor"
update_interval: 1s
filters:
- multiply: 3.3
- lambda: |-
return x * 1000; // Convert to millivolts
This ESPHome configuration sets up the KY-035 sensor connected to GPIO34 as an ADC sensor. It reads the analog voltage every second, converts it to millivolts, and logs the value. The lambda function ensures the output is in millivolts for easier interpretation.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define SENSOR_PIN 34
void setup() {
Serial.begin(115200);
Serial.println("KY-035 Magnetic Field Sensor Test");
}
void loop() {
int raw_value = analogRead(SENSOR_PIN);
float voltage = raw_value (3.3 / 4095.0) 1000; // Convert to millivolts
Serial.print("Magnetic Field Voltage: ");
Serial.print(voltage);
Serial.println(" mV");
delay(1000);
}
This PlatformIO code sets up GPIO34 as an analog input for the KY-035 sensor. It reads the raw ADC value, converts it to millivolts, and logs it to the serial monitor every second.
MicroPython Example
import machine
import time
SENSOR_PIN = machine.ADC(machine.Pin(34))
SENSOR_PIN.atten(machine.ADC.ATTN_11DB)
while True:
raw_value = SENSOR_PIN.read()
voltage = (raw_value / 4095) * 3300 # Convert to millivolts
print("Magnetic Field Voltage:", voltage, "mV")
time.sleep(1)
This MicroPython script configures GPIO34 as an ADC input for the KY-035 sensor. It reads the raw ADC value, converts it to millivolts, and prints it to the console every second.
Conclusion
The ESP32 KY-035 Analog Hall Magnetic Sensor Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.