Items you will need:
Arduino development board such as this one
What does it do?
The sensor has two outputs, an analogue output that is dependent on the strength of the magnetic field, and a digital output that will go high if the field strength goes above a threshold level set by the on-board potentiometer.Â The sensor has two outputs, an analogue output that is dependent on theÂ strength of the magnetic field, and a digital output that will go high if the field strength goes above a threshold level set by the on-board pontentiometer.Â This example program reads the status of both sensor outputs and outputs the resultÂ to the UART.
PIN 1: ANALOGUE OUT
PIN 2: GND
PIN 3: +5V
PIN 4: DIGITAL OUT
/* FILE: ARD_Keys_Hall_Effect_sensor_With_Analogue_Out_Example
You may copy, alter and reuse this code in any way you like, but please leave reference to HobbyComponents.com in your comments if you redistribute this code. This software may not be used directly for the purpose of selling products that directly compete with Hobby Components Ltd’s own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
/* Select the input pin for the sensors analogue output. */
#define HALL_SENSOR_ANA A0
/* Select the input pin for the sensors digital output. */
#define HALL_SENSOR_DIO 2
/* Initialise serial and DIO */
/* Setup the serial port for displaying the status of the sensor */
/* Configure the DIO pin the sensors digital output will be connected to */
/* Main program loop */
/* Read the sensors analogue output and send it to the serial port */
Serial.print("Sensor Value: ");
/* Read the status of the sensors digital output and if it is high
then send an alert to the UART */
Serial.println(" MAGNET DETECTED!");