Exercise 15 - Connecting a hall sensor
1. INTRODUCTION
A hall sensor is a device, which can measure magnetic fields. The measures can realize without physical contact, for this reason hall sensor is a reliable sensor.
You can find two types of hall sensor.
· Analog: Generates intensity of magnetic field proportional output.
· Digital: Gives HIGH state with magnetic field and LOW state without it.
2. HOW TO CONNECT?
Materials:
· Arduino UNO board
· Protoboard
· Some wire Jumpers
· Hall sensor
· 220 ohms resistor
· 10k ohms resistor
· LED
The sensor used in this example is, concretely the hall sensor A3144 following its datasheet the recommended circuit to use the sensor is shown in down picture.
Looking the sensor at reference side, you should connect a 10K resistor between left and right terminal. Left terminal is also connected to 5V and Right to Pin5. Furthermore, you must connect the middle terminal to ground.
On the other hand, you must connect led to pin13 on Arduino board.EXERCISE_A (Testing the sensor) |
|
3. PROGRAMMING
This program uses a hall sensor as digital input, which can measure magnetic field density.
To use this program, you must move a magnetic field nearby to the sensor.
const int sensor=5;//Associate hall sensor to digital pin 5
const int led=13;//Associate LED to digital pin 13
void setup(){
pinMode(led,OUTPUT);//Set led as OUTPUT
pinMode(sensor,INPUT);//Set sensor as INPUT
}
void loop(){
//If sensor equals HIGH state then led turn on.
if(digitalRead(sensor)==HIGH)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
}