0
\$\begingroup\$

I am designing simple security system to protect 20-30 windows (total length about 50m) with vibration sensors (based on SW-420 modules). Window are on the roof and due to environment i use optocouplers for controller isolation.

I want all of that sensors to be connected to one wire, something like Logic OR.

enter image description here

Explanation:
When sensors has LOW on OUT pin, optocoupler cathode has ground pulled via R21 resistor - controler pin has LOW.

When sensor is active, transistor Q sends 5v to optocoupler cathode, and IO pin getting HIGH via Pullup resistor R20.

Note: I places pulldown resistor at the end of line. So if signal or ground wire is terminated (cutted, disconnected), alarm will be activated.

I tested this circuit with only two sensors (don't have any more). Look's like working well. But i am worrying about stability and safeness when there will be 20-30 sensors on single line 50m long.

Also i were trying to replace sensors with HC-SR501 PIR Motion.
Unfortunately this circuit not working. Looks like 3.3v with 0.6v drop cannot drive 2N2222. May be other transistor will work?

So, will this circuit works stable and safely when scaled up? (may be some capacitors).
Also is R23/R24 resistor is necessary (i tried without them, and placed in schematic just in case).
Is 2n2222 is right choice for this circuit?

UPDATE

Another idea is breaking connection between led cathode and ground with mosfet

enter image description here

Will this works?
Is 2kOhm for mosfet gate pullup is enough/to much?
Will mosfet close when transistor closes?

\$\endgroup\$
  • \$\begingroup\$ a datasheet for the SW420 would be necessary to know how much it can drive. And your circuit does not work, unless your optocoupler can work with less than 0.5mA of current through its LED side. (it doesn't) \$\endgroup\$ – Marcus Müller Feb 10 at 15:57
1
\$\begingroup\$

Look's like working well.

Unfortunately this circuit not working.

Please make up your mind. My vote is that it's not working, and it never will. Let's look at a single unit.

schematic

simulate this circuit – Schematic created using CircuitLab

Let's assume the input is at zero volts. Then, for a Vf of 1.2 volts (which will not be quite right, since that's the nominal value at 20 mA), the total current will be 0.31 mA, and the voltage at the transistor emitter will be 3.1 volts.

If the input voltage goes to 3.3 volts, this only produces (at most) 0.2 volts across the base-emitter junction, and the transistor does not turn on.

Even if it does turn on, it cannot lift the LED anode to more than 3.3 volts, and this will not turn off the LED.

I suggest you try this

schematic

simulate this circuit

Replace the 10k resistor with a 200 to 500 ohm resistor. This will produce a much lower voltage across R1, and will allow the transistor to operate. With 2k on R2, the LED current will only be about 2 mA or a bit less, so the transistor should have no difficulty, and the transistor will act to directly bypass current from the LED.

\$\endgroup\$
  • \$\begingroup\$ I tried you suggestion, and it is working with both 5v SW-420 and 3.3v HC-SR501. But in your approach i have to use forth wire to every transistor collector, which i was planning to use for tampering and positive wire termination control. Anyway. Do you think your "bypass" approach will work on long distance - 20m - 50m? \$\endgroup\$ – Y Borys Feb 10 at 18:59
  • \$\begingroup\$ @YBorys - Sure. Just not for every data rate. It will have an upper limit which you will have to determine for yourself. And sorry about the fourth wire issue, but you did not include that in your question. \$\endgroup\$ – WhatRoughBeast Feb 10 at 19:03
  • 1
    \$\begingroup\$ @YBorys - Sure. The simplest is to use a mechanical relay with a NC contact. You can get 5 volt versions, and pc boards with logic level drivers for Arduino and other processors. Or, you can use an n-type MOSFET with a transistor in front as an inverter. \$\endgroup\$ – WhatRoughBeast Feb 10 at 22:27
  • 1
    \$\begingroup\$ @YBorys - Yes. Exactly. Also note that you don't need base resistors on your sensor outputs. Plus, you can tie all of your 2N2222 collectors together and only use a single 2k pullup and a single 2N7000. But be careful about substituting any other MOSFET for the 2N7000 - not all will work. And the new circuit will be marginal if you drive the sensors with 3.3 volts. It may work, and it may not, and it may do it on the bench but be unreliable in the long run. \$\endgroup\$ – WhatRoughBeast Feb 10 at 22:51
  • 1
    \$\begingroup\$ @YBorys - They should work. The Vgs(th) issue is that, for "regular" MOSFETs the turn-on voltage is specified between 2 and 4 volts, but this only allows small currents (like, typically, 0.25 mA), and this is not enough to reliably activate your particular circuit (recommended gate drive for power applications is 10 to 12 volts). The reason logic-level FETs are called that is precisely because you can use them by driving the gates with logic (3.3 to 5 volt) logic chips. \$\endgroup\$ – WhatRoughBeast Feb 12 at 16:00
2
\$\begingroup\$

I want all of the sensors to be connected to one wire, something like Logic OR.

You circuit does not work for multiple reasons:

  1. As pointed out by @Marcus, the current in the PC817 input diode is chronically low, and unlikely to produce a signal for your MCU.
  2. The 1k Ohm resistor will (depending on the SW420 variant you have) result in signal indicator failing to turn off.
  3. Your logic is incorrect since the output of the SW420 is normally high, and goes low on breaking the sensor.

There are two major circuit configurations for the SW420.

This is the original Grove schematic from which most others derive:

enter image description here

Read the setup and operation here.

The typical Ebay/Alibaba SW420 circuit is like this:

enter image description here

I would suggest the following configuration would work with either variant:

schematic

simulate this circuit – Schematic created using CircuitLab

Here the current in the PC817 is set to about 5mA and if ANY (OR logic) of the sensors trigger low on the out pin the current is applied to the PC817.

Update: Since the modules you have appear to be logically reversed (perhaps they have reversed the input pins on the comparator) you can still use FET OR'ing, but would need to change the circuit to suit.

schematic

simulate this circuit

You would have to take care and check that when buying modules they produce all produce the same logical output.

\$\endgroup\$
  • \$\begingroup\$ I use "Chinese" version of SW-420. I measured voltage and it is 0.15v in "standby" mode and almost 5v in active mode (alarmed). So it trigger HIGH when shaked. Are you sure your circuit will work, before i buy mosfets you suggected? \$\endgroup\$ – Y Borys Feb 10 at 19:04
  • \$\begingroup\$ I assume you have the adjust pot turned all the way to the gnd end. Read the description here: wiki.seeedstudio.com/Grove-Vibration_Sensor_SW-420 Adjust the pot to have VCC/2 (midway) and you should see the correct operation. I don't think I have it wrong. \$\endgroup\$ – Jack Creasey Feb 10 at 19:37
  • \$\begingroup\$ Tried this. Still the same. May be we are talking about different modules. I use like this: theorycircuit.com/sw-420-vibration-sensor-arduino-interface \$\endgroup\$ – Y Borys Feb 10 at 20:06
  • \$\begingroup\$ With no vibration, is the Signal LED ON or OFF? \$\endgroup\$ – Jack Creasey Feb 11 at 2:09
  • \$\begingroup\$ ON. But voltage is 0.15v. When vibrate - led is OFF - voltage HIGH. \$\endgroup\$ – Y Borys Feb 11 at 9:51
0
\$\begingroup\$

When sensors has LOW on OUT pin, optocoupler cathode has ground pulled via R21 resistor - controler pin has LOW.

That's wrong.

When all sensors are OUT=LOW, then we can just mentally "remove" the transistors from the circuit, which boils down to:

schematic

simulate this circuit – Schematic created using CircuitLab

So, that's 12 kΩ in series with the LED.

Hence, the current through the LED is If=(5 V - Vf)/12 kΩ . Since the datasheet suggest the thing won't turn on below a forward voltage of 1 V, If_max = 4V/12kΩ = 0.33 mA.

That LED has full brightness at 20 mA; at 1/60 of that, the Optocoupler won't work reliable.


The solution would be very easy: just tie all your OUTs together (if necessary for protection, with a diode each, and use that either directly as high side of your LED, if current sourcing of the SW420 allows, or connected to the base of one of your low-side NPN switch transistors.

\$\endgroup\$
  • \$\begingroup\$ I really don't know why, but i swear it's working. I mean with 12kOhm i have LOW on my IC pin (i use programming pullup in my arduino nano). I know that optocoupler led should be powered with at least 5mA. It definetly not working with 20kOhm (22 in total) - i tried. Unfortunately optocoupler and 2k resistor is part of ready made board and i have access to cathode (low side) \$\endgroup\$ – Y Borys Feb 10 at 16:53
  • \$\begingroup\$ Depending on which type of SW420 the OP has you CANNOT just wire OR the outputs. \$\endgroup\$ – Jack Creasey Feb 10 at 16:54

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.