Example program for the HMC1501 magnetic 90° angle sensor connected to a HX711 high precision 24-bit programmable analog-to-digital converter (ADC) .

Dependencies:   HMC1501 HX711

Example program for the HMC1501 magnetic 90° angle sensor. The HMC1501 analog output is connected to a HX711 high precision 24-bit analog to digital converter module.

HMC1501

100


The Honeywell HMC1501 is a miniature surface mount sensor for linear, 90° angular, or rotary displacement designed for magnetic saturating field sensing. The HMC1501 contains a single saturated-mode Wheatstone bridge sense element that creates an output voltage with respect to the direction of the magnetic flux passing over the sensor surface. It's a cost effective and space-efficient solution for high volume OEM designs. Applications for the HMC1501 sensor include Position Sensing, Rotary speed and angle detection, and non-contact precision location measurement systems. The HMC1501 sensor utilize Honeywell’s Anisotropic Magneto-Resistive (AMR) technology that provides advantages over hall-effectbased magnetic sensors. It is able to resolve better than tenths of a degree or tenths of millimeters, withstand large variations in magnet-to-sensor gaps, and exhibit insensitivity to shocks and vibrations.

Wiring of a connection with an HX711 Analog-to-Digital converter module:

https://os.mbed.com/media/uploads/hudakz/hmc1501_demo_wiring.png

Used libraries:

Import libraryHMC1501

Library for the HMC1501 magnetic 90° angle sensor.

Import libraryHX711

Library for communication with the HX711 24-Bit Analog-to-Digital converter.

Committer:
hudakz
Date:
Sat Sep 19 20:22:45 2020 +0000
Revision:
1:668c95f5e6f9
Parent:
0:7eed1f44df4a
Example program for the HMC1501 magnetic angle sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:7eed1f44df4a 1 #include "mbed.h"
hudakz 0:7eed1f44df4a 2 #include "HX711.h"
hudakz 0:7eed1f44df4a 3 #include "HMC1501.h"
hudakz 0:7eed1f44df4a 4
hudakz 0:7eed1f44df4a 5 //
hudakz 0:7eed1f44df4a 6 DigitalOut led1(LED1);
hudakz 0:7eed1f44df4a 7 HX711 hx711(3.2f, D2, D3, 32); // avdd in Volts, sck pin, dout pin, gain
hudakz 1:668c95f5e6f9 8 HMC1501 hmc1501(-35.5, 47.05); // minV [mV], maxV [mV]: measured by rotating a magnet in front of the chip
hudakz 0:7eed1f44df4a 9 Ticker ticker;
hudakz 0:7eed1f44df4a 10 volatile bool tick = false;
hudakz 0:7eed1f44df4a 11 //
hudakz 0:7eed1f44df4a 12
hudakz 0:7eed1f44df4a 13 /**
hudakz 0:7eed1f44df4a 14 * @brief
hudakz 0:7eed1f44df4a 15 * @note
hudakz 0:7eed1f44df4a 16 * @param
hudakz 0:7eed1f44df4a 17 * @retval
hudakz 0:7eed1f44df4a 18 */
hudakz 0:7eed1f44df4a 19 void onTick()
hudakz 0:7eed1f44df4a 20 {
hudakz 0:7eed1f44df4a 21 tick = true;
hudakz 0:7eed1f44df4a 22 }
hudakz 0:7eed1f44df4a 23
hudakz 0:7eed1f44df4a 24 /**
hudakz 0:7eed1f44df4a 25 * @brief
hudakz 0:7eed1f44df4a 26 * @note
hudakz 0:7eed1f44df4a 27 * @param
hudakz 0:7eed1f44df4a 28 * @retval
hudakz 0:7eed1f44df4a 29 */
hudakz 0:7eed1f44df4a 30 int main()
hudakz 0:7eed1f44df4a 31 {
hudakz 0:7eed1f44df4a 32 printf("Starting...\r\n");
hudakz 0:7eed1f44df4a 33 ticker.attach_us(onTick, 1000 * 1000); // 500ms
hudakz 0:7eed1f44df4a 34 hx711.powerUp();
hudakz 0:7eed1f44df4a 35 while (true) {
hudakz 0:7eed1f44df4a 36 if (tick) {
hudakz 0:7eed1f44df4a 37 tick = false;
hudakz 0:7eed1f44df4a 38 led1 = !led1;
hudakz 0:7eed1f44df4a 39 if (hx711.isReady()) {
hudakz 0:7eed1f44df4a 40 float mV = hx711.read(); // read voltage in mV
hudakz 0:7eed1f44df4a 41 printf("hx711 voltage \t= %fmV\r\n", mV);
hudakz 0:7eed1f44df4a 42 printf("hmc1501 offset \t= %f mV\r\n", hmc1501.getOffset());
hudakz 0:7eed1f44df4a 43 printf("hmc1501 angle \t= %f deg\r\n", hmc1501.angle(mV));
hudakz 0:7eed1f44df4a 44 printf("-------------------------------------------\r\n");
hudakz 0:7eed1f44df4a 45 }
hudakz 0:7eed1f44df4a 46 }
hudakz 0:7eed1f44df4a 47 }
hudakz 0:7eed1f44df4a 48 }