Forgive my naivety but I seem to lack a vocabulary for the whole electronics domain...

I'm interested in building something to measure wind direction. Inspired by this design I would like to build a circuit of a number of reed switches (say, 8). For the sake of simplicity, let's say only one of them will be active at the same time. Although I could connect each switch directly to separate pins on the Pi I would like to combine the switches into one, common output to the Pi. Somehow.

I'm picturing me some sort of chip that could go in between my circuit and the Pi. The switches could be numbered 0-7 and the chip could output a binary number corresponding to the currently active switch.

The question is, does something like this exist? Could it be built relatively easy?

  • Yip. an I2C ADC controller. Each reed switch then you put a resistor of different value which gives you an analoque voltage. eg 3.3volts input -> R1 -> 0.3v-0.4 is the east read switch and just do it for the rest.(just like the link you provided actually but you want different values on R9-R16) This is how the sparks fun weather stuff works. You have a truth table depending on voltages applied. Cheap an easy 2 GPIO pins which can be extended to more I2C devices, like temperature, light, humidity, rain counter, and Geiger meter, if you like. – Piotr Kula Nov 16 '14 at 20:58

The B+ has 26 usable gpios. In that context 8 doesn't seem a lot.

In effect you are trying to trade off the number of gpios used against complicating the circuit.

Have you considered a port expander, such as the popular MCP23017? That connects to the I2C bus (two gpios, SDA and SCL) and provides an additional 16 gpios per chip. Up to 8 MCP23017 may be connected to the same I2C bus. Additional types of I2C devices may also be connected to the I2C bus at the same time.

There are plenty of tutorials on the www of talking to the MCP23017 and similar using Arduinos and the Raspberry Pi.

Any other solution you come up with may be more complicated in hardware and software.

  • I was afraid this would be complicated. However, the port expander seems to solve the problem nicely. I can tuck all the wires away and only connect a few to the Pi and put all the logic in the code (which I know the best). Thanks for your help. – fiskeben Nov 15 '14 at 23:55
  • This is a little bit overkill. ADC chip would be better, easier and cheaper maybe? – Piotr Kula Nov 16 '14 at 21:02
  • @ppumkin If I was designing one I'd search for a rotary potentiometer which allowed continuous rotation. Each rotation going from minimum to maximum resistance. Sort of analogue equivalent of the discrete resistor ladder. Not sure if such a pot exists. – joan Nov 16 '14 at 21:57
  • Makes sense but then you have to waterproof it properly and also it has a lifetime. Where the reeds and resistors are all sealed with a much bigger life time and causes no resistance to wind as it sits on a free axis. – Piotr Kula Nov 17 '14 at 8:55

What you are asking for is a port expander, like joan said.

If you want a lower-level or cheaper solution, you could control 12 devices with 4 wires using Charlieplexing, but that is more complicated.

Like joan said, GPIOs are plentiful on the rPi, but if you are hoping for a low-wire count solution to have your sensors far away from the rPi, you will almost certainly need at least 3 or 4 wires, either Charlieplexing or i2c with power and ground. If you have a long i2c line, be careful to have a sufficient pull-up resistor. Good luck!


A simple star analogue design.

Feed your voltage in 3.3volts lets say. Then from the "centre point" (Pin 1 Vcc) you calculate a set of resistors that will give you various output voltages when the reed switches activate which can be measured (Pin 4 Vdd)

enter image description here

image source Weather Sensor Assembly p/n 80422

This is a truth table based on 5volts input but it shows you an example of the resistors used. You need to take into consideration the 10K resistor on input (not shown on diagrams) to prevent short circuit.

enter image description here

image source Weather Sensor Assembly p/n 80422

You have to take into consideration that two reeds may be active at the same time and they should not give the same value as any other 1 reed.

You then only need 1 channel to read 8 switches. Here is a cheap 2USD chip on its own but ebay has pre built or kits for a similar price using I2C

enter image description here

You can then wire it up like this. All I2C will be the same..

enter image description here

You then have the freedom to code in Python (I2C Library), Mono C# (sharp IO) or direct from the console with scripts (using GPIO Utility).


Does not sound robust to me. What when NO reed switch is closed? Mechanical adjustment must be perfect to have a single switch closed and not two or none. It is easier to get all switch states into the Pi and sort the wind direction out in software.

  • What if the mechanical adjustment is at least 1 but 2 on overlap. Then its robust. – Piotr Kula Nov 16 '14 at 21:32
  • So you have precise mechanics, non-standard resistors, and i2c and adc functions opposed to a straightforward i2c port expander -- your choice! – Cornelius Nov 16 '14 at 22:25
  • non standard resistors? – Piotr Kula Nov 17 '14 at 8:56

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.