Вернуться на страницу библиотеки модулей
int sensorPin = A0; // analog pin connected to the KY-035 signal (S) pin
int baseline; // resting value with no magnet, measured at startup
int val; // latest raw reading (0-1023 on Arduino)
int field; // signed field strength: val - baseline
void setup() {
pinMode(sensorPin, INPUT); // set analog pin as input
Serial.begin(9600); // initialize serial interface
// Measure the resting value with no magnet nearby by averaging 50 samples.
// This becomes the "zero" the field strength is measured against.
long sum = 0;
for (int i = 0; i < 50; i++) {
sum += analogRead(sensorPin);
delay(5);
}
baseline = sum / 50; // typically near 512 at 5V
}
void loop() {
val = analogRead(sensorPin); // read sensor value
field = val - baseline; // positive = one pole, negative = the other
Serial.print("raw:");
Serial.print(val);
Serial.print('\t');
Serial.print("field:");
Serial.println(field); // 0 at rest, swings + or - with a magnet
delay(100);
}
Рекомендуемые ссылки:
Arduino Analog Hall Sensor KY-035 — Pinout, Wiring & Code
KY-035 Bihor magnetic sensor – SensorKit
pdf.pdf
Analog Hall Magnetic Sensor Module(KY-035) – ArduWiki : Arduino Analog Hall Magnetic Sensor Module (KY-035) Guide
ESP32 KY-035 Analog Hall Magnetic Sensor Module Pinout