Making a cheap and simple barn-door star tracker with software tangent correction for astrophotography

I like to mix hobbies, so naturally I’ve been eying astrophotography for a while. I’ve taken a time-lapse here and a moon picture there but, inspired by the folks over at /r/astrophotography,  I wanted to take it to the next level. Since the Earth is spinning, any long exposure of the night sky has star trails, so you have to make your camera counter-spin if you want clear shots. In this post, you can read about how I made a simple barn door sky tracker to do this.

Barn door sky trackers have been made at home by lots of people for a long time. There are a variety of designs with different levels of complexity and precision required. I thought I’d make the simplest-to-construct one, a Haig mount. To correct he tangent error, I decided to use a cheap microcontroller (MCU) and have it speed up appropriately via software. Fun!

With/without tracker

The Math

The math behind this is fun mostly because it’s straight out of high school and you finally at long last get to use it. Here’s the basic design:

Cartoon of barn door tracker

The angle must increase at a constant rate based on the rotation of the Earth. We all know the rate the world turns so we can get explicit expressions for the angle as a function of time.

Since the Earth is also rotating around the Sun, it turns out that it actually takes more like 23 hours, 56 minutes, 4.0916 seconds for the stars in the sky to rotate all the way around. This is called the Mean Sidereal Day and is the value we’ll actually use in this system. As you can now calculate, the constant angular velocity we need this thing to open at is 7.292115e-05 radians per second.

Now we are faced with a classic word problem: “What rate should we spin the motor to maintain a constant angular velocity in the above triangle?” First let’s just see how fast the screw has to rise. Bust out some trig to get an expression for y(t) and then take its derivative (don’t forget the chain rule!) and you’ll find:

Ok, now we just have to convert that to a rotation of the screw. The threaded rod I got at Hero Ace downtown is a 1/4-20 bolt, where the 20 means “there are 20 threads in 1 inch,” or in other words, “there are 20 rotations per 2.54 cm of insertion = 7.874 rotations/cm.”  Adjust accordingly if you have a different screw thread.

Let’s plot the rotations per minute required to match the Earth’s rotation for varying values of L my multiplying dy/dt [cm/minute] by 7.874 [rotations/cm] for 90 minutes.

Rotation rate graphNote: You can check out the Python code used to do these calculations here.

As you can see, the rate changes with time! This is called “the tangent error” and it’s caused by the fact that the acorn nut is sliding along the hypotenuse as the “barn door” opens (see schematic above). There are a bunch of ways people have dealt with it. One is to use a curved screw. Another is to put a specially-shaped cam where the acorn nut contacts the top board. But for this project, I’m simply going to speed up the motor as time goes on if I do a very long exposure. Not having a proper shop, I prefer to use simple physical construction and deal with it in code. If you’re doing 5-10 minute exposures, this issue won’t get to you. Note also that if you have a constant 1 RPM motor, a 29cm L is about right for you.

Putting it together

I bought some stuff at the local ACE hardware store to put this together. They had pretty much everything I needed in the hardware department. ACE Hardware Receipt

Picture of hardware

My steps:

  • Cut boards to size. I chose my total board length as a few inches longer than the 29cm I wanted between my hinge and the shaft. Note that you want to give the top board enough space to open and still contact the shaft, so give it at least 2-3 inches, and longer if you want even longer exposures.
  • Attach hinge
  • Attach slide plate if you have one (not sure if needed)
  • Measure out L from hinge pin and drill hole in bottom board
  • Apply epoxy to tee-nut for drive shaft and hammer it in place
  • Epoxy small washers to the top of rails
  • Stick motor shaft in drive hole and mark location of rails
  • Drill 1/8″ holes for 1/8″ rails on bottom board and slide them in
  • Drill hole for ball mount on top board
  • Mount camera and have a friend help balance it to try to figure out where the center of gravity is on the bottom board. Choose a spot and drill and install 2nd tee-nut for bottom tripod mount. I ended up moving mine from the bottom to the top (so the tripod screw pulls it into the wood, not out) and getting a really long tee-nut for better stability. Then I can really crank down on the tripod screw so the thing stays steady.
  • Drill out 1/4″ hole in one side of 5mm coupling nut to attach drive shaft to motor
  • Screw threaded rod into main hole, install acorn nut on top
  • Put motor on tails and fire it up!

Loud video warning:


In the barn

The sky tracker all put together

Programming the Stepper Motor/MCU

Before I started this project, I happened to have a bag full of stepper motors (like these) and their controllers, and also a bag full of ESP8266 microcontrollers (like these). These are both extremely cheap (like $5 each) items and so I figured they’d be fun to apply for this. ESP8266’s even have Wifi if you want to get super fancy but I didn’t use that here.

NOTE: If you’d rather not bother with a MCU and variable-speed motor, you can do very well just skipping this step and using a much simpler 1 RPM motor and a L of 29 cm.

 

Using instructions from here, I got my ESP8266 all hooked up and ready to program using the Arduino IDE. Here’s a good intro to spinning these kinds of motors with code.

Calibration of the ESP8266 delay

First thing I wanted to do was just double check that the timing would be precise enough for what I need (mostly I just wanted to fire up the scope). I got the motor turning with a 5 ms delay, double-stepping and took this measurement from one of the 4 pins:

Oscilloscope screen grabPretty close to that 10 ms we’d expect. Looks good to me. Here’s the code:

Timers, user input, and the accelerating motor

Now for the real deal, let’s code up what we need to do to correct the tangent error and have other practicalities. I was using barebones code for testing and realized it was a pain to reverse my motor (I had to remove wires and rails and twist it by hand. So I decided to add a button to control reversing and stuff.

The motor starts up when you power it up and does its thing. If you press the button once, it reverses all the way back to exactly the starting point (it remembers!), then it stops. If you press the button again, it starts back up.

The delay call in the code above is fine and all, but when the loop step is more complicated (i.e. computing our changing rate), there’s a chance we will not get the right timing. For these kinds of things, there are timers and interrupts. Basically, you write a callback function and register it to be called whenever a specific timer times out. Check it out: (update: this code is available on github)

(That bit about setting the timer at the end of the callback took some trial-and-error… it kept crashing around 4.2 billion clock cycles. Turns out that’s the max unsigned long int value. Neat. )

Portable use and Power Consumption

Stars are better when it’s darker, and that often requires remote operation. This thing runs off a USB port so if you have one of those external batteries, that should work. I tried a few options here, including a big deep-cycle battery that I use for ham radio for the really long hauls.

Through a 12V-to-5V converter, I measured 0.189 Amps, yielding 2.27 Watts. So my huge 20Ah battery could run it for 4 full days. More practically, 3 of those common lightweight Li-ion 18650s chained together would run it for over 2 days (wow). So that’s nice.

Polar alignment

It’s important to get everything aligned so it works right. You have to make sure:

  • Your finderscope is aligned with the hinge axis (swing it and make sure a faraway thing like a star stays in the middle).
  • Your finderscope is pointed at the celestial pole (close to Polaris, but not right on it)

I set a straw on my hinge and aimed it at a tower crane in the distance. Then I pointed the camera at the same crane and rotated it. With some adjustment it didn’t rotate too much, so at that point I could point the camera at Polaris, lock in the tripod, and be off.

For the longer term, I ordered one of those red-dot things from the internets because my dad got one years ago for his telescope and it was great. Once get it aligned I can just point-and-go.

UPDATE: I got it (see picture in angular calibration section below) and it is perfect.

First attempts at using

I tried it out with the straw-on-the-hinge alignment and got it sort-of aligned, to the point that I couldn’t wait to turn it on and try it. This was from downtown downtown Seattle so the light pollution was pretty intense. Fortunately I shot in RAW and could get some stars out of it.

Test number 1: It works!

With/without tracker

Then I just pointed it around and did what I could.

Downtown Seattle Stars. No they don’t look like that with the human eye.
Jupiter and moons
Our Moon
Seattle under the stars

Not bad. It wasn’t perfectly aligned so I’ll do more serious tests once I get that done and head to some actual dark sky.

Precise Angular Velocity Calibration

Just to check my math a bit more, I got a digital level and figured out how to get it to dump data to my PC. Then I let it run with my tracker for a while and did some least-squares fitting to see how it was working.

Pic of level sitting on tracker
Calibrating the barn-door tracker with a digital level. Note also the red-dot sight for alignment.
Graph of data with line through dots and equation
Acquired data with least-squares linear fit

So I measured a nice and constant 7.255e-5 radians/second over 10 minutes. That’s within 0.5% of the right answer. I can now adjust my target in software to speed it up by 0.5% and get it really accurate! The calibration software is also available on github.

Future work

Get a telescope. Learn how to stack photos.

Some references

11 thoughts on “Making a cheap and simple barn-door star tracker with software tangent correction for astrophotography”

  1. Neat write up and project, thank you. Be fun to build. First look, seems you have a nice solution for attaching a stepper motor to the threaded rod. Can you let us know how/ part number please

  2. The other way I have seen this done is for the rod to be affixed to the top plate and bent around an arc with R = “distance to hinge” and have the nut driven by a gear or rubber timing belt.

    Both methods are valid, with yours seeming to be easier to software troubleshoot for minor errors. The arced rod version lets you find tune with a potentiometer or adjustable PWM, on the other hand. Makes for a simpler electronic build.

    1. I saw those too and that should work great. You can also attach a shaped cam to the top plate to do the correction. I just wanted to throw a twist into the mix with this software-heavy option.

  3. Could you give a list of the parts. I know you show the receipt, but a list of hardware would be great.

    Please thanks,

    Ken

    1. Ah. Ok so the constants D1, D2, etc. are defined in mine because I have my board set as the “Wemos D1 R2 & mini” in the Board Manager, which was the particular ESP8266 package I purchased. They just point to certain pin numbers as mapped here: https://github.com/esp8266/Arduino/blob/master/variants/d1_mini/pins_arduino.h

      D1 is actually pin 5, etc. Your board may vary. Just point to the pin number you’re plugged into as integers if you have some other board.

      1. Thanks so much for the quick reply. Actually it was the serial driver… eek!

        On another note, how long is the 1/4 20 bolt?

Leave a Reply

Your email address will not be published. Required fields are marked *