I am in the process of building a water meter counter using a Pycom Lopy. The Lopy operates at 3.3v but my input sensor which is a metal detector (K1208065) uses 12V.

Someone else has already build a similar counter using a raspberry PI with a piface. This is the circuit that is used:

enter image description here

I bought the reed relay (SIL121A7272L) as described in the circuit. However I couldn't get it to work. What I did to troubleshoot is:

  • Measured resistance between pin 3 and 5 (1k resistance as expected)
  • hooked up a multimeter in continuity mode on pins 1 and 7, I expected that when detecting metal (pull down the signal) the continuity mode would buzz. However that did not work.
  • Tried swapping the coil and switch pins (opposite from what is described in the circuit)
  • Tried using another reed relay, I actually bought two.

After I could not get the circuit to work, I decided to protect my input pin using a simple voltage divider. I used 100k and 33k values, because that is what I had laying around. The result was a voltage of 2.98V which is detected by the Lopy as "HIGH", but the signal is not stable. It jumps around from "HIGH" to "LOW" every now and then. My thought is that this might be because of the resistor values being to high, is this correct?

Any thoughts on getting the reed relay to work, or getting the voltage divider stable are very welcome. Any other solutions to protect the input are welcome as well.

  • \$\begingroup\$ Driving a transistor (MOSFET or Bipolar) should be safe. An optocoupler would be safer. Reed relay is OK but has finite lifetime and is more fragile. Datasheets .... 71L seem hard to pin down data from but appears to have 1000 Ohm coil which MAY overload IC. \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 8:11
  • \$\begingroup\$ Can you recommend an optocoupler type and configuration (circuit)? Any suggestions why my reed relay is not working? \$\endgroup\$ Mar 6, 2017 at 8:59
  • \$\begingroup\$ What is the meter maximum output pulse rate? \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 10:09
  • \$\begingroup\$ Relay should work - see my answer - or 2 resistors. Opto can be any that take a few mA to operate and have an output that suits you. ie almost ANY opto. Use a series input resistor to limit current Iopto_in = (Vdrive - Vopto_LED)/Rseries in ~~= (12-2)/Rseries. Or Rseries ~= 10/I_opto_in_mA. 3K3 OK for an opto that needs < 3 mA etc. \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 10:12

2 Answers 2


The sensor is shown here

It says that it has a PNP output switch with positive logic output.
This means that the output (black) is open circuit when off and outputs V+ when on.
The reed relay needs to connect from output to ground = (based on your image) Black (output +ve) to blue (ground).

If your uC (microcontroller requires a 0/3.3V signal you could divide the output by 4 to give 0/3V operation.
eg 39k + 10k from output to ground with output from the centre point.

Your 100k / 33k may be OK - but the Pi-Face will have some upper limit to the input impedance. Even eg a 10k/3k3 will probably be acceptable as that draws only 12V/(10k + 3k3) or ~~= 1 mA from the sensor.

Variation in the output can be "slowed" using a capacitor from centre tap to ground or even in this case from the sensor output to ground.
Divider point to ground = slower on than off.
Sensor out to ground = fast on, slow off.
Too big a capacitor on sensor output MAY damage it.

Time constant on R centre point is ~~ C x (resistance of two R's in parallel) for turn on and C x Rlower for turn off (if PiFace input resistance is high.)

What is the meter maximum output pulse rate?

  • \$\begingroup\$ Actually the sensor operates the other way around (from what I have seen). The sensor is V+ when no metal is detected. And pulled down when metal is detected. The meter has a metal disc which rotates every 1 liter. So that could be quite a rate when water is flowing massively. What capicator value do you recommend? \$\endgroup\$ Mar 6, 2017 at 10:38
  • \$\begingroup\$ @Maartentech Why not make life too simple for us and priovide links for the items used. You should be able to just paste them if the system does not yet let you insert them properly.| Sensor polarity: If the sensor datasheet I found is close enough to yours and has "positive logic output" then on = high = 12V usually. If yours behaves differently it would be lovely if you told us. Or tell us what it does do. (You mentioned 2.98V but did not say when it was there and what else was there). \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 11:55
  • \$\begingroup\$ @Maartentech Cap value: Vee ask zee qwestchins around heer !!! | :-) | I asked the rate to help size the cap. Based on your answer it would be "about K x 1/(Flowing_massively). K may be 1 or some other value :-). As we don't know if this is a tail-race, down pipe, jet-boat nozzle or ...? we need YOU to quantify "massively" . | That said. T= RC is time constant. At 100 l/s that's 100 Hz pulse rate. If your bottom R is 10k and you put the cap on the tap then you want 10k x C < 0.01s by a resonable amount. So eg C = t/R = 0.001s/10k = 0.1 uF may be an OK starting point. ... \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 11:58
  • \$\begingroup\$ @Maartentech ... All that does is slow the rate of change so a quick occasional blip may not get seen by the uC. If the output is noisy (which you'd expect it NOT to be) then you can probably denoise it in software. You can use a hardware Schmitt trigger but software is "free" and takes up no PCB space. \$\endgroup\$
    – Russell McMahon
    Mar 6, 2017 at 11:58
  • \$\begingroup\$ Sorry about not providing the links to the components used. Here are my components: Water meter (it is a residental watermeter): Sensus 620, static1.squarespace.com/static/5019e8afe4b01ee276c09ae3/t/… Microcontroller is a Lopy: pycom.io/product/lopy And the sensor is the one you posted. The sensor behaves the other way around as I mentioned. When metal is detected it is LOW = 0v. And when no metal is detected (normal operation) it is HIGH = 12v. \$\endgroup\$ Mar 6, 2017 at 12:17
  1. Relay:

The (LoPy) input is floating (if connected to the relay output, like in the OP's diagram) when the relay is open and 0V when closed!

If so, use a 10k pull-up resistor to 3V3 or set pull-up in software! Then the LoPy will "see" 0V (LOW) when the relay is closed and 3V3 (HIGH) when the relay is open.

The relay output DOES NOT have 12V on it (It is galvanically isolated from the input (coil)). The output is (open) open-circuit OR short (closed-circuit), that's it! Therefore, there is no need for any doltage divider with the relay!

  1. "Opto":

The optocoupler (AKA: optoisolator, opto) behaves similarly to a relay, but uses light instead of electro-magnatism. This will be fast responding & reliable (within specs). They generally require less current to drive, but the output generally supports less current than a relay (you will require very little current for this application, anyway).

You will have to set the current (via a resistor) through the LED side: Say the LED (input) side is rated at 2V 10mA: R = (Supply-LED_voltage)/LED_current = (12-2)/10m = 1kOhm.

It will not be possible for 12V to appear on its output!.


simulate this circuit – Schematic created using CircuitLab

  1. Voltage divider:

I you go with the (much simpler and more reliable) voltage divider, it should work fine (without pull-up or pull-down resistor). The danger/risk with this is that if the 0V side of the divider becomes detached, 12V will appear on the LoPy (although limited by the 100kOhm resistor).

  1. Debounce:

If you know the maximum rate of the pulses, you can ignore any unwanted signals in between the pulses (in software); a form of debounce (there are a few ways to debounce!)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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