Introduction: Grove Hall Sensor - Arduino

After posting a couple of tutorials on instructables, I got a few grove sensors so I thought I would write about it, so the next couple of instructables I will using grove sensors. Seeed Studio has a wide range different sensors, but I will be writing about the most commonly used ones and these sensors will be part of more complex projects.

To start of I'm using the grove Hall Sensor, a hall sensor detects magnetic field and when you take a magnet near it it would send a signal to a micro-controller (in this case we are using an arduino).

So lets get started...

Step 1: Tools and Components

All that you need to get started is

  • Arduino UNO
  • Grove Hall Sensor
  • BreadBoard
  • LED
  • Jumper wires

The Grove Hall Sensor can be brought form Seeed Studio.

Step 2: Circuit

Now its time to hook up the connections, the connections goes as follows -

  • VCC => Arduino +5v
  • Gnd => Arduino Gnd
  • Sig => Arduino D2

Then upload the code below to check the connections.

void setup()  {<br>  Serial.begin(9600);
  pinMode(2,INPUT);
}
void loop()  {
  while(1)  {
    delay(500);
    if(digitalRead(2)==LOW)  {
      Serial.println("Magnet in range");
    }
    else  {
      Serial.println("Magnet out of range");
    }
  }

}

If everything went fine you should have "Magnet out of range" outputed in the serial monitor and "Magnet in range" when the magnet is close to the IC.

Step 3: Control and LED

In this step I'm going to show you how to control an LED, such that when you bring a magnet close to the Sensor the LED will glow.

Connect the anode of the led to digital pin 6 and the cathode to Gnd.

After connecting the LED upload the code -

void setup() <br>{ 
     pinsInit(); 
} 
  
void loop()  
{ 
    if(isNearMagnet())//if the hall sensor is near the magnet? 
    { 
        turnOnLED(); 
    } 
    else 
    { 
        turnOffLED(); 
    } 
} 
void pinsInit() 
{ 
    pinMode(HALL_SENSOR, INPUT); 
    pinMode(LED,OUTPUT); 
} 
 
/*If the hall sensor is near the magnet whose south pole is facing up, */ 
/*it will return ture, otherwise it will return false.                */ 
boolean isNearMagnet() 
{ 
    int sensorValue = digitalRead(HALL_SENSOR); 
    if(sensorValue == LOW)//if the sensor value is LOW? 
    { 
        return true;//yes,return ture 
    } 
    else 
    { 
        return false;//no,return false 
    } 
} 
void turnOnLED() 
{ 
    digitalWrite(LED,HIGH); 
} 
void turnOffLED() 
{ 
    digitalWrite(LED,LOW); 
}