/Modules and Components/

Hall Effect Sensor

The following info is based on using the Freetronics Hall Effect Magnet and Proximity Sensor.


This module in it's most basic form detects the presence of a magnet. There are a number of different uses for this including:

  • detecting if a window or door was opened,
  • removal of objects, or
  • as per the Robot 1 - a wheel moving.

Freetronics Hall Effect Sensor

All of the parts on this module are of course available as separate items, but for the $10 it cost me, it was money well spent from both a convenience and time to implement perspective.


I'm working on the video for this one.


Sign up to the alerts if you want to know when I put this up.




Below defines how to hook up the Hall Effect Module and LED to work with the code in the above tab.


Hall Effect Sensor Diagram


1. Hook the Ground and Vin pins up to the appropriately labelled contacts. Ensure you hook the VIN contact in to the 5V pin and not the VIN pin on the Arduino.


2. Connect the 'OUT' contact to an available PIN (pin 8 in this case). This will notify us to turn the light on when a magnet is in the vicinity of the HE Sensor. There is also an onboard green LED that lights up for the same indication.


4. Hook up a standard red LED to the board with a 220ohm resistor.


5. See the Freetronics website for more information on this module.




The following is the sketch uploaded directly to the Arduino.


It has been set up to send back to the Serial Monitor an On/Off message to identify if there is a magnet in the vicinity of the sensor.


I have also added an LED which turns on and off as a magnet is detected.




//Following code modified from original code by Author: Bruce Allen - 23/07/09

// Set up the constant variable to read in the ping. I have set this one to Digital Pin 8 on the Arduino.
const int pwPin = 8;

// Store these values to convert the pulse in to distance.
long pulse, inches, cm;

// variable for the final distance
int distSensor = 0;

// *********************************


void setup() {
  // Intitiate Serial connection for debugging and seeing the results live
// *********************************


void loop() {

  int i = 0;
  distSensor = 0;

  // Average of 8 conesecutive readings (within 1/2 a second) to accomodate noise      and error
  for (i=0; i<8; i++) {

      // Used to read in the pulse that is being sent by the MaxSonar device.
      pulse = pulseIn(pwPin, HIGH);

      // Pulse Width representation with a scale factor of 147 uS per Inch.
      inches = pulse/147;

      //change inches to centimetres
      cm = inches * 2.54;
      //add all 8 readings together
      distSensor += cm;

      // Wait for 1/20th of a second - 50 miliseconds

  // get average of the 8 readings
  distSensor /= 8;

  // send the results back to the console on the pc to review.


  // Wait for 1/2 a second - 500 miliseconds

// *********************************