Remarks

LinearHallEffectTachometer
Status Not Tested
Source code GitHub
NuGet package

A Hall effect sensor is a device that is used to measure the magnitude of a magnetic field. Its output voltage is directly proportional to the magnetic field strength through it. These sensors are commonly used for proximity sensing, positioning, speed detection, and current sensing applications.

Frequently, a Hall sensor is combined with threshold detection so that it acts as and is called a switch. Commonly seen in industrial applications such as the pictured pneumatic cylinder, they are also used in consumer equipment; for example some computer printers use them to detect missing paper and open covers. They can also be used in computer keyboards, an application that requires ultra-high reliability.

Hall sensors are commonly used to time the speed of wheels and shafts, such as for internal combustion engine ignition timing, tachometers and anti-lock braking systems. They are used in brushless DC electric motors to detect the position of the permanent magnet. In the pictured wheel with two equally spaced magnets, the voltage from the sensor will peak twice for each revolution. This arrangement is commonly used to regulate the speed of disk drives.

The following example instantiates a LinearHallEffectTachometer object, and registers the RPMsChanged event handler, and it outputs the RPMs in the output console. To trigger the event of the sensor, you can place a magnet on a rotating object like a small motor, or even a fidget spinner, and make sure that the magnet passes very close to the sensor in every rotation so it picks up the electromagnetic field and it will start measuring RPMs.

Code Example

The following example prints horizontal and vertical values ranging from -1 to 1, 0 being the center position:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp()
    {
        LinearHallEffectTachometer hallSensor;

        public MeadowApp()
        {
            Console.Write("Initializing...");

            hallSensor = new LinearHallEffectTachometer(
                inputPort: Device.CreateDigitalInputPort(Device.Pins.D02, Meadow.Hardware.InterruptMode.EdgeRising, Meadow.Hardware.ResistorMode.InternalPullUp, 0, 10),
                type: CircuitTerminationType.CommonGround,
                numberOfMagnets: 2,
                rpmChangeNotificationThreshold: 1);
            hallSensor.RPMsChanged += HallSensorRPMsChanged;

            Console.WriteLine("done");
        }

        void HallSensorRPMsChanged(object sender, ChangeResult<float> e)
        {
            Console.WriteLine($"RPM: {e.New}");
        }
    }
}

Sample projects available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object > LinearHallEffectTachometer
Namespace Meadow.Foundation.Sensors.HallEffect
Assembly Meadow.Foundation.dll

Syntax

public class LinearHallEffectTachometer : object

Constructors

LinearHallEffectTachometer(IDigitalInputController, IPin, CircuitTerminationType, UInt16, Single)

LinearHallEffectTachometer driver

Declaration
public LinearHallEffectTachometer(IDigitalInputController device, IPin inputPin, CircuitTerminationType type = CircuitTerminationType.CommonGround, ushort numberOfMagnets = null, float rpmChangeNotificationThreshold = 1F)

Parameters

Type Name Description
IDigitalInputController device

IDigitalInputController to create digital input port

IPin inputPin
CircuitTerminationType type
System.UInt16 numberOfMagnets
System.Single rpmChangeNotificationThreshold

LinearHallEffectTachometer(IDigitalInputPort, CircuitTerminationType, UInt16, Single)

LinearHallEffectTachometer driver

Declaration
public LinearHallEffectTachometer(IDigitalInputPort inputPort, CircuitTerminationType type = CircuitTerminationType.CommonGround, ushort numberOfMagnets = null, float rpmChangeNotificationThreshold = 1F)

Parameters

Type Name Description
IDigitalInputPort inputPort
CircuitTerminationType type
System.UInt16 numberOfMagnets
System.Single rpmChangeNotificationThreshold

Fields

lastNotifiedRPMs

Last notified RPM value

Declaration
protected float lastNotifiedRPMs

Field Value

Type Description
System.Single

numberOfReads

Number of reads

Declaration
protected ushort numberOfReads

Field Value

Type Description
System.UInt16

revolutionTimeStart

Revolution start time

Declaration
protected DateTime revolutionTimeStart

Field Value

Type Description
DateTime

rpms

Revolutions pers minute

Declaration
protected float rpms

Field Value

Type Description
System.Single

Properties

InputPort

Input port for the tachometer

Declaration
protected IDigitalInputPort InputPort { get; set; }

Property Value

Type Description
IDigitalInputPort

NumberOfMagnets

Returns number of magnets of the sensor.

Declaration
public ushort NumberOfMagnets { get; }

Property Value

Type Description
System.UInt16

RPMChangeNotificationThreshold

Any changes to the RPMs that are greater than the RPM change threshold will cause an event to be raised when the instance is set to update automatically.

Declaration
public float RPMChangeNotificationThreshold { get; set; }

Property Value

Type Description
System.Single

RPMs

Returns number of revolutions per minute.

Declaration
public int RPMs { get; }

Property Value

Type Description
System.Int32

Methods

OnRaiseRPMChanged()

Notify when RPMs change

Declaration
protected void OnRaiseRPMChanged()

Events

RPMsChanged

Event raised when the RPM change is greater than the RPMChangeNotificationThreshold value.

Declaration
public event EventHandler<ChangeResult<float>> RPMsChanged

Event Type

Type Description
EventHandler<ChangeResult<System.Single>>