AS5600 - Angular speed
This page contains an example demonstrating how to read the angular speed of a rotating magnet using the AS5600 magnetic position sensor.
Reading angular speed
Instead of tracking absolute angle, getAngularSpeed() tells you how fast the magnet is currently rotating. Initialization is the same as every other example, wait for begin() and magnetDetected() to succeed before reading anything:
#include "Position-sensor-AS5600-breakout-SOLDERED.h"
PositionSensor sensor;
void setup()
{
Serial.begin(115200);
Wire.begin();
if (!sensor.begin())
{
Serial.println("AS5600 not found! Check wiring. Freezing.");
while (true)
{
delay(1000);
}
}
Serial.println("AS5600 found!");
while (!sensor.magnetDetected())
{
Serial.println("Magnet not detected!");
delay(1000);
}
Serial.println("Magnet detected!");
}
void loop()
{
Serial.print("w = ");
Serial.print(sensor.getAngularSpeed());
Serial.println(" deg/s");
delay(1000);
}
sensor.getAngularSpeed()
Calculates the angular speed of the magnet by comparing the current angle reading to the previous one. By default, it triggers a fresh angle reading and returns the result in degrees per second.
Returns value: A float representing the angular speed, in the unit selected by the mode parameter.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Optional. AS5600_MODE_DEGREES (default), AS5600_MODE_RADIANS, AS5600_MODE_RPM, or AS5600_MODE_RPS. |
bool | update | Optional. True (default) triggers a fresh readAngle() call before calculating speed; false reuses the last reading. |
getAngularSpeed() works out speed from the difference between the current and previous angle reading, so the first call after begin() won't have a meaningful previous value to compare against. Give it a moment to settle once the magnet starts moving.
Running the sketch above while turning the magnet back and forth by hand produces output like this, with the sign flipping depending on which way it's currently turning:

Choosing a unit
The mode parameter picks what unit the result comes back in, useful if your project thinks in RPM (a spinning wheel) rather than degrees per second:
sensor.getAngularSpeed(AS5600_MODE_RPM); // revolutions per minute
| Constant | Unit |
|---|---|
AS5600_MODE_DEGREES | Degrees per second (default) |
AS5600_MODE_RADIANS | Radians per second |
AS5600_MODE_RPM | Revolutions per minute |
AS5600_MODE_RPS | Revolutions per second |
Full example
#include <Wire.h>
#include "Position-sensor-AS5600-breakout-SOLDERED.h"
PositionSensor sensor;
void setup()
{
Serial.begin(115200);
Wire.begin();
if (!sensor.begin())
{
Serial.println("AS5600 not found! Check wiring. Freezing.");
while (true)
{
delay(1000);
}
}
Serial.println("AS5600 found!");
while (!sensor.magnetDetected())
{
Serial.println("Magnet not detected!");
delay(1000);
}
Serial.println("Magnet detected!");
}
void loop()
{
Serial.print("w = ");
Serial.print(sensor.getAngularSpeed());
Serial.println(" deg/s");
delay(1000);
}
Angular_Speed.ino
Full example for reading the angular speed of a rotating magnet using the AS5600 sensor