Using an IMU to Find Stars!

Using an IMU to Find Stars!
Five years ago, my friend bought a fancy dobsonian telescope and vowed to find Cats Eye Nebula. Well, we didn't find it (I blame the light pollution). But I did end up building a device that at least gets the telescope pointing in the right direction. Progress! Many folks use GoTo mounts or star charts to narrow in on specific celestial wonders. I enjoy a challenge though, so my approach was to use an IMU (inertial measurement unit) to track the telescopes position in the celestial sphere and guide you to anything you want. This is the same kind of device you might find in a virtual reality headset, fitbit, or even your phone. Much to my surprise, the modern MEMS sensor is more than accurate enough for this task. My approach can find stars within 0.3° on average.
Here's how I did it.
The early days
At first I had the brilliant idea of strapping a mobile device to my telescope and making an app to read the onboard sensors. And you know what? This kinda worked! Mobile phones have fully calibrated 9-DoF sensor clusters which lets it do things like compass navigation, orientation detection, fall detection, and much more. These sensors can sample the direction of gravity, magnetic north, and your angular rate-of-motion. But there were a few roadblocks I hit along the way.
- Mostly, I didn't understand the math.
- It wasn't really accurate enough for my purposes.
- Cross-device performance was not consistent.
I spent months trying to get it to work, but all my attempts failed. The integration frequency was just too low, which means if you bumped the telescope even a little - then it lost track of where you were. This wasn't going to fly, I needed something more custom.
So I built my own circuit
Overkill? Perhaps. But I was certain if I went back to first-principles, I could overcome any problem. It's just math, right? Right... (This was 3 years ago). I'm happy to report that it really was "just a math problem", but I had to learn so much along the way. Linear algebra, quaternions, direction-cosine matrices, "right-hand rule", coordinate frames. The list goes on and on.
But before I did all that, I had to build a platform to play with. And for that, I needed a sensor. I tried 3 different ones.
- The BMI270
- The ASM330
- The ICM-42688-P
If you are a drone enthusiast, you may be familiar with all of these. They're pretty common on control boards and honestly, they all had pros and cons. Each of these packages include 2 different kinds of sensors. An accelerometer and a gyroscope. Here's what they do.
Accelerometers
The accelerometer is the sensor which tells you the direction of gravity (and acceleration, if the device is under motion). For my sensor fusion application, I didn't care much about the gravity vector other than periodically. In fact, it could be polled infrequently and everything would still work. The performance here was not really important so any of these sensors would suffice.
Gyroscopes
The gyroscope is the sensor which tells you how the device is moving (typically in "degrees per second") along each of the 3 axis (X,Y,Z). These kind of sensors are typically very accurate during short durations, but they have so many other problems if you observe them for more than a few seconds.
- "Bias instability". Kinda similar to "controller drift" if you're a gamer. Basically the range of values it reports could be skewed and you need to account for it.
- "Random walk", which is a coy way of saying the bias changes over time.
- "Noise", which is to say that the sensor is just... wrong... sometimes.
- "Temperature sensitivity", which means the bias can also drift if the ambient temperature changes.
- And more fun and exciting sources of error!
Engineers have a thousand and one ways to improve the performance, but it's not usually very straightforward. So picking a sensor that mitigates these problems became a critical part of my design.
Dead reckoning
But how do these sensors actually tell you where stars are? Great question! The crux of my solution was dead reckoning. All I needed was a device that could keep track of my position given any arbitrary starting point. As long as I had a way to point the telescope towards one known star, everything else would fall into place. And with direct access to the sensors in question, I could fine-tune the frequency so that bumping into the telescope would not mess up the readings.
The general pipeline is something like this.
First, generate an initial orientation estimate. That'd be your pitch and roll, which are observable using the accelerometer. If you know the direction of gravity, clever math can be applied to unwind that vector into these angles. Then use the gyroscope to update your estimated position a few hundred times a second. This is called sensor fusion.
How do you know it's working?
Being able to "replay" my findings offline was imperative for verification. So I added an onboard memory unit to the circuit which lets me save the raw sensor readings at native frequency. This provided the flexibility to test different algorithms in a sandboxed environment.
Recording the data is not enough, I also had to build a few tools. My favorite is the 3D visualization app (pictured above) which let me actually see how the device thought it was oriented. I could scrub through time and watch it change, then compare that with the motion I actually made in real life to uncover tricky bugs and gain a better understanding of the nuanced problems.
Armed with these custom tools, I devised a few different experiments to help me actually verify the device works.
The best experiment is to find a few stars with the telescope. Save the data. And then calculate how close it got using known position information. I could iterate on my algorithm and use the average error between stars as an empirical metric. Another experiment was to find a point on the wall, turn on the device, then meander the telescope and eventually "return home". If it wasn't close to 0.00 degrees, I knew something was off.
Did it work?
Yep! The first time it started working really well I discovered a lot of cool things I didn't even know existed (like an asterism) all thanks to my device. The excitement was palpable. With a single, uncalibrated sensor (and a lot of firmware tricks) the device actually found stars within 0.3° of error (on average). This means the device can guide you to anything and it'll be close to "center of viewport" for a wide-angle telescope lens.
Perhaps not "military grade", but for a cheap MEMS sensor I think that's incredible.
Want to see for yourself?
During the month of August 2025, I'm building 20 units and I'm looking for folks to send it to. If you're interested in beta testing this thing, check out the official website https://stargraph.net
The next phase of development is going to be centered on the app. Did you know Wikipedia has an enormous database of interesting information for thousands of celestial objects? Well, I want to make it really easy to find those hidden gems with your telescope and link up the rad facts that Wikipedia has thoughtfully recorded.
Stargazing is super fun and maybe some of the work I did here will help bring renewed joy to folks who find it difficult to navigate the cosmos.