2
\$\begingroup\$

I used this circuit as a reference to drive a relay from the digital output of an arduino. This circuit worked as expected.

schematic

simulate this circuit – Schematic created using CircuitLab

Instead of controlling the 2N2222 with the arduino, I then tried to control it with the Panasonic EKMC1601112 motion sensor. The results were not good: I noticed that the output kept flickering on and off, even with no one in the room. I measured the output of the sensor and found that it was 5V when "on" and about 0.1V - 0.2V when "off".

I have several questions about this.

1) I'm assuming that 0.1V is enough to turn the 2N2222 on, which causes the flickering behavior. Does that sound right?

2) I know I can run the output of the motion sensor into the arduino (and I eventually will do that) but how can I adjust the existing circuit? Is the issue proper transistor biasing?

3) If I'm reading the AtMega328 data sheet correctly, when powered by 5V it recognizes a "low" signal up to 0.3V. So I should be fine if I use a digital input. What is normally done...is that "good enough" or would you do something to lower the voltage that appears at the AtMega input?

I'm assuming that the problem totally goes away if I connect the sensor to an analog input on the arduino. And again I may do that, but I really would like to understand the other issues involved.

\$\endgroup\$
  • \$\begingroup\$ What makes the 1N4148 better? Slightly lower V_F? \$\endgroup\$ – Rick Jan 23 '14 at 15:02
  • \$\begingroup\$ Never mind, didn't read close enough. That won't help. \$\endgroup\$ – Matt Young Jan 23 '14 at 15:08
  • 1
    \$\begingroup\$ Try adding a pull-down resistor to the base of the transistor. The sensor has a P-channel mosfet output which will not drive the output low when not detecting. (This is shown in the wiring diagram in the datasheet) \$\endgroup\$ – Tut Jan 23 '14 at 15:59
2
\$\begingroup\$

There is a basic digital wiring diagram in page 11 of the datasheet you have linked

enter image description here

There is a note (and the specs table has this too) that the sensor can only source 100uA, so you need to use a high value resistor for the base, something like 100k which will sink about 43uA (assuming 5v supply) and a resistor from base to ground in the range of 1000K or so. As a load in the collector you should place a resistor of about 10K-100K (I would say 47k).

This will still not solve the hysteresis problem, the transistor will turn on/off rapidly when the sensor detects motion.

One solution for that is to feed a pin of your mcu from the collector of the transistor, detect the change and apply the delay in software.

The other solution is the circuit provided in the same page of the datasheet that uses a timer to add delay

enter image description here

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Good call on the resistor values. Making that correction would only make my answer redundant so I'll delete and up-vote yours. \$\endgroup\$ – Tut Jan 23 '14 at 17:16
  • \$\begingroup\$ @Tut I thought of writing a comment under your reply but changing the resistor value would only solve part of the problem because the transistor would turn on/off rapidly. I decided to write a reply instead to mention some of the possible solutions. \$\endgroup\$ – alexan_e Jan 23 '14 at 17:27
  • \$\begingroup\$ About the 100k resistor sinking 43uA: is that because the min base-emitter voltage is ~0.6V giving ~4.4V across the resistor? \$\endgroup\$ – Rick Jan 23 '14 at 17:33
  • \$\begingroup\$ @Rick Yes, it's about (Vdd-Vbe)/Rbase . It's an approximation because the voltage of the sensor output may be lower (like 4.5v or 4v). Also the resistor from base to emitter will be sinking some current too. \$\endgroup\$ – alexan_e Jan 23 '14 at 17:40
  • \$\begingroup\$ possibly dumb question, but does this mean there is about 0.6uA across the 1M resistor, and about 56.4uA into the base? My transistor knowledge is a bit fuzzy (a big understatement!) \$\endgroup\$ – Rick Jan 23 '14 at 17:46
1
\$\begingroup\$

No, 100 mV is not enough to "turn on" the transistor. I won't conduct significant current until the base is at least 500 mV. More likely it will be at 600 mV or more when the relay is being turned on.

Look at the sensor output when the transistor is connected. It may not be 5 V at for the high level. You need to characterize this sensor output better to understand what is happening and what circuit would properly trigger a relay from it.

Many of these sensors have open collector outputs, or open collector with a pullup. This means that they actively pull low and passively float high, sometimes requiring you to provide the passive pullup. Find out the real specs for your sensor.

The flickering on and off may be due to feedback thru the power supply. The noise or voltage drop on the 5 V supply from powering the relay may be causing noise on the sensor output.

In general, you want a little hysterisis in detecting the sensor output. A simple single-transistor relay driver like this doesn't have hysteresis. You could achive that with two transistors, but again, we need better specs on the sensor output before it makes sense to recommend a particular circuit.

| improve this answer | |
\$\endgroup\$

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.