Table of Contents

Other Sensors

 General audience classification icon  General audience classification icon

Hall sensor

A Hall effect sensor detects strong magnetic fields, their polarities and the relative strength of the field. In the Hall effect sensors, a magnetic force influences current flow through the semiconductor material and creates a measurable voltage on the sides of the semiconductor. Sensors with analogue output can measure the strength of the magnetic field, while digital sensors give HIGH or LOW output value, depending on the presence of the magnetic field.

Hall effect sensors are used in magnetic encoders for speed and rotation measurements. They can replace mechanical switches in keyboards and proximity switches because they do not require contact, which ensures high reliability. An example application can be sensing the position of rotary valves. Sample sensor is present in figure 1 and its connection to the Arduino board in figure 2.

 Hall-effect sensor module
Figure 1: Hall-effect sensor module
 Arduino Uno and Hall sensor schematics
Figure 2: Arduino Uno and Hall sensor schematics

The example code:

int hallPin = A0; //Hall sensor output is connected to the analogue A0 pin
int hallReading;  //Stores Hall sensor reading
 
void setup(void) {
  Serial.begin(9600);      //Begin serial communication
  pinMode(hallPin, INPUT); //Initialize the Hall sensor pin as an input
}
 
void loop(void) {
  hallReading = analogRead(hallPin);   //Read the analogue value of the Hall sensor
  Serial.print("Hall sensor value: "); //Print out
  Serial.println(hallReading);
  delay(10); //Short delay
}
Global Positioning System

A GPS receiver is a device that can receive information from a global navigation satellite system and calculate its position on the Earth. A GPS receiver uses a constellation of satellites and ground stations to compute position and time almost anywhere on Earth. GPS receivers (figure 3) are used for navigation only in the outdoor area because they need to receive signals from the satellites, which is complicated inside the buildings. The GPS location's precision can vary depending on the number of visible satellites, weather conditions, and current satellites' placement. The GPS receiver is often connected to a microcontroller with a serial communication port and sends information according to the NMEA scheme (figure 4).

A GPS receiver is used for device location tracking. Real applications might be, e.g., pet, kid or personal belonging location tracking.

 Grove GPS receiver module
Figure 3: Grove GPS receiver module
 Arduino Uno and Grove GPS receiver schematics
Figure 4: Arduino Uno and Grove GPS receiver schematics

The example code [1]:

#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64];    //Buffer array for data receive over serial port
int count=0;                 //Counter for buffer array
void setup()
{
    SoftSerial.begin(9600);  //The SoftSerial baud rate
    Serial.begin(9600);      //The Serial port of Arduino baud rate.
}
 
void loop()
{
    if (SoftSerial.available())  //If data is coming from software serial port 
                                 // ==> Data is coming from SoftSerial shield
    {
        while(SoftSerial.available())  //Reading data into char array
        {
            buffer[count++]=SoftSerial.read(); //Writing data into array
            if(count == 64)break;
        }
        Serial.write(buffer,count);    //If no data transmission ends, 
                                       //Write buffer to hardware serial port
        clearBufferArray();            //Call clearBufferArray function to clear 
                                       //The stored data from the array
        count = 0;                     //Set the counter of the while loop to zero 
    }
    if (Serial.available())       //If data is available on hardware serial port 
                                       // ==> Data is coming from a PC or notebook
    SoftSerial.write(Serial.read());   //Write it to the SoftSerial shield
}
 
 
void clearBufferArray()                //Function to clear buffer array
{
    for (int i=0; i<count;i++)
    {
        buffer[i]=NULL;
    }                         //Clear all content of an array with NULL
}