Démarrer
Câblage vers l’ESP32
| Broche du capteur | Broche ESP32 | Statut | Rôle |
|---|---|---|---|
| GND | GND | Requis | Sol |
| +V | 3.3V or 5V | Requis | Alimentation |
| D0 | GPIO17 | Optionnel | Entrée numérique (n'importe quel GPIO) |
| A0 | GPIO36 | Optionnel | Entrée analogique (broche ADC) |

Code
Aucune bibliothèque à installer.
// Declaration and initialization of the input pins
int analog_input = A0; // Analog output of the sensor
int digital_input = 3; // Digital output of the sensor
void setup() {
pinMode(analog_input, INPUT);
pinMode(digital_input, INPUT);
Serial.begin(9600); // Serial output with 9600 bps
Serial.println("KY-024 Magnetic field detection");
}
void loop() {
float analog_value;
int digital_value;
// Current values are read out, converted to the voltage value...
analog_value = analogRead(analog_input) * (5.0 / 1023.0);
digital_value = digitalRead(digital_input);
//... and printed at this point
Serial.print("Analog voltage value: ");
Serial.print(analog_value, 4);
Serial.print(" V, Threshold value: ");
if (digital_value == 1) {
Serial.println("reached");
} else {
Serial.println("not reached");
}
Serial.println("-------------------------------");
delay(1000);
}
Brochage
Caractéristiques
Le KY-024 est un module de capteur Hall magnétique linéaire qui fournit des sorties analogiques et numériques. Il est équipé d'un potentiomètre pour régler la sensibilité et convient à la détection de champs magnétiques dans diverses applications.
| Caractéristique | Valeur |
|---|---|
| Weight | 1 g |
| Dimensions | 45 x 15 x 14 mm |
| Sensitivity | 1.0 mV/G min., 1.4 mV/G typ., 1.75 mV/G max. |
| Operating Voltage | 3.0V to 5.0V |

