loading

Is there a cheap way to make a digital compass?

Trying to make a weather vane and needs to be hooked up to an arduino board. I have a rotary encoder which is just a potentiometer that can rotate forever. I need something to help determine direction, and for cheap.

I've seen the compass modules , and they are just too expensive. >$40...

Any ideas?


sort by: active | newest | oldest
AndyGadget7 years ago
A standard way of doing this is using an optical encoder. Look at this <a href="http://en.wikipedia.org/wiki/Rotary_encoder">Wiki article</a>, especially the section on Gray code and the disc picture. You would use a simple LED / optosensor on each ring, which would give you the cardinal and secondary points (N,S,E,W,NE,NW,SW,SE). As long as you have a compass to set things up initially (choose one code for North, and decode everything else accordingly) this will do the job.<br /><br />Alternatively . . . <br />If you're looking for a transportable weathervane which is self calibrating, you could use a <a href="http://www.google.co.uk/url?sa=t&source=web&ct=res&cd=3&ved=0CAsQFjAC&url=https%3A%2F%2Fwww.zagrosrobotics.com%2Ffiles%2Fdens1490.pdf&ei=x2TQStD3FuShjAf-xKXRCA&rct=j&q=dinsmore+1490+&usg=AFQjCNEd3NBqSOKV2p-QQWIa_VuMuCPxuw">Dinsmore 1490 module</a>. This gives similar outputs to the optical encoder method but contains a compass so North will always be correct, independent of the mounting position.<br /><br />They cost $15 from <a href="http://www.robsonco.com/Dinsmore/Untitled_7.html">Robson company</a>. They take PayPal and I had a couple shipped to the UK a few months ago, but haven't done anything with them yet.<br /><br />
If your potentiometer encoder has three wires, connect one end one to V+, one to 0V and the slider to the input of an ADC.  Your program will read the ADC and decide which sector of the pot the slider is in.  From ehat you can work out the direction.  Of course, you'll have to calibrate it against a compass first.  Make sure your code takes into account the jump from full-scale to 0V at the end of the pot. 
If your encoder has more than three pins, then it's something a bit more complicated and we'll need more information on it.
arduinow (author)  AndyGadget7 years ago
Hi, thanks for an awesome reply.
Based from what you've told me, I think for now I'll just have to calibrate my weather vane by hand. I would have preferred inbuilt calibration but I don't have that much time. But that Dinsmore 1490 looks really tempting...xD

I thought I'd include an image of the rotary encoder with which I have. It does have the three pins but also has few more, one of which I think handles a 'push' as it's also a button.

Thanks.
arduinow (author)  arduinow7 years ago
<a href="http://cdn.shopify.com/s/files/1/0031/5472/products/09117_03_l_large.jpg?1254987032">cdn.shopify.com/s/files/1/0031/5472/products/09117_03_l_large.jpg</a><br />
Looking at a couple of similar continuous rotation pots the mechanical rotation is 360 degrees, but the electrical rotation is 340 degrees, i.e. there's a 20 degree dead spot at the end of the track.

Taking a step back and considering this top-down, the simplest remote-reading weathervane would be to have a vertical shaft with the vane at the top and a magnet on a disc at the bottom.  Below  the magnet disc you would have another disc with eight reed switches.  Take the 9 wires (one common) down to a circle of LEDs (one in series with each switch), a resistor and a battery.  No arduino required!
You would have to be careful with the magnet positioning and have at least one switch activated at all times otherwise you would get dead spots.  With this method you would also get the intermediate positions (e.g. NNE) showing as 2 LEDs lit.

Sounds like a goodie for an Instructable!
arduinow (author)  AndyGadget7 years ago
omg, that's awesome!
I actually sat here thinking, "reed switch, what the heck is that?" haha.

I'm actually looking to make an anemometer as well, and from a product description, it uses reed switches which I figured was to get frequency in order to measure the the wind speed.
but anyways..
I'm still in need of the arduino though as I need something to handle relaying the wind direction data to a mobile phone and eventually end up as a sms on another phone.
Your design should still be able to work with it right?
A couple of magnets mounted on a spinny thing and a reed switch sounds good for an anemometer.  Watch out for contact bounce though.  (Once you've detected a closure, put in a 20ms-ish delay to get over the bounce period.)
If you're going for wind speed and direction you may as well put in temperature and humidity as well and have a full-blown weather station ;¬)
Getting all this data to a mobile phone is going to be rather challenging, but I would imagine there are modules and code available for the Arduino to help you do this.


arduinow (author)  AndyGadget7 years ago
Haha, the thing is, that's exactly what I'm building, a weather station.<br /><br />Been playing around with a One Wire temperature sensor. <br /><a href="http://cdn.shopify.com/s/files/1/0031/5472/products/one_wire_tempsense_3_large_large.jpg?1254987032">cdn.shopify.com/s/files/1/0031/5472/products/one_wire_tempsense_3_large_large.jpg</a><br /><br />Unfortunately, I haven't been able to get something with humidity because the modules cost quite a bit. <br /><br />Good point about the bounce, it's my first time using reed switches, I would have no idea how to troubleshoot it.<br /><br />Thanks again.<br />
Yep, the Dallas is the one to go for.  I take it the Arduino has routines for the 1 wire bus?  The standard humidity sensor is pretty pricy, but I bought a very cheap one a while ago.  I'll track it down tomorrow.  (Silly time here - I'm off to bed!)
So you actually want a wind direction indicator, not a digital compass ? All you need to do it read the pot position.
arduinow (author)  steveastrouk7 years ago
Thanks. But how do I know what the direction is from the pot reading without having any previous calibration?

Once again thanks.
You don't. You use a compass, you sight up a local landmark, then align the vane with that. Why be more complicated ?
arduinow (author)  steveastrouk7 years ago
haha, I decided to do that for now. I had in mind to develop something which would be straight forward to setup, but I'm only prototyping for now, so yeah, keeping it simple. xD

Thanks.