Electronic – Control relay from sensor output when LOW is 0.2V

biaslogic-leveltransistors

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.

Best Answer

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