Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
documentation:microcontroleurs:arduino:modules:49e_hall_effect:index [2021/08/03 07:04] – f1sls | documentation:microcontroleurs:arduino:modules:49e_hall_effect:index [2021/08/03 07:06] (Version actuelle) – [CODE] f1sls | ||
---|---|---|---|
Ligne 46: | Ligne 46: | ||
Serial.print(" | Serial.print(" | ||
delay(2000); | delay(2000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code cpp> | ||
+ | /* | ||
+ | Analog 49E Hall Effect sensor test | ||
+ | |||
+ | Basic code for reading the analog output of the 49E hall effect sensor. | ||
+ | Sensor is connected to A0, but can be any analog input pin. | ||
+ | */ | ||
+ | const int AnalogPin = A0; | ||
+ | const float GAUSS_PER_STEP = 2.57; // Sensor outputs approx 1.9mV / Gauss. | ||
+ | // ADC step is about 4.89mV / Step for 5V operation. | ||
+ | float rawValue = 0.0; // Raw ADC Reading | ||
+ | float gaussValue = 0.0; | ||
+ | float zeroLevel = 518.0; | ||
+ | |||
+ | // | ||
+ | // Initialization | ||
+ | // | ||
+ | void setup() | ||
+ | { | ||
+ | pinMode (AnalogPin, INPUT); | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // Main | ||
+ | // | ||
+ | void loop() | ||
+ | { | ||
+ | rawValue = analogRead (AnalogPin) - zeroLevel; | ||
+ | Serial.print (" | ||
+ | Serial.println (rawValue); | ||
+ | // Reading positive relative to the South Pole, the North Pole negative | ||
+ | gaussValue = rawValue * GAUSS_PER_STEP; | ||
+ | Serial.print (" | ||
+ | Serial.println (gaussValue); | ||
+ | delay (3000); | ||
} | } | ||
</ | </ |