DPRG Events Shoptalk

Website design and hosting by NCC

Low Cost Gyro-Accelerometer Combo Sensor

January 2003, by Earl W. Bollinger

Populated Gryo PCB
Click for full-sized image

Project Summary

In building a balancing robot you need a gyroscope unit and an accelerometer unit in order to get it to balance. But I also wanted it to be reasonably low in cost with high performance and easily interfaced to a MCU. Some of the other solutions are prohibitively expensive, even if they may work well. Also the solution I had in mind had to be fairly small and use up little space and use up little power too. So when Analog Devices recently came out with their ADXRS150 and ADXRS300 piezo-gyroscope integrated circuit, I now had a solution that had low cost and low power with high performance too. The gyro is very small at about 5mm square (about 0.3 inches square). You can see the small combo gyro PCB mounted vertically in the center section on the balancing robot photo below.

2-Wheeled balancing robot
Click for full-sized image

I also took advantage of the small size and combined an Analog Devices accelerometer integrated circuit on the same PCB to maximize performance. Plus there are no moving parts per se to complicate the issue. All the good stuff is contained inside the chips. Using the two Analog Devices ADXRS150 and ADXL202 we can build a combo PCB for under $100.00 in parts. In this case at the Analog Devices web site, they are selling the gyro for about $39.90 in singles and the accelerometer for about $29.90 in singles. I know that the Express PCB service charges about $62 for three mini-boards, so one board costs about $20, then we have about $20 for all the other parts, since the PCB uses up only a small portion of the whole PCB blank, you can put in a few other needed layouts for other things on the same PCB and cut them out later as you need them. I usually use a scroll saw to cut out the small PCBs. In some cases you could obtain samples of these chips, or as they start to fill in the vendor pipeline, you'll be able to get them at better prices through the vendors and distributors.

Traditional Gryo Solutions

You can, off and on, get nice Murata Piezo Gyros for $40 each from some vendors. But these tend to go to the manufacturers first, so sometimes it is difficult to get one. Gyration sells a micro gyro for $450. There is also a special academic version of the kit for $35. It has three gyros and supporting chips included in the kit.

Microstrain sells a number of different gyro modules starting at $295 up to around $1495.

The old classic approach is to obtain RC hobby model aircraft gyros and use them. These gyros run in cost from about $69.00 on up to several hundred dollars, depending on the model or type. A source to check out is Tower Hobbies or maybe a RC specialty store like Helicopter World. Sometimes Servo City has RC model plane Gyros too.

Then the most basic method is to use a potentiometer with a pole or pendulum attached to it. You feed the wiper output from the potentiometer to an ADC and then you can determine your position or tilt angle. This is the standard classic approach to balancing robots that balance a pole on top of them. But you could invert it as well. Usually you would still have to have some kind of a reference to the floor or tabletop for the robot to know where the floor is. But you could trail a potentiometer with a small arm touching the floor behind the robot for this purpose as well.

Although a RC hobby gyroscope is cost effective, it is a bit difficult to interface to a MCU. The gyro is designed for RC model airplane servos that work with a 1 to 2ms-width pulse train. Thus 1.5ms is neutral, 1ms full one way and 2ms full the other way. Using a MCU you have to transmit the 1.5ms neutral signal to the gyro, then receive the pulses from the gyro and translate them into something more meaningful for you to use. The next problem is you basically have to have the MCU stop for up to 2ms to read a pulse width, before you can do something with it. Depending on the MCU you might have to have the MCU send the the 1.5ms pulse as well, eating up even more time. That 2ms may be very critical to other things going on. But if we use the gyro chip, we can use a ADC (analog digital converter) to convert the analog voltage level to a numerical value much faster, plus you could, in some cases, start the ADC to get a value, and come back later for the result. We can now reduce the time to get a numerical value down to microseconds instead of milliseconds. Thus we get better accuracy, and faster performance. If you use a high performance DSP processor, you may be able to get this down to less than a microsecond to read a voltage level.

The more expensive gyroscope systems, unfortunately, tend to be prohibitively expensive. So although they are really neat solutions, I didn't pursue them any further.

ADXRS Gryoscope

Without going into all the engineering gobblygook, the basic way the ADXRS150 or 300 gyroscope IC's work, is they output a 2.5 volt level at rest. If the gyro is tilted one way or the other, then it will output up to a +/- voltage change from reference. This is an analog level that you need to feed into an analog digital converter (ADC) for a MCU to use. The ADXRS150 has about a 12.5mv per degree of sensitivity, for up to about 150 degrees per second of tilting. This can be adjusted some more as needed too. The voltage change is proportional to the speed or rate of the tilt angle. The faster the robot tilts the larger the change in voltage. The ADXRS300, as a higher performance device, gives about 300 degrees per second of tilting.

The following sequence of photos illustrate the voltage change when the gryo is titled. (the photos are an exaggeration as I couldn't tilt and snap the photo fast enough)

Gyro output at rest
Above: Gryo is at rest

Gyro output, forward tilt
Above: Gryo titled forward

Gyro output, reverse tilt
Above: Gryo titled backwards

This short MPEG video also shows the oscilliscope measurements of the gyro circuit at rest, tilted one way, and then tilted the other way.

If you want more information about the chips, please go to the Analog Devices website and download the spec sheets and documentation on the chips. Also get the documentation on the accelerometer evaluation board as well. I expect Analog Devices to have an evaluation board for the gyroscope IC pretty soon as well.

ADXL202 accelerometer

The ADXL202 accelerometer is a really neat device in itself. It basically outputs a pulse string, and changes the duty cycle as the unit is tilted. Plus the change stays at the tilted angle until you change it to a different angle. Thus it makes for a really handy reference point type of device, such as where is "up" versus where is "down".

Using a gyroscope by itself seems reasonable, but the gyro develops a slow creeping tilt error that continues to increase. An example of this is when you tilt the gyro you'll see a change in the output voltage, but it quickly returns to it's resting level, if the tilt doesn't change. Thus if your robot was to tilt forward a few degrees and stay at that angle, the gyro will report that the robot is standing straight up after a second. So eventually the errors add up and the robot falls over. Using an accelerometer helps to solve this problem. The accelerometer outputs a steady duty cycle when the robot is standing straight up, and if the robot tilts one way or the other the duty cycle changes, and stays changed, until you have the robot's computer correct for the tilt. Now on the surface it looks like you could use only the accelerometer, but the gyro reacts much faster to tilt changes than the accelerometer can. So the gyro gives you the fast response and the accelerometer helps to correct for the creeping gyro errors that will occur and tells you when your level or not, or where up and down is.

I basically followed the designs as put forth by Analog Devices, but I did add more filtering into the power line for the gyroscope chip. Without the additional filtering you run the risk of noise causing too many spurious readings, which would cause more problems. I also kept the two circuits somewhat separate in order to ensure that the noise generated by the accelerometer doesn't interfere with the gyroscope or vice versa. Plus the additional filtering is needs as the MCU or electric motors will generate additional power line noise as well.

PC Board

PCB Artwork

Except for mounting the gyroscope IC, building the PCB is fairly straightforward and simple. But do be extremely careful with the surface mount capacitors as they are not marked and they typically all look alike. I would suggest taking the capacitors from their package one at a time and soldering them down one at a time to ensure you don't mix any up. Also note that the two IC chips are complex and sensitive to static electricity so you need to be careful with them. I use a small X-Acto knife to help hold the little parts down as I am soldering them. Sometimes a bit of air gets trapped under the part and it'll pop off from the heat as you solder it. When the part goes poof and pops off the PCB you can't find it on the desk or floor, so you have to go get another one.

Mounting the gyroscope IC is a big problem as it is a BGA (Ball Grid Array package) that is about 1/4" square in size. The 32 little pins are .020" in diameter and are about .015" apart. In looking at the chip, it had me spooked for quite a while. There may be other ways of doing it, but the three that I know of are: One) you can use a IR oven designed for soldering these parts onto PCBs; Two) you can use a hot air SMD rework station to heat up the parts and solder them; Three), you could heat up a toaster oven to 300 degrees or so and then stick the PCB with the gyro on it into the oven and cook it for a few minutes or so (I have not ever tried this method though). In the oven methods, I've seen them use some kind of a PCB pre-heater to heat the PCB up to near 300 degrees, but just short of where the solder starts to melt. Note that a unique characteristic of the soldering is as the solder melts it sort of self aligns the chip onto the pads, based on the surface tension of the solder in it's liquid state.

Unpopulated PC board
Click for full-sized image

I suggest you build the gyroscope circuit first and test it, then build the accelerometer circuit and test it. There is an option to use a common single 78L05 voltage regulator on the PCB, but I decided that might be risky, as it may introduce too much RFI noise back into the gyroscope circuit, from the accelerometer circuit. I also left several empty pads for additional filter capacitors, should I need them. Although I used a 47uh inductor to attenuate noise on the VCC line it is possible to leave this off or change the inductor value as needed, depending on your environment. I also left a couple of shorted pads on the PCB layout for an optional filter diode, should you want even more noise filtering.

The two parts only draw about 3-5ma of current, so they won't load down your battery power any. If your running directly off a 4.8v battery, you could leave off the 78L05's and run a jumper to bypass them. I would probably use the filter diode in this case though, as RFI or noise can get into the circuit more easily.

The secret to making this work is to use liquid flux. Also you can't use just any flux, it has to be a non-corrosive flux. Some flux will be trapped under the gyroscope IC, thus corrosive flux residue would be bad. I like to use GC Electronics number 10-4202 Liquid Solder Flux myself. The thin paste fluxes would work too. After the solvent evaporates some it gets nice and sticky, which helps aid in holding parts in place. The flux also is invaluable in helping to prevent solder bridges from occurring when soldering as the flux tends to fill the gap between the pins. Then of course it also serves as an aid in getting the parts to solder well. After you have completed the PCB you can use some denatured alcohol to clean off the flux. Gently using an old toothbrush helps with the cleaning too.

Unpopulated PC board
Click for full-sized image

First we need to mount the gyro chip. Since this is the hardest part, we need to do it first.In my case I opted to use a hot air SMD rework station. So we need to apply some flux to the PCB, and wait a little while for it to get sticky. Then we carefully align the gyro chip onto the PCB using the corner guides I had etched into the PCB. Note that there is a little arrow on the chip that should match up to the Rate Out corner on the PCB. Setting and aligning the gyro is scary, sort of an "Act of Faith", as you can't see the pins or pads.

Now with the SMD tool all heated up good and adjusted to a low air pressure setting, we carefully and gently hold the chip in place with a X-Acto knife blade tip and use the hot air SMD tool to heat up and melt the solder on the chip onto the PCB. This is tricky as we need to only lightly apply enough pressure to hold the chip from moving from the hot air, plus we need to move the hot air nozzle around evenly so as to not burn anything. The whole operation should take about 2-3 seconds. After getting it soldered, carefully move everything away and be extremely careful not to jiggle the PCB until it cools down. I used a PCB holding vice/stand unit for this purpose.

Now after it has cooled down, take a digital multimeter and check to ensure that none of the adjacent pins (that aren't connected together) have become shorted. If it's OK you can then proceed to mount the other parts on as needed. If you do have a short, you'll have to use the SMD tool to remove the gyroscope chip, then "re-ball" the chip's pins, remove any excess solder from the pads on the PCB, and repeat the process again. "Re-balling" is basically putting a tiny dab of solder back on each pin; it'll form a small half sphere in the pin as it cools. Which is tricky as the pins areso darned small.

Capacitor placement
Click for full-sized image

Building up the rest of the Gyroscope circuit is fairly easy now. Note that on the back there are two caps, a 47nF cap and a 100nf cap. In the Analog Devices spec sheet they stated that these two parts have to be as close as possible to the chips pins to help avoid RFI noise problems. I also put in a 2.2uF tantalum on the back of the PCB, but I don't think it is really needed, but I wanted to cut noise as much as possible.

After getting it all soldered down, we now come to the scary part; Powering it up. But before you apply power, use your multimeter to ensure we don't have a short to ground someplace. With the PCB at rest, apply power. With a multimeter you should read a voltage of approximately 2.5v on the Rate Out line. Now taking the PCB carefully in your hands (you don't want any of the wires, you may have hooked up, to short against anything) hold the PCB in a vertical position. As you tilt the PCB from side to side you should see the voltage out from the Rate Out line change. Tilting faster increases the voltage change, tilting gently just causes a little change.

Gyro output at rest

Using an oscilloscpe you can watch the gyroscope in action, also note how clean the signal is with little or no RFI noise to cause erratic readings.

After building the gyroscope circuit, you can now finish up and build the accelerometer circuit. This is actually pretty easy as it has only a few simple parts to mount. Nothing complicated like the BGA part on the gyroscope IC. Plus all the parts are on the same component side of the PCB.

Completed PC board
Click for full-sized image

Make sure you don't have a short. Then power it up. This is a bit harder to test, as you really need to use an oscilloscope to see the pulse train outputs on the X and Y output lines. But a quick and dirty test is to run a multimeter with an AC input and see if you can measure the output. As you tilt the unit back and forth, you should see the average AC voltage change a little from the duty cycle changing on the pulse train. Another way is to simply use a logic probe and see if you have a pulse train output running. Using an oscilloscope, you'll be able to see the pulse train at about a 50% duty cycle. The following sequence of photos illustrate the changes in duty cycle and pulse width seen as the tilt increases or decreases.

Accelerometer output at rest
Above: Accelerometer at rest

Accelerometer output, forward tilt
Above: Accelerometer titled forward

Accelerometer output, reverse tilt
Above: Accelerometer titled backwards

Everyone should actually be able to obtain an oscilloscope. I got mine off of eBay a long time ago for about $14.00 plus shipping. The probe cost me $15.00. An oscilloscope is invaluable in checking things out on electronic circuits, as you get to see things easier. Tuning and debugging circuits are so much easier with an oscilloscope. Although a low cost Radio Shack Logic Probe is quite handy for looking at logic level signals too.


At this point if everything is working OK, you're in business. Depending on the MCU or processor your use you can use an internal or external ADC to convert the gGyroscope's analog output into a digital value for processing. You would typically measure the pulse width of the accelerometer and determine the duty cycle to get the tilt angle. At this point it is all up to your imagination. Please note that the PCB is designed to stand up on its edge, not down flat. You'll need to allow for that if you are using it in a balancing type of robot.

I plan to build up an Atmel ATTiny26 MCU based PCB (I had to have something to fill in that empty space on the PCB that I sent off to Express PCB to have made). The ATTiny26 MCU has 2k of flash program space and 10 ADC channels along with two PWM channels as well. My plan is to use the gyroscope/accelerometer combo PCB along with the ATTiny26 PCB running as a coprocessor and have an autonomous balancing unit controlling the motors on the robot. The main MCU or computer would then tell the ATtiny26 to move forward, backwards, turn, stop et cetera.

Also I have been tinkering with a New Micros ISOPOD DSP MCU and I might use it instead, as it has a lot of performance going for it. It is so fast that it could replace several MCUs and still have time to do other things as well. Thus I wouldn't have to use co-processors to offload processes and tasks to.

A Socket Option?

After this article was published, a reader pointed out that a Japanese company, Enplas Tesco, Inc., makes a socket that will hold the BGA packaged Gyro. The socket is designed for testing and burn-in of BGA components. The part number is OTB-32(144)-0.8-16 and it costs $32 in small quantities. The use of this socket would simplify the project for those who'd like to avoid soldering the Gyro to the PCB.

A mechanical drawing of the socket (PDF format)

For more information contact:

John Ambrosini
Enplas Tesco, Inc.
603 635-7526 voice
603 635-7738 fax

Schematic Diagram

Gyro-Accelerometer combo schematic
Click for full-sized image

Component List

Gyroscope circuit
  • (3) 22nF ceramic capacitors 25v or 50v 805 size (note the charge pump capacitors need to be 25v or greater)
  • (1) 47nF ceramic capacitor 25v or 50v 805 size
  • (2) 100nF ceramic capacitors 25v or 50v 805 size
  • (1) 1.5uF electrolytic 16v or 25v or 50v
  • (1) 47uF electrolytic 16v or 25v or 50v
  • (1) 2.2uf tantalum 16v or 25v 1206 size (note this is optional)
  • (2) 47uH inductor 1210 size (note this could vary depending on conditions, up to 470uh or even 1mh)
  • (1) 78L05 voltage regulator IC TO92 package
  • (1) ADXRS150 or ADXRS300 Gyroscope IC
Accelerometer circuit
  • (1) Analog Devices ADXL202 Acceleometer IC (a ADXL210 would work also but 10gee's seems way too high for my purposes)
  • (2) .047uf ceramic capacitors 25v or 50v 805 size (note these are tunable, see specs)
  • (1) .47uf ceramic capacitor 25 v or50v 805 size
  • (1) 124k ohm 1% resistor 805 size (note this is tunable see specs)
  • (1) 1.5uf electrolytic 16v or 25v or 50v
  • (1) 47uf electrolytic 16v or 25v or 50v
  • (1) 78L05 voltage regulator IC TO92 package

The Details

Related Links

  • autopilot - UAV project. Good source for GPL'ed Kalman filter code
  • nBot - A two-wheeled balancing robot
  • Gyrobot - another two-wheeled balancing robot

Copyright © 2003 Dallas Person Robotics Group
The Gyro-Accelerometer Combo Sensor schematic and PCB artwork are licensed under version 2 or later of the GNU GPL. This means everyone has the freedom to use this design for any purpose, to study it, to copy it, to distribute it, and to change or improve it, provided such changes are also made freely available to everyone.

Copyright © 1984 - 2016 Dallas Personal Robotics Group. All rights reserved.