Hall-sensor absolute encoder Archive
An attempt at a cheap absolute encoder for our FRC robot. A ring of Hall sensors around a magnet, and the circle geometry to find the magnet, worked out by hand in C.
- Role
- Algorithm and C code
- Period
- Jul–Oct 2022
- Team
- With a teammate · Team NF
- Stack
- C · Python · Arduino

Why
In 2022 a teammate and I tried to build a cheap absolute encoder for our FRC robot. A magnet turns with the shaft, and a ring of analog Hall sensors sits around it. If each reading can be turned into a distance, every sensor gives a circle the magnet must lie on, and where the circles meet is the magnet, so the shaft angle.
What I did
I wrote the algorithm and the C code by hand: first a prototype in Python, then plain C for an Arduino, with my own small geometry library for points, lines and circles.
How it works
- Two circles: the intersection of two circles is reduced to their radical line, then a line–circle quadratic gives the two points.
- The shortcut: the code first intersects the first two circles. If one of the two points lies on every other circle too, that is the answer and it returns right away. Three circles whose centres are not on one line meet in at most one point, so the match cannot be a coincidence.
- The usual case: real readings never meet perfectly, so every pair of circles is intersected, the point closer to the magnet's path is kept from each pair, and the kept points are averaged. The search runs in buffers set up in advance, with no malloc inside it.
- Calibration is stored in EEPROM behind a versioned header.
Where it stopped
It never got past simulated readings. Turning a raw Hall reading into a distance was never written, so every test ran on distances computed from a known magnet position. It is still one of my favourite bits of math.

