Skip to content

Analog/Digital Hall Sensor Wireling Tutorial

gif alternating between analog and digital board option

This Wireling lets you measure the intensity of magnetic fields via the A1454 Linear Hall Effect Sensor or the TCS40DLR Discrete Hall Switch. This particular version of the A1454 is intended to be used with ferrite type magnets.

You can read about the differences in common magnets here.

Technical Details

Allegro A1454 Hall Sensor Specs (Analog)

  • 2 factory programmed sensitivity options: 2 LSB/G (for fields up to ±1000 G) and 4 LSB/G (±500 G)
  • Temperature-stable sensitivity for NdFeB and ferrite magnets
  • I²C interface for easy integration with support for up to 127 unique addresses
  • EEPROM stores factory-programmed settings and up to 16 bytes of user information (programmable through the I²C interface)
  • Micro-power sleep mode through I²C command for minimizing power in battery-operated applications
  • Precise recoverability after temperature cycling
  • Wide ambient temperature range: –40°C to 125°C
  • 12-bit ADC with 10-bit ENOB (Effective Number of Bits)
  • Operating Voltage: 2.65V - 3.5V
  • Operating Current: 5mA (max)

Toshiba TCS40 Hall Switch Specs (Digital)

  • Omnipolar (dual detection) 
  • Open-Drain 
  • ßON = 3.4mT
  • ßOFF = 2.0mT
  • Operating Voltage: 2.3V - 5.5V
  • Operating Current: 1.0mA

TinyDuino Power Requirements

  • Voltage: 3.0V - 5.5V 

Pins Used

  • A5/SCL - I²C Serial Clock line
  • A4/SDA - I²C Serial Data line

Dimensions

  • 10mm x 10mm (.394 inches x .394 inches)
  • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 4.60mm (0.18 inches)
  • Weight: 1 gram (.04 ounces)

Background

  • The A1454 will be able to pick up readings from magnets or metals containing Ferrite or Neodymium. The Wikipedia articles may sound confusing, but basically any magnet that goes on your fridge or other things made of neodymium, like headphones or DC electric motors will give a reading.
  • Hall Sensors are commonly used in projects needing switches, like a home security system that has attachments on doors and windows that detects when a magnet is moved away (like when a door opens).
  • A Hall effect sensor can operate as an electronic switch, which can be cheaper and more reliable than a mechanical switch.
  • Linear Hall Effect Sensors, like the A1454 in this tutorial, can measure a wide range of magnetic fields rather than a digital hall sensor like the TCS40DLR Discrete Hall Switch that solely measures whether there is a magnet or not (You may notice that the A1454 gives readings from a range of 0-4096)

Materials

Hardware

Software


Hardware Assembly

Assembly gif alternating between analog and digital board option with WirelingZero and cables

Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling to Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch by editing the Analog pin used as noted in the program (for the Digital Hall), or by editing the Wireling.selectPort() (for the Analog Hall) function to match your setup.)


Software Setup

If you have not already done so, download the example sketch for the Digital or Analog Hall Sensor (found above under Software) and open it in the Arduino IDE. All the necessary files for the program are included in the zipped folder.

Make the correct Tools selections for your development board. If unsure, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


Analog Hall Effect Sensor

After uploading the program, you should see output in the Serial Monitor displaying the readings for level of magnetism, and the temperature in both degrees Celsius and Fahrenheit:

This image is the output of having no magnet near the A1454 Sensor, and then putting a magnet right in front of it.

Analog Sensor Code
/*************************************************************************
 * A1454 Hall Effect Wireling Test Code - 
 * This program will show the basic method of interfacing with the sensor 
 * by printing out the Analog values (readings from 0 to 4096 (12-bit)) on
 * the Serial Monitor.
 * 
 * Hardware by: TinyCircuits
 * Written by: Laveréna Wienclaw for TinyCircuits
 * 
 * Initiated: 6/20/2018
 * Updated: 12/04/2019
 ************************************************************************/

#include <Wire.h>               // For I2C communication
#include <Wireling.h>           // For Interfacing with Wirelings
#include "TinyCircuits_A1454.h" // For the sensor

// A sensor object, the methods will be used to interface with the A1454
TinyCircuits_A1454 hall = TinyCircuits_A1454();

// Make Serial Monitor compatible for all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
  #define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#endif

void setup() {
  // Begin communication 
  SerialMonitorInterface.begin(9600);
  SerialMonitorInterface.println("HALL LIBRARY TEST CODE");
  Wire.begin();

  // Enable & Power Wireling
  Wireling.begin();
  Wireling.selectPort(0); // This must match the port the Wireling is connected to 
                          // on the Adapter board

  hall.begin();
//  hall.wake(); 
}

void loop() {
  long mag = hall.readMag();
  long temp = hall.readTemp();
  long mode = hall.readMode();

  if (mode == 0) SerialMonitorInterface.print("AWAKE\t\t");
  else if (mode == 1) SerialMonitorInterface.print("SLEEPING\t\t");

  SerialMonitorInterface.print("Mag: ");
  SerialMonitorInterface.print(mag);
  SerialMonitorInterface.print("mW");
  SerialMonitorInterface.print('\t');

  SerialMonitorInterface.print("TempF: ");
  int tempF = ((temp * 1.8) + 32);
  SerialMonitorInterface.print(tempF);
  SerialMonitorInterface.print("°F");
  SerialMonitorInterface.print('\t');

  SerialMonitorInterface.print("TempC: ");
  SerialMonitorInterface.print(temp);
  SerialMonitorInterface.println("°C");

  delay(500);
}


Digital Hall Switch

Upload the Digital Hall Sensor program in order to detect binarily whether there is a magnet close to the sensor or not. If there is a magnet near the sensor, a 1 will be printed to the Serial monitor, and a 0 will be printed if there is not magnet detectable.

Digital Hall Switch Sensor Code
/*************************************************************************
 * TCS40 Hall Switch Sensor Wireling Tutorial:
 * This program prints the status of a magnet detected or not using a 
 * TCS40 Digital Hall Switch Wireling.
 * 
 * Hardware by: TinyCircuits
 * Code by: Laverena Wienclaw for TinyCircuits
 *
 * Initiated: 09/27/2019
 * Updated: 12/04/2019
 ************************************************************************/

#include <Wireling.h> // For interfacing with Wirelings

// Hall Sensor variables
#define magPin A0        // Corresponds to PORT# of Wireling used (Do not use A0)
bool hallOutput = 0;     // What is directly output from Wireling
bool magnetDetected = 0; // Make sense of output 

// Make Serial Monitor compatible for all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
  #define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#endif

void setup() {
  // Enable & power Wireling
  Wireling.begin();

  // Set Hall Switch Pin to input
  pinMode(magPin, INPUT);
}

void loop() {
  hallOutput = digitalRead(magPin); // If no magnet, hallOutput == 1
  magnetDetected = !hallOutput; // Flip the hallOutput so magnetDetected == 1 when there is a magnet

  SerialMonitorInterface.println(magnetDetected);
}

This Wireling does not use I²C communication, so a pin is used to interface with it, rather than the usual selectPort() I²C function.

You can use this inexpensive Wireling to make a speedometer, like it's used in the RGB LED Scooter project!


Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads