Introduction: Control Your Telescope Using Stellarium & Arduino

Picture of Control Your Telescope Using Stellarium & Arduino

I am fascinated by astronomy since the first time I looked to the night sky. Recently, I bought a 8" Newtonian telescope that came with a Dobsonian mount. It's a nice mount (cheap, portable and very easy to use), but to get what you want to see, you need to know the sky like the palm of your hands (which can be a problem to a beginner like me..!).

To help you to know the sky, there are several software's you can use and stellarium is my favorite one. Stellarium is an open source project with a lot of helpful astronomy features, including a plugin that allow a connection between a computer and a telescope controller (like celestron, meade or sky-watcher).

After a couple of nights using my telescope, I realized that it should be helpful if, at any moment, I can compare my telescope position with the position of the target that I am looking for.

You can say: Yeah! Buy a goto telescope and you will see your problem solved! Well, you are absolutely right!

However, because of my electrical background and because I like to consider myself hobbyist, my first thought was: - I can (and I will) build a DIY controller for my telescope.

Why build a controller instead buying a ready to use one?

  • It will be a lot of fun trying to do something new;
  • It's a good contribution to learn a lot of new things (otherwise skipped by using a ready to use solution) like: alt-azimuth and celestial coordinates, local sideral time, earth movement, spherical trigonometry;
  • You can control your own budget and keep it below 50USD;
  • Your telescope will be customized to fit your needs;
  • Your telescope will become "famous" among your friends;
  • If you are not interested to spend thousands in a go-to mount, this will give you a really good help when you start to point your telescope to the sky;

This instructable will guide you, step by step, how to complete your own controller using Stellarium (astronomy software) and Arduino (open-source prototyping platform based on easy-to-use hardware and software).

And, why Arduino? Well, there is not a simple answer for that... I personally prefer Arduino for several reasons, including:

  • It's cheap and easy to find;
  • It's an open source project;
  • Have a huge community and tons of information online;
  • It's easy to find libraries that can help you using a lot of different things;
  • You can easily add a lot of shields and sensors specially designed for Arduino, or you can adapt others;
  • For most of the projects, it's reliable enough;
  • It's very versatile and flexible (I/O ports, communication, etc);
  • It's user friendly;
  • Uses "C" as programming language;
  • It's easy to interact with I/O ports, both digital and analog;

Now, that you are already introduced to this "little" project, a summary of what you need to do is:

  • Find a way to place 2 position sensors (encoders) to read azimuth and altitude;
  • Connect them to a controller like Arduino;
  • Build the hardware interface (elementary electronics);
  • Program the controller to calculate coordinates and communicate with a computer;
  • Install and config Stellarium to work together with your controller;

It will cost you some time and (a lot...of) patience, but you will be pleased with the result. Watch the video above and...

- It will be worth it!

Step 1: Tools and Materials

In my opinion, a DIY project should be something that you can make in your garage using your own tools. It also should have a low budget, otherwise, it would be better if you just buy what you are looking for. Also, I always like to use recycled materials or something that I can salvage from scrap.

Tools you need:

  • Hand saw and/or jigsaw
  • Sand paper, sander, rasp
  • Drill and a drill bit set
  • Soldering iron
  • Ruler, caliper, compasses
  • Screw driver, pliers, cutter,...
  • A laptop with stellarium and arduino IDE (you can download and install both for free)


  • 2 incremental encoders, from ebay
  • 2 pulleys GT2, from ebay
  • 2 timing belts GT2 with 600mm, from ebay
  • 2 bearings 5175 (5mm hole and 5mm thick), but you can use others
  • Arduino DUE and USB cable (UNO have a lot of limitations for this project..)
  • a small proto PCB to solder the components (instead, you can work with a breadboard)
  • some screws, bolts, nuts, washers
  • 2 springs (you can remove from a pen..) or 2 rubber bands
  • metal plate (I use 2mm aluminium plate I took from an old cabinet, but steel should be fine)
  • plywood (5mm and 3 mm thick) and some pieces of wood (12x12mm)
  • wire and connectors from scrap (old serial or VGA cables, usb cables, ...)
  • solder, shrink tube, cable ties, tape, etc
  • some dupont connectors for arduino (optional)
  • black paint, wood glue, hot glue
  • 4 trimmers (10 kOhm)
  • 4 resistors (470 Ohm)

Step 2: Mechanics, Part 1 - Make Gear-wheels From a Timing Belt

Picture of Mechanics, Part 1 - Make Gear-wheels From a Timing Belt

This is a simple step that will guide you to build a gear-wheel from a timing belt.

Because we need to read 2 axis (altitude and azimuth) we need to build 2 wheels. Those gear-wheels will be attached and fixed to the mount and will be responsible to drive the encoders, as you turn your telescope around (azimuth) and up/down (altitude).

Why build a gear? First I though I could connect directly the encoders to the telescope. Then I realized it would be better if I use a gear-wheel fixed to the mount and telescope to drive the encoders. This gear will allow a smoother mechanical connection (to prevent mechanical loads on the encoder) and, more important, will allow more resolution from the encoder - by multiplying the turns of the encoder by a gear ratio. This configuration (timing belt with 300 teeth and encoder's pulley with 20 teeth) give a gear ratio of 15 (ratio = 300/20 = 15). This means, a complete telescope's turn will give 15 complete encoder's turns , so you will multiply the encoder resolution by 15!

Doing the wheel:

Start drawing a circle into a piece of 3mm plywood. Use a compasses and do not forget to make a good mark at the circle center - you will need it!

Because the GT2 timing belt have a 600mm perimeter, you should draw a circle with a 95,5mm radius (or 191mm diameter). If your timing belt have a different perimeter, you can find the circle diameter (d) doing: d=P/pi. Radius (r) is r=d/2.

I worked with a jigsaw to cut out the circle, and then I sand it with a sander, as you can see from the picture above. To have the best result, start to cut a slight bigger circle and then sand it until the timing belt can enter. To prevent gluing the belt, I let it really tight around the plywood.

Try to make the circle as perfect as you can!

After you install the timing belt (mine have 6mm width), cut the rubber excess to get it as thick as the plywood (3mm).

To provide extra stability, I cut and glued a smaller (about 20mm in radius smaller) circle (check pictures above) made out of 5mm plywood.

Drill a center hole in both wheels. This holes must have the same diameter as the existing bolts, so, I drilled a 6mm hole from the altitude whell and 10mm hole from the azimuth wheel.

Remove the timing belt and finish your work with a layer of black paint around the plywood. After the paint dry, install the timing belt again and it´s done!

Step 3: Mechanics, Part 2 - Install the Wheels

Picture of Mechanics, Part 2 - Install the Wheels

Install the altitude wheel directly to the telescope, using the existing bolt. It should be easy and fast to install and uninstall it (to transport and pack up easily).

The same way, use the existing bolt at the bottom of the mount and install the azimuth wheel on it. Add a washer and a nut (M10) to tighten the wheel. I used a wing nut instead, as it will became useful when you need to dismantle or adjust the wheel.

This is an important step:Be sure your wheels are tight enough to prevent a slip during the operation!

At this moment, you can check if the wheels are centered and straight by rotating the telescope and the mount.

Good work!

Step 4: Mechanics, Part 3 - Making the Azimuth Encoder Holder

Now that we have the wheels installed, we need to find a way to place and drive the encoders.

Feel free to use the materials you want (or you already have) and the sizes that better match your telescope and mount. Instead building a pillow block to hold the bearing, you can buy a cheap pillow block bearing from ebay. It should be faster and easier, but, because I had 2 bearings sitting on the shelf, I gave them a proper use!

To become a little more organized, I separated this step into 2 parts: this one to show how to build the Azimuth encoder holder and the next one (which is very similar) to show the Altitude holder.

Building the encoder's holders:

As you can imagine, it is not easy to obtain a perfect mechanical joint while using handcrafted tools. So, I wasted some extra time doing flexible holders (using bearings and springs). This way, I believe I can prevent undesirable loads on the encoders (that can cause damages) by turning all the mechanical operation smoother.

By doing this, I also increased the portability of everything - it should be easier placing and removing the gear-wheels, by pulling the encoder back. It will be also easier to make some future mechanical adjustments.

Instead a huge description on this step (and the next one), I will show you how it's done by using a video and some pictures (please, read all the comments carefully).

Step 5: Mechanics, Part 4 - Making the Altitude Encoder Holder

Now that we already have the Azimuth's holder, let's build, following the same principles, the Altitude's holder.

Again, because one image speaks for one thousand words, I described this step by using the images and the video above (and their comments).

If you accomplished the previous step without any major problems, this step should be a "piece of cake"!

Step 6: Mechanics, Part 5 - Put It All Working Together

Picture of Mechanics, Part 5 - Put It All Working Together

Install the encoders and test them:

Screw the holders to the telescope's mount and then install the encoders. Once again, I like to use wing nuts (see pictures).

NOTE: About the way I designed, built and attached the encoders and the wheels:

You might have noticed I had some careful not to damage the telescope and the mount, as I found a way to install all the mechanical parts without drilling, gluing or doing something that could damage or loose the telescope's value. Like this, you can place and remove the wheels and encoders from your telescope and, at the end, your telescope will be exactly the same telescope you bought (except a very tiny and imperceptible 4 holes...).

At this point, you should check again if the wheels are centered and straight, by rotating the telescope around and up/down. Be sure the operation is smooth, and, the most important thing, be sure that there is no slip between wheels and encoder's pulleys.

The video above shows you exactly what I have done so far.

You can confirm that, if you rotate the telescope one complete turn, the encoder will rotate exactly 15 times.

So far, if everything went OK, you can rest for a while!!

Step 7: Build a Box to Place the Electronics

Picture of Build a Box to Place the Electronics

It's desirable if you build a box to place the all the components, including the Arduino.

The box I made will never win a beauty contest, but it's big just enough to fit everything I need, it's light and portable and the most important, hold tight and protects the electronics.

I used 5 pieces of 3mm plywood glued together to make a 16x14x5 (cm) box, as you can check from the pictures above.

To reinforce the box, I glued some pieces of wood at the corners. The cover, as you can see, is made from a piece of acrylic. It's not mandatory to be transparent, but it should be removable. Just drill a hole at each corner to screwing it.

Drill some holes for passing the cables.

You can add a hook to hang the box in a convenient place or, like the in last image above, you can glue a piece of plywood with a hole that you can use to hang the box using an existing bolt from the mount.

NOTE: Because I also use this box for many other purposes, there are some extra cables going around. Please ignore them!

Step 8: Electronics - Make the Interface and Wire It Up

Picture of Electronics - Make the Interface and Wire It Up

After you build the box, just place the Arduino and secure it with some hot glue or even some small screws.

Connect the USB cable (I'm using the programming port on Arduino).

Building the interface:

We need to build the hardware interface for 2 reasons:

  1. Adapt the voltage level from the encoder (minimum voltage = 5V) to Arduino DUE (3.3V);
  2. Add a pull-up resistor (it's needed because the output from the encoders is a open collector).

Above, you can find the shcematics that I used for each encoder's channel. You will need to build 4 like those.

It´s a very simple interface, where a 470 ohm resistor is used to pull-up the encoder's output and a 10K trimmer is used just as a voltage divider. The trimmer's center pin is then connected to the Arduino's input pins.

I used the following configuration:

  • encoder 1, channel A - connected to pin 2
  • encoder 1, channel B - connected to pin 3
  • encoder 2, channel A - connected to pin 5
  • encoder 2, channel B - connected to pin 4

WARNING: Be sure, before you connect the encoders to Arduino, that you adjust the trimmers to output exactly 3,3V. It's very important that you not exceed 3.3V, otherwise you will damage the Arduino.

To do that safely, connect the red wire from the encoders to the +5V Arduino pin and the black wire to ground. Adjust all the trimmers until you read 3.3V at the middle pin. You might have to slightly rotate the encoder to find the "ON" position at each channel.

To became more portable, instead soldering directly the encoder wires to the PCB, I added USB connectors that I took from 2 USB cables. Solder the female ends to your PCB and the male ends to your encoders.

By doing this, just be sure you won't swap any wire - following the colors would help you a lot!

As I told before, I'm using this Arduino for other purposes, so ignore all the extra wires and components you see from the pictures above - you will not need them!

Step 9: Important Steps Before Making the Code

To become a little more "instructive", I feel that I owe you, at least, a simple explanation about the way I programmed the Arduino and the techniques I used to make (almost) any telescope "speak" with Stellarium.

Despite of involving maths, trigonometry, programming and some signal processing, don't worry, I will try not to be too extensive!

Knowing the encoders:

In a very simple way, one encoder (angle encoder or position encoder) is a device (sensor) that can read, and therefore, transmit a position or an angle.

There are a lot of types of encoders. For this specific purpose, I have chosen the incremental ones. Despite being not so easy to integrate with Arduino (programmed in C), these encoders are reliable, cheap (at least the ones I bought..!), easy to find and, the most important, they can be very accurate while having high resolution.

The major problem using this type of encoders is that they never give you their position (angle)... instead, they give you pulses...strange? So, how can we know the angle? Here's a very little explanation:

  1. There are two channels at each encoder (channel A and B);
  2. Each channel can switch between ON and OFF (0 or 1) as you turn the encoder. That is a pulse!
  3. The 2 channels are not in phase. There is a 90º lag between them. That is called a quadrature signal;
  4. By using quadrature signals, we can know the direction of movement (if one channel is leading or lagging the other);
  5. It's also possible multiply the resolution by 2 or by 4 (quadrature proprieties);
  6. We can calculate the position by counting the number of pulses (CW and CCW);

The technique: To avoid loosing pulses (because the code takes some time to run...), I used some special pins and functions on Arduino: Interrupts. So, each time that one of this pins changes his state (meaning the encoder has moved), this special pin (through the interrupt) activate a special piece of code (ISP - Interrupt Service Routine). Here you can read some extra information about using interrupts on Arduino.

This technique makes it possible to define a "time sensitive" section of code, and that was what I did to count all the pulses, with no exception.

Communication with Stellarium

Nothing too difficult here!

The Stellarium plugin works just fine with the LX200 protocol. I think it's an old and outdated protocol, but is simple to use and, for this end, works just fine.

While connected to Arduino, periodically Stellarium sends 2 strings: ":GR#" - ready to receive RA and ":GD#" - to receive DEC. The code checks this strings and then sends, to the serial port, the corresponding string with the current right ascension (RA) and declination (DEC).

Coordinate system conversion

Now, the complicated part... Every dobsonian (or altazimuth) mount uses two axis (altitude and azimuth, as you should already know!) to create a coordinate system. This system it's very intuitive and easy to use because is related with your quotidian life (go up/down and right/left...).

But, this coordinate system is very poor if you are talking of astronomy. That happens that the sky is "alive" and seems to move around continually. Actually, all the stars describes a circumference centered at the pole star. They rotate 360º in about 24H (15º per hour).

As you can imagine, if at certain moment you are pointing to one object using a certain coordinate, after a few minutes, you need to recalibrate your coordinates because the object has moved, so, altazimuth coordinates are time dependent. They also are location dependent, as you can imagine!

So, to prevent using a coordinate system that changes every single second, the astronomers have found a very ingenious way to determine the sky coordinates - the equatorial coordinate system.

Because Stellarium, through the LX200 protocol, only can read equatorial coordinates, I had to find a way to convert the readings from the telescope (altazimuth) to the equatorial coordinate system. That operation is a little bit complex because involves spherical trigonometry and some time concepts (Local Sideral Time - LST).

Everything about this conversion is done, once in a computing cycle, using the function "AZ_to EQ()".

To learn more about coordinate systems, positional astronomy or LST, you can go here, here and here...

Welcome to my world!

Step 10: Install Arduino and Load the Code!

Picture of Install Arduino and Load the Code!

Hope you are already familiar with arduino, but if you aren't, please, don't worry - there is a lot of information you can get on-line. Nevertheless, I will guide you how to start from scratch!

It's quite easy to load the code into your Arduino. If you don't have the arduino IDE, you can download it freely from here. I'm using the version 1.6.8, but others should work as well (just in case, try not to use some older versions). Just download and install into your computer.

Be sure you have installed the DUE drivers (SAM boards, 32 bits) - check images above.

Connect the USB cable to your computer and open the code (see attachments). Be sure the code files (NF_v1.ino and config.h) are inside a folder with the same name ("NF_v1").

Select, under the "tools" tab, the board (Arduino DUE - Programming port) and the port that you are using. Note that the port (port 4 in my case) can vary from computer to computer. It will be the serial port that your computer associates with Arduino.

After everything is set up, click to upload the code (Sketch > Upload).

A "Done uploading" message will show up, after a few moments, at the bottom of the screen. That means your code is compiled and uploaded into your Arduino.

After that, you are ready to go!

Step 11: Install and Config Stellarium

Picture of Install and Config Stellarium

You are almost there!

If you don´t have Stellarium installed into your computer, it's time to do so!

You can download it for free, from the Stellarium homepage.

Stellarium is a really nice software for astronomy. It features a user friendly environment and, if you choose a recent version (version 0.13.1 or ), should already integrate the Telescope plugin, so, the only thing you need to do is activate it!

Go to the configuration window and choose the "plugins" tab. Check the box to activate the plugin. The next time you open Stellarium, you should have a new tool at the bottom's bar (see pictures above).

Click on the "telescope tool" and then select "telescope configuration".

It will open a new window. At this window, choose "add telescope".

To configure your telescope, follow the images above. You only need to this one time!

One thing that is important to do: Set up your location, otherwise, all the coordinates will be wrong..

So, just click, at the left side of your screen, the location manager and add your location (I mean, your observation site location...!).

Among other things, you can customize some visualization features. Make a tour and learn how to use it!

For this purpose, it's desirable that you enable some features at the "view" and "configuration" tabs, as you can see from the pictures above.

Finally, you are ready to connect your telescope to Stellarium!

Go to the next step to learn how to do it!

Step 12: Test and Run!

Picture of Test and Run!

Now you are only a few steps from your reward!

Make sure you have everything in place (both electrical and mechanical) and run your telescope by opening the telescope's plugin. Click "configure telescope". A new window will show up and the only thing you need to do it's click "Start" and... voilá!

Wait a few seconds (10 seconds or so..) and a new object ( _Hello_ ) will appear somewhere at the Stellarium's sky. It will have the same name you gave before...! Move around and you will find it!

Perform the movement test:

Move your telescope around and up/down. You should see the object moving accordingly at Stellarium.

Do you see it? GOOD WORK!
Troubleshooting: If your object tends to move at the wrong direction (azimuth or altitude), that means your encoder channels (respectively, azimuth or altitude) are reversed. Correct them by switching the corresponding wires at Arduino or, simply, by changing the the code and load it again (see image). Please note that the Encoder 1 is the Altitude encoder and the Encoder 2 is the azimuth encoder. Use the "config.h" file to make your changes.

Set up your encoders count

Arduino must have configured how many pulses your encoders give by turn. So, using the "config.h" file, set how many pulses you have by turn and then multiply by 4. In my case, I have a 600 pulses encoder and a mechanical gear ratio of 15 times. That means I will have 9000 pulses by turn. Multiplying this number by 4, the number I wrote was 36000, as you can see from the example above. This will be the overall resolution, equivalent to an amazing 36 seconds of arc (1296000/36000). Comparatively, a full moon have about 30 minutes of arc wide (0,5º).

Align your telescope:

To keep maximum accuracy, the telescope mount should be perfectly leveled (use a bubble level).

By default, the telescope should be aligned to north (0º azimuth) and leveled horizontally (0º altitude) before connecting to Stellarium. You can do this easily by pointing the telescope to the pole star (0º north aprox.) and then move down until it's horizontal (use a bubble level...!).

Set up location and time:

Now, if you connect your telescope to stellarium, you will probably see that your telescope is not pointed to north as it should. Well don't worry... that's because your location and local sideral time (LST) are not the correct ones!

If you remember from a few steps ago, we should have both our local sideral time (LST) and location calibrated. To do that, just open the code using Arduino IDE and edit (using the tab "config.h") your current location and the right ascension (AR), as well the hour angle (H) of the pole star (at the moment you connect to Stellarium). You only need to set up you latitude. Longitude will be calculated through AR and H.

To set up your location and time, please follow the steps I described in the images above.

Load the code again and reconnect to Stellarium. The code will do the rest of the work!


Never, but never point your telescope to the sun! It can cause you irreversible blindness.

Finally, you can point your telescope to whatever you want, using Stellarium to guide you!

Hope you enjoy it, as much as I do!


ravibhat (author)2017-11-17

Hi Nelson,

Great job. I want to build something similar for my 10 inch dob. I have a couple of questions after running through your code:

1. You have chosen not to connect the encoders directly to the alt/azimuth axes. In such case I assume you have to keep a count of complete encoder revolutions since your encoder is performing 15 revolutions per one revolution of telescope. As I can see the encoders you have chosen have only A and B channels, no Z channel present. Then how are you keeping track of encoder revolutions?

2. What is the idea behind hard-coding the Polaris hour angle in the header file?

stefaco (author)2017-08-01

Hello, and it's possible to modify the code for adapt ti for equatorial mount?

NelsonFerraz (author)stefaco2017-08-02


It's possible! You only need to remove the coordinates conversion routines, so the coordinates you will reed will be the equatorial ones. Then send those coordinates to stellarium (who only works with equatorial) and that's it!

stefaco (author)NelsonFerraz2017-09-19

could you modify for me ? because it s so difficult for my level "0" on code developper .. thanks you very much

stefaco (author)NelsonFerraz2017-08-02

Ok thank you.

aniansh (author)2016-11-29

What if you add 2 stepper motors to both the geared wheel? Goto telescope?

NelsonFerraz (author)aniansh2016-12-27


Exactly! There will be my v.2 project..

Doff74 (author)NelsonFerraz2017-08-11

Amazing, I've got quite a similar telescope (orion XT10) and was searching about controling it with stellarium, then I've found your project :)

Did you started v2 ? (with stepper motors to control it)

That's what I'm planning to do also, starting with a NANO and easy drivers for stepper motors.



NelsonFerraz (author)Doff742017-08-13

Hi, not yet... I need to find a stable way to add both motors to the mount. It will be required a lot of steps per revolution, so I think I will need some kind of a gearbox or so.. If you have any ideas to do that, please let me know!

Doff74 (author)NelsonFerraz2017-08-13

Hi Nelson,

Indeed, I'm thinking about creating something for mine (an Orion XT10).

I've found something like this regarding the mechanical part.

I was thinking about something smart for the electronic part : having the angles directly given to the arduino (with this kind of device : Attaching it to the tube, you know exactly what angles it makes (no "zero" calibrating then).

And then, having it pointing to some coordinates are just mathematics in spherical coordinates :) with some stepper motors / gear adjustments.

My thought was : if stellarium can give continously the coordinates of a (moving) object, then sending it to the arduino would make the telescope track the object directly :)

NelsonFerraz (author)Doff742017-08-15


OK! Looks nice, but I would be concerned about two things. One is the accuracy that you can get from the 3 axis device.. compare it with your phone. Mine have a very low resolution and a huge error at the compass... but I don't know the device you want to use, so it could be better than I think..

The other thing is about stellarium - I think it's not possible to receive coordinates continuously as you will need. What I did in my code (my v.2 not published yet) was something like this:

- receive coordinates (after you set an object at stellarium) RA and DEC. Convert to alt/az and then recalculate coordinates every sideral second - to do that, I added timmers and a real time clock. Tell me if you found a way to get coordinates continuously from stellarium, it would save a lot of work!

JohnD829 (author)2017-08-02

work! Sorry for the long comment/questions, but if the
assumed answers to my questions below are correct it will clear up a
lot of confusion I was having with beginning a similar project.

was thinking of doing something like this but I am afraid I am
confused as to what Stellarium's role is. I wanted to make sure
I understood what Stellarium would do, so I set up the "dummy"
server, selected an object, and told it to slew to the selected
object. I assumed it would then continually send out updated
location info, but it seems like it is the other way around, right?
Stellarium sends to the telescope the RA/DEC of the object and
the scope is supposed to track the object from that point on, and it
also sends back to Stellarium it's current RA/DEC. What you are
doing here is sending that info based on your "sensors" to
Stellarium and it shows where your scope is pointed. Is that
right? If I wanted to do the opposite, say send the
RA/DEC to a raspberry pi, and have it tell me how to set the Az/Alt,
then I would need to do the EQ->Az/Alt on the raspberry pi, and
would need to have the correct location and time on the PI to do so.
In addition I would need to be able to determine the Az/Alt of
the scope. Is that right?

NelsonFerraz (author)JohnD8292017-08-13

Hi JohnD829,

That's absolutely correct! At least, using LX200 protocol you will send your RA/DEC to stellarium (need to convert your Az/Alt before) and stellarium will show your telescope "on the screen". Slew commands will be sent only once and after you press "send coordinates" at stellarium and they will be sent as RA/DEC.. I think the telescope plugin was designed assuming that the telescope have a controller installed (like an LX200 or other..), so all the calculations need to be performed using an external controller.

stefaco (author)2017-08-01

And it's adaptable on arduino nano?

NelsonFerraz (author)stefaco2017-08-02

not sure... but I think not! Use DUE instead. It will handle double precision and all the interrupt pins you need.

larrym1972 (author)2017-06-29

im using the arduino mega with no problems. my big pulley in 220 teeth and my other pulley is 20 teeth. this will give a gear ratio of 11. im using 600 pulse encoders. so 11 x 600 is 6600 pulse total and multiply by 4 is 26400 my location is 39 degrees 39 min 10 sec and polaris RA 02 hr 31 min 50 sec it does connect to stellaruim ok . when i try to move to M51 or saturn it does not move the of goes off the map. the alt/azm does not match my setting circles. i have an accuracy problem. you got any idea what could be the problem

NelsonFerraz (author)larrym19722017-07-02


The resolution looks great!

Did you tested your encoders? Have you sure every pulse is counting the right way? You also need to change the variables that contain the "resolutiom factor" (how many pulses per arc second)as described. Test and let me know.

larrym1972 (author)NelsonFerraz2017-08-02

my problem is the mega 2560 i took measurement at three different degrees. i got the output of every variables and check with calculator and number where off i going to get the arduino due or the tinker board

larrym1972 (author)larrym19722017-07-21

i check the encoder pulse count and the lat and azm counts every pulse. i did have the gear ratio wrong i thought it was 11 instead it 10. this will give 6000 pulse time 4 which is 24000 pulse but the problem remains. i discovered a new problem with both encoders. the azm start at 1 and goes to 24000 roughly when i rotated clockwise thta great but when turn back from 24000 to 1000 the next count starts at 99000 and starts counting down but never to zero. i reset and tried opposite direction and i get the same result ill keep try different thing with it

GigiG25 (author)2017-06-21

Hi Nelson, great work! I'd like to know if it is possible to use an Arduino Mega2560 instead of Due, mainly because I already have a couple of Mega at home. Best regards and thanks for sharing your project!

NelsonFerraz (author)GigiG252017-06-24

Hi, you can use, but I don't recommend. There are two problems with mega: have only 2 interrupt pins (I think...) that are not suitable to read both encoders (not impossible, with some changes at the code...). The other issue is that mega uses only 4 bytes for a double variable (the same as float) while DUE uses 8 bytes, and therefore, have more precision dealing with all the maths.


seaeagle1972 (author)2017-06-20

Hi Nelson,

Nice Work!!

Before I start playing with this, what programming changes would be needed for the southern hemisphere? I'm in Australia,



The equations I used are valid both for north and south hemisphere, so You should have no problems at all.


MiguelG91 (author)2017-06-14


He modificado un poco la electrónica con un conversor lógico de 3,3/5V.

Funciona muy bien y espero colocarlo en breve plazo en mi telescopio. Saludos desde Madrid

NelsonFerraz (author)MiguelG912017-06-16

Hola Madrid!

Muy bien!

Buenas observaciones con tu telescopio.


carticluz (author)2017-06-11

hi i was looking at the pictures and was wondering were the 2 other wires from each encoder went as they disapear into the background a bit in each picture. Do you use the other two wires at all or are they still plugged into something. (the wires that aren't channel a or b from each encoder)

NelsonFerraz (author)carticluz2017-06-13

Hi, You can see 4 wires from each encoder: Channel A, Channel B, VCC and GND. After you connect both channels from both encoders (4 wires), is left 2 VCC and 2 GND wires. Connect both VCC to one end and both GND to another end and your 8 wires will become only 6 wires..!

NelsonFerraz (author)2017-05-10


Great work!


OleksiyZ1 (author)2017-05-09

Hey, very cool project. I used it as inspiration to make similar without ANY disks or so:

KacperP11 (author)2017-04-14


You did great job, but i have few questions... Where are yours encoders, are they in motors? Will it work on arduino uno? Can I glue printed encoder discs to stepper motor's shaft and then calculate impulses from laser? Can't encoders be connected directly to arduino (I see a lot of cables and im stressed because im not good at electronics) and information sector will be only arduino? I would be really grateful for any help :)

NelsonFerraz (author)KacperP112017-04-17


Those black cylinders that you see are the encoders! This is a push-to and not a go-to - sorry there are no motors at all...

I advise you not to use UNO because of its low precision. UNO uses double variables as a normal float variables, so you will loose precision. About encoders, yes, you can print discs and read pulses, just be careful (again) with precision and accuracy. I think it's better if you buy a cheap ones..!

About electronics, there is nothing too complex, I just build a voltage divider to adapt de encoders voltage (5V) to the DUE input voltage (3.3V). If your encoders voltage is the same as arduino, you can connect them directly.

Stellarium acts as an object database and graphic interface, while arduino is responsible for reading coordinates from encoders and convert them from altazimutal to equatorial (and send them to stellarium).

KacperP11 (author)NelsonFerraz2017-04-21

Can i use 2x LM393 on the encoder disc. Two sensors on the same transparent line?

NelsonFerraz (author)KacperP112017-04-22

Why two sensors on the same line? You should have two sensors (channel A and B) mounted in quadrature so you can read 4x pulses and detect direction as well. Anyway, how do you found room to place two sensors at the same line?

KacperP11 (author)NelsonFerraz2017-04-22

I was going to make something like this: and i want to ask is this working like in Your encoder cilinders? I'm not really planning where to find room because i have encoder disc with 10cm diameter and i think i will contrive it since i get laser sensors.

NelsonFerraz (author)KacperP112017-04-23


I think there is no problem doing that, just be sure sensors are in quadrature (one channel shifted 90º) and the output pulse is the same voltage as the arduino input. One more advise: Be careful with de output wave - I believe you will experiment some bouncing problems with your home made encoder, so you will need to find a way to debounce (using hardware or software). The code I used already do some work deboucing the signals, but I can´t be sure it will work properly with your solution..

Keep me updated!

KacperP11 (author)NelsonFerraz2017-04-24

I don't really know what debouncing is, but anyway i have stepper motors and i know that my stepper motor make 200 steps per one turn its 1.8º per one step. Can't i use it like encoder :D? I could have another window in arduino to controlling speed of steps and giving informations to Your program in another window? Will it work? Which variable is it? Last thing which make me confused me its 500:12 gear ratio :[ it gives 41,6666... i think for longer time it won't work properly is it true...?

NelsonFerraz (author)KacperP112017-04-25

Hi, I see no problem using home made encoders and so on.. I was just advertising for some problems that you can face doing that. The wave you will get from your encoder is not a fancy square wave like you see in theory. Instead it will be noisy and the controller will count dozens of pulses when the encoder send only one pulse - you can make a small test by writing a small program - attach an interrupt to read an input and monitor that input. Just use a pressure switch attached to that input and you will see your input conter increasing lots of times more than the times you pressed the switch (because signal bounces...).. that's the real world..! Use that simple code to test your encoder!!

For a better understanding, just google "debouncing signals", take a small look at the images and.. you will get there!

About monitor windows, I think you can use only one but you can monitor several variables at the same time.

About gear ratio, 500:12 is your gear ratio? Shouldn't be 500*12 instead?

In my case, I have 3600 pulses by turn (600 lines * 4 * 300 /20). Anyway, if the gear ratio is not an integer, that's no problem.. the reading error will not be cumulative.

FYI, to test, I turned my telescope around more than 50 times and after that the reading error was... zero degrees.

KacperP11 (author)NelsonFerraz2017-04-27

OK my stepper motors works fine it turned lots of times on its still on the same position. About gear ratio i mean: 200(steps per turn)*500/12(number of teeth first gear and second)= 8333,333... (this number tell me how many pulses i have to make to rotate 360º my telescope) Is it possible to inform your variable to see in the stellarium my current position of telescope?

for() {



YOURvariable=YOURvariable+0,0432º // (360º/8333,333...)


NelsonFerraz (author)KacperP112017-04-30


Fell free to modify the code as you want, but I think you don't need to do nothing special for this case.

How the code works: Every time arduino receive a pulse from encoders, the volatile variables are updated (azimuth and altitude) by the ISR. Then, the angle is calculated and corresponds to seconds of arc (not degrees). If you take a look at the code, this angle is calculated using a double variable and works just fine with non integer numbers.

So, tacking your example, 8333.33 pulses will correspond do 1296000 seconds of arc. Each pulse will increase (or decrease) 155.52 seconds of arc (yes, 0,0432º), that's your resolution.

If there is some remaining error due to the calculation, don't worry, that error will not be cumulative, the only thing that is important is to keep the volatile variables well updated - everything else will depend from it.

21969661 (author)2017-04-04

Hello I am making a goto telescope and was wondering if you knew how to make stellarium output the slew commands and tracking commands to the ardunio? Any insight would be extremely helpful as this is then being passed to a raspberry pi that controls the telescope

NelsonFerraz (author)219696612017-04-05

As far as I know, Stellarium can output only a few commands. See step 9, 11 and 12 for a better understanding. You will need to activate the telescope plugin and therefore stellarium will send a string with the coordinates of the object you had chosen - see the code.
I also can advise you to take a look at the output log file that stellarium will generate (you should activate the log before.!).

NelsonFerraz (author)2017-04-03

OK! Great.

larrym1972 (author)2017-04-01

hi i did test of this project and ran into problems. my encoder i used went to my out of date meade magellan 1 for my 10" dobsonian. encoder has 1024 pulse.

the first is not stable telescope icon jump all over the place

the second is encoder 2 didnt work i even switch encoder around and got the

same result. i think the problems are the same bug

so what going on. i really need help

NelsonFerraz (author)larrym19722017-04-03


I don't fully understood what was the problem, but it seems that you have a hardware problem..

To count pulses, both encoders and both channels must be connected to interrupt pins on arduino. Are you using DUE or UNO arduino? Please note that your encoders voltage must match the input voltage at the arduino inputs.

larrym1972 (author)NelsonFerraz2017-04-03

update i found the problem. on the due all pins are interrupt but on the mega only 6pin are interrupt 2,3,18,19,20,21

larrym1972 (author)NelsonFerraz2017-04-03

im using the arduino mega 2560. the encoder output volts is -0.5v to 7v other if the supply volts 3.3 the output is 3.3. encoder1 counts good
encoder2 doesnt count. i ever switch the encoder and tried different pins and change from 4,5 to 6,7 i get the same results

NelsonFerraz (author)2016-10-13


no thinking to move to raspberry...

JJV6 (author)NelsonFerraz2016-10-21

Have you tried this on an equatorial mount? This would be so helpful for imaging!!

NelsonFerraz (author)JJV62016-10-26

not yet! But I'm planning to build an equatorial mount to use this!

OmarS123 (author)2016-10-11

excellent idea my freind so do you think work your project or future proyect with Raspberry?

About This Instructable




Bio: Master in Electrical Engineering Background: Renewable energies. Hobbies: Astronomy, DIY projects, Flight sports, RC planes and drones
More by NelsonFerraz:Control Your Telescope Using Stellarium & ArduinoConvert a Flashlight for Astronomy in a Few Seconds
Add instructable to: