Use an Arduino to Get to the Moon


September 13, 2014

So, this whole Maker movement has got you excited, and the rocket you are building in your backyard is nearing completion. But you haven't decided on a navigation computer yet. You were thinking of using a laptop, but your daughter needs it for school. Maybe a Beaglebone Black. Darn! Seems they are sold out everywhere. You look around your lab, but all you can find is an Arduino. At first you pass right over it. But when you can't find anything else, you start to wonder, "Could it get me to the moon?"

Of course this scenario is a little bit far-fetched, but the question of whether an Arduino could navigate you to the moon is an interesting one. A typical Arduino, with an ATMega 328, is actually quite a bit of computing power. I often cringe at some questions I see on forums, where people are wanting to throw a Raspberry PI or a Beaglebone Black, or some similar board, at a problem that could be easily handled by a lowly Arduino. I am no fan of Arduinos, but the AVR chips used on them are quite powerful and capable of much more than many people realize. I came up through the computing and electronics world during times when typical microcontrollers and even PC's were 8 bits and could execute somewhat less than a million instructions per second. In those days, one of today's typical cell phones would have been considered a supercomputer. As a way to demonstrate just how much power is in one of those little Arduinos, I decided to write this article. Perhaps it will encourage some of you to write your software better and make better use of the power available, rather than trying to throw more hardware at whatever problems you face.

I think most readers will agree that sending men to the moon was one of the greatest technical accomplishments of mankind. We did that 45 years ago. Rocket science is often considered "hard" and is used to represent difficult, mathematically intense problems. "It ain't rocket science" is a common phrase where I live to indicate something isn't very difficult. And since navigation and positioning are two common problems I often see people trading their Arduino for something more powerful "to handle the calculations", perhaps we should start there. So pull that Arduino out of the drawer, blow the dust off and bolt it to the control panel of your new rocket, and let's see what happens.

Fourty five years ago, three men strapped into the command module of Apollo 11, sitting atop a huge fireball called a Saturn V rocket. They blasted off with an acceleration of around 6 Gs, headed into orbit. From there, they pointed the rocket into space and fired again, setting themselves on a trajectory to reach the moon some 238,000 miles (400,000 km) away. The trip would take them about 3 days and require speeds in the neighborhood of 25,000 Miles per hour (40,000 kh/hr). The navigation had to be perfect, going from the Earth as it traveled at tens of thousands of miles per hour to the moon orbiting it at similar speeds, and touchdown right in the designated spot. There were no wheels or even propellers to steer with. Only small thrusters to slightly change the course as needed. There was no GPS or anything similar to use for guidance. Only the stars. If you think it is hard to get your robot to navigate around your kitchen and return to the same place, imagine if your kitchen were a million times larger and you had only the stars to navigate by. What kind of computer would you need to accomplish that?

The Apollo missions carried two Apollo Guidance Computers on board: one in the command module, and one in the lunar module that actually landed on the moon. The two computers were identical, but had different programs loaded into them. These were the first computers to use the new integrated circuits (chips), all those before using discrete transistors or vacuum tubes. They consisted of several thousand very simple logic chips, each having a few OR gates and nothing else. This was actually the second version of the computer, which was designed specifically for the Apollo missions. It was called the "Block 2" as opposed to the first model, the "Block 1." It was very small and low power for it's time, and packed quite a bit of power relative to others of the early and mid 1960s. The computer was about the size of a microwave oven and used about as much power as a typical laptop of today (70 watts). These computers succesfully guided 6 rockets and 12 men to land on the moon and return safely. Sounds like some pretty impressive equipment! Let's have a look.

As I mentioned, each computer was about the size of a microwave oven and used 70 watts of power. They were each made of 2800 chips, each chip having two 3 input OR gates. Almost all the world's production of digial logic chips at the time went into making these computers. It was all very new. There were no RAM chips or FLASH chips. The memory was "core" memory: little donut shaped pieces of magnetic material that could each store a bit. It was "sort of" a 16 bit computer, but in reality only 15 bits. One of the sixteen bits was used as an error checking parity bit and could not be used for data or instructions. The fifteen bits were used as 14 data bits and one sign bit. The memory was of two types: "normal" random access core (RAM) and "rope" core, which was a type of Read Only Memory (ROM). The rope core was equivalent to FLASH memory on modern chips, but was programmed at the factory and could not be changed. The machines that flew to the moon had 36 K words of rope core (72 Kilobytes) and 2K of core (4 kilobytes). That is pretty close to what an ATMega 328 on an Arduino has. It should be noted that the AVR processor has more powerful instructions, so it takes fewer to accomplish the same work. One note about core memory: it retains it's data even without power, so it is similar in operation to EEPROM in an AVR or other modern microcontroller.

Apollo Guidance Computer core memory modules
What about processing power? The Apollo Guidance Computer (AGC) operated at 2.048 MHz. That's a far cry from the typical Arduino at 16 MHz. But that doesn't even tell the whole story. As mentioned above, the simple instructions on the AGC are nowhere near as powerful as the instructions in an AVR. In addition, all AVR instructions except those that "jump" to another place in the program operate in a single clock cycle. The AGC took several clock cycles per instruction. Overall, the AGC was capable of considerably less than 1 million operations per second, compared to the Arduino's 14 million or so more powerful instructions.

During the landing of the Apollo 11 Lunar Module on the moon, a time when the AGC was using near it's maximum capability, an overload occured. The problem came from a hardware bug in a radar system. It was causing interrupts when it should not have been, and those interrupts added to the already high load caused the AGC to become overloaded. The problem was resolved by a combination of very good programming and good work by the ground crew to reset the computer. As we know, the Lunar Module landed Neil Armstrong and Buzz Aldrin safely on the moon. The AGC had gotten them there almost flawlessly.

Apollo 11 Lunar Module on the surface of the Moon
The AGC continued to perform nearly perfect for the launch from the moon to rendesvous with the Command Module in orbit around the moon. It then succesfully navigated the spacecraft out of Lunar orbit and back to Earth, inserting it into orbit here, and then on to insertion back into Earth's atmosphere.

Having proved itself capable of flying men to the moon and returning them safely, the AGC was then used as a proof of concept of "fly by wire" systems to control fighter jets. Quite some list of accomplishments for the very first production computer to use primitive integrated circuits and designed in the early 1960s.

An Arduino using an ATMega328 operating at 16 MHz is many times more powerful than the AGCs that took 12 men to the surface of the moon and returned them. The math required to navigate to the moon and control a spaceship carrying 2 men to land there is quite complex. The AGC handled it well. The Arduino is plenty capable of the same. The next time you are wondering if an Arduino is capable of balancing or navigating your little robot around your house, consider the AGC and what was accomplished with it. There is an awful lot of power on that little board.

Some interesting reading:
Pictures from the apollo missions
Wikipedia's article on the AGC
Nasa book chapter on the AGC
Build your own AGC!
An AGC simulator
And courtesy of Gareth, some more links:
Teardown of a circuit module
More LVDC video