My little weather station is run on a Nano and has the anemometer and the temp/humidity sensor. A smoke detector is on the way because I live where wildfire is a big concern.

I would like to build a simple weather vane without spending a lot to buy the commercial solutions. Rotary potentiometers have dead spots and using a bunch of hall effect sensors would use up too many digital inputs to be useful, afaik.

Question: How can I build a simple direction sensor?

  • 2
    There are two-axis analog hall sensors that detect the orientation of a magnet, but they cost a bit more. You could probably make yourself a low resolution absolute optical encoder with hand tools or a 3d printer. – Chris Stratton Oct 26 '16 at 5:16
  • 1
    Use two pots with the dead-spots at opposite ends. – Gerben Oct 26 '16 at 8:40
  • 1
    Not sure but I think you should be able to use a magnetometer (compass). 5US on Amazon.com could afford you something good enough. amazon.com/HiLetgo-HMC5883L-Electronic-Compass-Magnetic/dp/… – Dat Ha Oct 26 '16 at 11:45
  • Thank you for your pointer. Here is the one I just ordered: amazon.com/gp/product/B00SDTFI1Q/… – SDsolar Oct 27 '16 at 23:35

Its a long time since I looked at this and the details are a bit misty, so sorry for the inaccuracies, but I'm sure people will correct them for me :)

I originally brought one of these http://www.maplin.co.uk/p/maplin-replacement-wind-direction-sensor-for-n96fyn96gy-n81nf and then decided to take it to bits, like you do.

The vane spins a magnet around and this triggers 1 of 8 reed switches as it passes around. The read switch is connected to VCC and a resistor and the resistors feed into a common wire back to the microprocessor. The 8 resistors all have different values, so the result is a differing output voltage depending on which reed switch has been triggered.

So what you need is:

  • A magnet
  • A number of read switches positioned far enough apart so only one is triggered at a time
  • A number of different resistors

Supply 5V from you Nano and read the result on an analogue pin, then come up with a calibration table to work out the direction.

I hope that makes sense. (Sorry I can't draw you a circuit diagram)


Another option (similar to reed switches) is to do it optically.

The vane is on an axle. The axle has a disc attached to it. The disc has a small notch out of the edge.

Positioned around the edge are a whole series of photo-interrupters. The disc spins between the infra-red beams and the notch allows only one of them to pass light at a time.

Make the notch the right size so that as one interrupter turns off the next one turns on - you need one on all the time. You could over-compensate slightly so that on occasion two adjacent interrupters are on at once, in which case you can say it's between the two.

A similar system is to use a disc with a series of special slots cut in it (see Gray Code) which allow light to pass through onto a line of photodiodes. In different rotations different combinations of photodiodes are on, and that gives you your direction.

  • 1
    The Arduino has plenty of pins (unless you're using lots and lots of them already). Think KEYPAD. – Majenko Oct 27 '16 at 21:03

I decided to go with 4 reed sensors. With experimentation I found I can successfully detect 8 distinct directions using 4 reed switches since the rare-earth magnet will switch two on at once when it is in between.

Thank you all for your answers. Upvotes for everyone for the discussion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.