Introduction to the Hall Effect Sensor
A hall effect switch is a component that provides an output based on the strength of a magnetic field. This can be used for many applications, such as a simple alarm on a door or window.
More complex applications would include the speed or direction of a motor. If a magnet is placed on a motor, as the motor is rotating, the hall effect sensor can be used to count pulses in a given amount of time. This would determine the speed of a motor. If two switches are placed near each other, we can also determine the direction of rotation. We would just need for our program to detect which switch is made first to determine this direction.
In our example, we will use the Hall Effect Sensor as a simple switch. To wire this switch, we will assume the small side (front) is facing you. The pin on the left, we will wire to 5v on our Uno board. The pin in the middle will be our ground, and the pin on the right will be our signal, which we will connect to I/O pin 2 on our Uno board.
Notice that we are also placing a 10K resistor between the left and right pin to hold the input pin 2 high until a magnetic field is detected. When a magnet is moved over the hall effect switch, the input will go low.
Using the code
To make this application work in it’s simplest form, we don’t need to write any code. We can just use the button example that is in the Arduino software already. Just click on File | Examples | Digital, and you will find the button example. Before you upload, be sure your board is set correctly, and your communication port.
If you are using this sensor for more high speed applications (such a motor speed), you will want to read up on Interrupts. When you configure an interrupt, the regular scan of the Arduino can be interrupted when the hall effect switch changes it’s value. The code for your interrupt can then count the transition, then the processor can return to it’s regular scan cycle. By using interrupts, your counts will not be near as dependent on the speed of the processor.
— Ricky Bryce