Hall Effect sensor

The Hall Effect sensor works on the principle of the Hall Effect of magnetic fields. The sensor will generate a voltage that indicates whether the sensor is in the proximity of a magnet or not. This sensor is useful to detect vehicular presence, especially vehicles coming in and going out of the parking area.

There are ICs and modules that implement the Hall Effect. For instance, you can use a transistor, US1881. You can read about and buy this sensor from SparkFun (https://www.sparkfun.com/products/9312). This transistor may also be available in your local electronic store:

Now we can try to develop sketch program to read a magnetic value from a Hall Effect sensor. We will use the US1881. You can also use any Hall Effect chip according to your use case. Firstly, we'll make our hardware wiring as follows:

  • US1881 VCC is connected to Arduino 5V
  • US1881 GND is connected to Arduino GND
  • US1881 OUT is connected to Arduino Digital 7
  • A resistor of 10K ohms is connected between US1881 VCC and US1881 OUT

You can see the complete hardware wiring here:

We can now start writing our sketch program. We'll use digitalRead() to indicate a magnet's presence. If the digital value is LOW, we'll detect the magnet's presence. Write this program:

int Led = 13 ;  
int SENSOR = 7 ;  
int val;  
  
void setup () 
{ 
  Serial.begin(9600); 
  pinMode(Led, OUTPUT) ;    
  pinMode(SENSOR, INPUT) ;  
} 
  
void loop () 
{ 
  val = digitalRead(SENSOR); 
  if (val == LOW)  
  { 
    digitalWrite (Led, HIGH); 
    Serial.println("Detected"); 
  } 
  else 
  { 
    digitalWrite (Led, LOW);     
  } 
  delay(1000); 
} 

Save this sketch as ArduinoHallEffect.

You can compile and upload the program to your Arduino board. To see the program output, you can open the Serial Monitor tool from Arduino. For testing, you can use a magnet and put it next to the sensor. You should see "Detected" on the Serial Monitor tool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.76.7