Introduction: TinyCompass

In this Instructable, we will be building a compass using the TinyShield Compass as well as the Circle Edge Led shield. Before starting, the proper drivers must be installed to detect the COM ports. These drivers must be installed before downloading any codes from the codebender plugin. The drivers needed can be found here.

Step 1: Materials

Lucky for us there are no downloads for this project, we can simply use the codebender plugin to directly program our TinyDuino.


  • TinyDuino Processor w/Battery Holder : link
  • TinyShield USB: link
  • TinyShield Compass : link
  • TinyShield Circle Edge LEDs: link
  • CR1632 3V coin cell battery

Step 2: Programming the Tiny Duino

The code below was used for the TinyCompass and has comments throughout to help explain what is going on. The magnetometer used for our compass board is the HoneywellHMC5883L 3-axis compass. This code can be downloaded to your computer or directly uploaded to your TinyDuino processor board.

Step 3: Calibration

After your TinyDuino has been programmed you can remove the USB Shield. Each time you turn on or restart the processor, you will need to calibrate it. To calibrate, simply rotate it 360 degrees on each axis (the gifs above show exactly what to do). We now have fully functional compass that takes up less than a cubic inch of space! Because of how sensitive the HCM5883L chip is, ferromagnetic materials, magnetized or not, within a 2 inch radius of the chip will cause disturbances.



  • Clocks Contest

    Clocks Contest
  • Oil Contest

    Oil Contest
  • Creative Misuse Contest

    Creative Misuse Contest

48 Discussions

I reckon thats a sweet idea! Do you know if you can get rechargeable batteries that small? That way it could be linked into a car stereo and charge. Nice work.

4 replies

I don't know about rechargable batteries, I suspect that there are some available, however you might also look for supercapacitors as an alternative as well. The battery series that the tinyduino uses is the cr16xx series, no larger than the cr1632. The dimensions for this series are a cylinder 16 mm in diameter, and no more than 3.2 mm top to bottom. You can use smaller batteries or supercaps, but not larger. Voltage of 3-3.3v, even up to 5.5v should work. The processor board does _not_ have a voltage regulator on it though, so don't put two 3v batteries back to back in the slot (otherwise a pair of cr1616 or smaller batteries might work) or you will exceed the recommendations of the component manufacturers. (I'm not saying that it _won't_ work, or that it _will_ destroy your board, just that the manufacturer would consider this a bad idea.)

Thanks for the reply very helpful. Seems you know a lot about electronics wish I knew more.

I've been playing around in the field, and working in related fields for most of my life. That said, I've learned one thing through the years, if you are interested in a topic, the tools needed to learn more are out there. (Exceptions are mostly found in the doctorate level work where you end up creating the tools needed to expand human knowledge in some way or another.) What works for one person learning isn't necessarily going to work for anyone else though, so if I were to recommend one engineer's course, or another, it may help, but it may also drive you away from the field. The most important element I think is curiosity, and recognizing that there is only one person responsible for you learning any field, and that's you. Others may encourage you, stoke your curiosity, or help you get there, but only you can recognize that you have something to learn, and make the effort to learn it.

With over 25 years in IT and only recently earning my degree, I agree with you 100% when you say:

"The most important element I think is curiosity, and recognizing that there is only one person responsible for you learning any field, and that's you. Others may encourage you, stoke your curiosity, or help you get there, but only you can recognize that you have something to learn, and make the effort to learn it."

Are there any cheaper options? I know you can get knockoff arduinos for a couple bucks so if you could with these boards too that would be great. I cant justify spending $68 on something so useless. Its cool don't get me wrong but its utterly useless.

9 replies

This instructable was made by the company Tinyduino to showcase one of their produces. As with many makerstuff suppliers, Tinyduino's wares (like Adafruit's and Sparkfun's) are way more expensive than buying the components off of eBay from Hong Kong. I just saw a HMC5883L breakout board on eBay for $1. However, forget about customer service, and maybe I'm the only one who feels a twinge when I pull a great project tutorial from one of these suppliers, and then look for all of the parts elsewhere. Then again, you can do a lot more tinkering when they are 90% cheaper!

Thanks. My thoughts exactly on the last part. Cheaper parts = more tinkering. And i'm really not going to spend $70 on a compass that isn't water proof, Only works after you take time to calibrate it, Only works in a civilized area with batteries, and is missing a ton of functionality. If you have the parts on hand though i suppose it could be a fun build to help you learn to code, and i'm not a coder, just a builder. =P

You're welcome to use a digital compass without calibrating it. Pretty much every digital compass I've seen includes the recommendation that it be calibrated, but you're welcome to use one without doing that. I understand it's a good way to become lost. (Note that compass directions provided by GPS units in cars are usually derived from your motion as detected by the GPS monitoring satellites for position information. It doesn't require calibrating, but is also not using a magnetic compass. The digital compass in your phone very likely does include a setup step to calibrate it.

As for battery life, yes you will need batteries or a 3.3-5v power supply of some sort. That's true for pretty much any digital device. But you should also keep in mind that also includes the computer you're using, in as far as you're still going to need a supply of power sufficient to operate that computer. And unless you've built a computer out of scrounged parts and a Raspberry Pi, you've likely spent (or someone has spent) significantly more than $70 for what you're using.

If you are thinking that switching to a magnetic needle compass and avoiding the digital realm entirely, remember that there is only a limited part of the US where magnetic North has any real relationship to true north. I happen to live close enough to that zone not to make a lot of difference, but I wouldn't suggest that anyone disregard knowing what the magnetic declination of their location is. This is true of digital magnetic compasses as well, and it bother's me a little bit that most digital compasses and compass apps on phones don't have a way for you to enter a magnetic declination correction.

As to waterproof, no argument, though I know a lot of digital devices that are not waterproof, including most phones, tablets, PCs, and so on. You can work around the issue to some degree with a ziplock bag, or building a waterproof housing. But I realize it's a lot easier to dis the people interested in seeing what they can do that's interesting to them with off the shelf or newly created tools. Keep it up.

Your points about calibration and declination are well taken. I don't think anyone on this thread was trying to discourage anyone from trying this project or "dissing" people interested in it. Sounds like hornbadoing is simply not one of those people.

Could be. I've run into some odd attitudes over the past few years.

From my perspective, I have to admit that yes, this can be done for less by buying the components, and building everything yourself. that said, I'm not really interested in building an led ring. I've worked with compass breakouts, and rtc breakouts, and the like. Having what I'm interested in working on all in small boards that I can put together, potentially mount into a box or in this case hang on a zipper fob of a jacket, has some appeal to me. As noted elsewhere, I'm using the basic ible here as a starting point to stretch what's provided a bit. And I have some other ideas that using this as a starting point may help me pull together some other idea on down the line. All without having to do any soldering. (Which is not to say that I can't do the soldering, just saying that with this, I can play with ideas that otherwise would require me to break out the soldering iron and build.)

Here is the compass $7 chip on Sparkfun https://www.sparkfun.com/products/10494 but you can find it cheaper elsewhere. What Sparkfun is good for is breakout boards like the $15 https://www.sparkfun.com/products/10530 You can learn more via the always excellent Adafruit https://learn.adafruit.com/adafruit-hmc5883l-breakout-triple-axis-magnetometer-compass-sensor/overview and her breakout board is $10 http://www.adafruit.com/product/1746

That's the beauty of arduino, though. Build the project, write the code, test and play. Then disassemble and use the parts for something new. It's like expensive Legos. Actually, it might be cheaper than Legos these days...

Testing with a couple of changes to the code.

First up I added the Prescaler library, changed calls to 'delay' to 'trueDelay', and switched the cpu to 500 khz from 8 mhz. From some of the information out there, this should double the battery lifetime for the processor. However that's not everything by any means.

Next up I commented out all calls to serial. They are debuging calls, and since I've neither included the USB board, nor am I using a uart serial link to a computer, the calls are not going to help the program function, or the battery life.

Finally I modified the program to add a ledsOff function, after what you see in the code as a 40 ms delay, and add another 100 ms delay with the leds off. Presuming that most of the power usage is the led, this alone may double the battery life. All the ledsOff() function does is set all of the led leads to LOW which turns them off. It now blinks about 9 times a second, which is enough to give the user an idea of what direction North is.

We'll see how long a battery goes with this setup.

Not sure if it's the commenting out of the serial commands, or just that I"m getting expected results that I wasn't expecting. I implemented the above on Monday before a meeting that I went to. Since then every so often, about 20-24 hours at a shot, I'm performing a reset with the reset button on the controller board. It's still going strong. So a single cr1632 will keep this going for at least over a weekend. I'll let it continue to run and see how long it ends up lasting, but I think the next two steps are to figure out how to 'normalize' the magnetic readings over a second or two to get the compass pointing more accurately to north.

Then I start working on getting the package to do something else entirely, namely working as an optical radio compass. The idea being that you have the device flash in some way to uniquely identify it, so that you can place it on the ground, or in a space, then it blinks a start of process pattern so that someone has a starting point for a timer, then you blink each led in sequence with a known/predictable time between each pulse, starting at the LED pointing north. The idea being that multiple people can make use of the compass, they know what direction they are from that compass on the ground, and with a couple (or three) compases you can figure out where you are on the ground.

You can do this in a somewhat more manual process with simple beacons, where you have a good reference for where the beacon is on the ground, know how to identify that beacon, and can measure, or estimate, the angle from you between pairs of four beacons. (Possibly 3 if they are diversely enough located, though even 4 in a line will still give you two possible locations.)

Having all of the parts, I built one yesterday morning, and picked up a battery for it yesterday afternoon. It's been running now for over 24 hours. I can leave it running and "report back" at some point, but I'll probably forget. You can look at the specs of the components involved, and get some idea of the lifetime for a given battery, or you can put an amp meter in the system and calculate battery life based on the testing conditions, but if "over a day" isn't sufficiently long, I suspect you would do better to set up your own test situation.