PIR sensor project

Discussion in 'The Projects Forum' started by fila, Jul 18, 2012.

  1. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    Hello!

    I am in the making of a PIR (passive infrared) sensor which will detect human motion. It is for my final project.

    It consists of three parts: a PIR sensor, amplifier and a comparator. I don't want to bother you (yet) with the whole design. For now I have a question about the comparator part.

    I have attached two images. In one of them I use LM358 op amp as a comparator, and in the other LM393 (open-collector) comparator.
    LM358.PNG

    LM393.PNG

    Vcc is 12 V in both cases. The input signal comes from the SenzorOutput line which carries the amplified signal from the PIR senzor. It can vary from 0 to 12 volts but in a steady state it is 4 V. Values for the resistors R12, R13 and R14 have been chosen to detect a signal which is higher than 6 V and lower than 2 V. The TRIG line is connected to the TRIGGER pin of the 555 timer. So you can see that I want to trigger the 555 when the signal goes above 6 and below 2 volts. I've read on the Internet that to trigger a 555 you need to go below Vcc/3 and that TRIGGER pin shouldn't be held low for too long. I realize that we need capacitors to accomplish that. When the output signal from one of the op amps (comparators) goes from Vcc to 0 a negative impulse is created and since we have some sort of a differentiator circuit on the right a negative spike is created. Because of the spike the voltage on the TRIG line should decrease. In the ideal case it should fall to 0 V.

    Now here comes the fun stuff. When I use a LM358 in the design the 555 doesn't get triggered. But when I use LM393 it triggers just fine. A simulation program (LT Spice IV) predicted this. I used different models in the simulation, LT(something) OP AMP and an LT(something) COMPARATOR but I think that is irrelevant. I also measured the signals with the oscilloscope and saw that when using the LM358 the generated spike is lower in magnitude than the LM393 spike and it doesn't reach the desired 12/3 = 4 V.

    How can you explain this effect? I guess it has something to do about LM358 and LM393 circuitry but I can't figure it out. If I replace LM358 with some other dual op amp (LM747) will it make any difference?

    I was advised to use LM747 in the design and NOT the LM393.

    Thanks for reading. :)

    EDIT: The following text should have been in this first post when I started the thread so I am just copy-pasting it from the second page. The text explains my second problem in this circuit.

    So here is the whole thing:

    circuit_diagram.png 555.png

    The amplifier part of the circuit and the values are from the datasheet application example. I added the comparator and the 555.

    So let's start from the left.
    The FET_N thing is the sensor IRA-E710ST. It is modeled as a FET with some extra stuff connected to the gate but that is not important. R1 (10k) connected to the Vcc (12 V) is there for safety reasons. The DC value for the Source is approximately 1 V. When the sensor is powered up it registers changes in temperature, that is infrared radiation. So when you move your arm in front of it small signals are generated at the Source. The idea is to amplify them. The band pass should be between 0.22 Hz and 10 Hz.
    R3 and C1 make an integrator with the cutoff frequency 16 Hz. After the integrator comes the first order active band pass filter (non inverting). Voltage at the non inverting input is 1 V from the Source plus the small generated signals. Voltage at the inverting input should go from 0 volts (when we start up this whole circuit) and stop at the 1 V. But it doesn't!!! I am not a great expert in op amps and I have studied negative feedback. And since we have connected the output to the inverting input we have a negative feedback. So after some time v+ and v- should be almost equal. Am I correct?
    But what happens is that v+ goes over 1 V and the first op amp saturates. So at the output I have 12 V. That messes up the second stage (op amp) so the whole thing doesn't work. Am I missing something? Is there a possibility of oscillation or positive feedback in this circuit?

    I have to emphasize that this is the SECOND time I am constructing this part of the circuit on the breadboard (don't ask why, please). First time (couple of months ago) this worked perfectly.

    Here is the simulation. After you start it up it should look like this.

    DC_values.PNG

    1st_INVERTING is the inverting input of the first op amp and 1st_OUTPUT is the output. Voltage at the inverting input should settle down at around 1 V. After that the output should go down to 1 V also because for DC values op amps act as voltage followers.
     
    Last edited: Jul 21, 2012
  2. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    The LM358 is too slow to get enough of a pulse thru the capacitor to trigger the 555. I had a similar problem recently when trying to trigger a 4017 counter IC thru a capacitor. I switched to a TL082 (faster and available locally) op-amp and this fixed it. A comparator is even faster and swings farther, though. If you want to use an op-amp, look for a high slew rate and a rail-to-rail output.
     
    absf and fila like this.
  3. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    Why? That op-amp has a low slew rate of 0.5V/µs. That's MUCH slower than a comparator and similar to the LM358 you already know doesn't work. The LM393 will switch rail-to-rail in 1.4µs.

    My first boss was a grade-A tool, but smart and full of advice. One thing he told us repeatedly was to always ask "why"?
     
    absf and fila like this.
  4. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    I don't know why I was given that advice. :)

    So in general it is much better to use a comparator than an op amp in these type of applications where you have to compare voltage levels?
     
  5. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    As a sweeping generalization, yes. But in your case the problem is related to speed. For DC or slow circuits, even slow op-amps can make fine comparators. And there could be special situations where an op-amp with particular properties would be best (ultra high impedance inputs or higher power handling examples come to mind). But a purpose-built comparator IC is likely to be superior in most instances.
     
    absf likes this.
  6. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    I've been doing some calculation and research and found something. Assume a steady state, that is SensorOutput voltage is 4 V. We can model the op amps as the 12 V voltage sources. Now imagine that the input signal goes above 6 V. The output of LM358 unit A goes to 0. We can model that transition as an impulse (in this case make it ideal, slew-rate is INFINITE).

    I attached a picture with explanations.
    LM358_Thevenin.PNG

    So the crucial thing is that when using an LM358 there is a loop containing nothing but capacitors (negligible resistance)! Using the good old Thevenin I get the equivalent impulse that is HALF than the original and equivalent capacitance Ct = C1 + C2 = 0.2 μF. Maybe this is the problem. The all-capacitor loop lowers the magnitude of the impulse and the spike.

    In the LM393 design the necessary 10k resistor is in series with the capacitor so there is no all-capacitor loop.

    I don't know what is the right term for a loop containing nothing but capacitors and voltage sources. I call it all-capacitor loop. Correct me if I am wrong. :)
     
  7. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    And that helps you, how?

    Sorry, you lost me. I can't judge whether you're right or wrong, but that's on me, not you. You have little to lose by experimentation. I encourage you to use real devices often and not rely too much on simulations. They're incredibly useful but they have limits.
     
  8. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    wayneh I did some experimenting today on the breadboard and it appears that the LM393 design is not very reliable. It worked yesterday but when I tried it today it failed. To be more precise when I lowered the input voltage below 2 V it failed to generate a spike that would trigger the 555. When I increased the input voltage above 6 V it worked, then I tried to fix the problem and now that isn't working either.

    If you want to trigger a 555 timer (monostable) when you see voltage going above 6 V or below 2 V how would you do it?

    Edit: I've looked up 555 on the web. For example http://www.kpsec.freeuk.com/555timer.htm#monostable
    Look at the picture of the monostable circuit. The trigger is some kind of a switch. Should I use a transistor for this?
     
    Last edited: Jul 19, 2012
  9. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
  10. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    Your window comparator is the right approach. For an open collector comparator, you can OR the outputs by simply tying them together to a single pull-up resistor. The combined output will then go low if either one goes low. You need to have the right logic on the input pins to send the output low when the signal voltage leaves the window.

    You need to post your current circuit schematic before anyone can help you diagnose your problems with it. A photo of the build wouldn't hurt, either.

    It would also help to understand why you are using AC capacitive coupling for your output. You mentioned wanting to avoid holding the trigger low for "too long". This is only a problem in that a new timing interval cannot be started until the trigger goes high again. Is this really a problem? Consider the "edge triggering" advice in that link you posted, if you think you really need that.
     
    Last edited: Jul 20, 2012
  11. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    OK, I will post everything. It will take a while.
     
  12. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    It took me some time to convert Kicad schematic to pdf but I did it! :)

    So here is the whole thing: View attachment pir_schema.pdf .
    The amplifier part of the circuit and the values are from the datasheet application example. I added the comparator and the 555.

    So let's start from the left.
    The FET_N thing is the sensor IRA-E710ST. It is modeled as a FET with some extra stuff connected to the gate but that is not important. R1 (10k) connected to the Vcc (12 V) is there for safety reasons. The DC value for the Source is approximately 1 V. When the sensor is powered up it registers changes in temperature, that is infrared radiation. So when you move your arm in front of it small signals are generated at the Source. The idea is to amplify them. The band pass should be between 0.22 Hz and 10 Hz.
    R3 and C1 make an integrator with the cutoff frequency 16 Hz. After the integrator comes the first order active band pass filter (non inverting). Voltage at the non inverting input is 1 V from the Source plus the small generated signals. Voltage at the inverting input should go from 0 volts (when we start up this whole circuit) and stop at the 1 V. But it doesn't!!! I am not a great expert in op amps and I have studied negative feedback. And since we have connected the output to the inverting input we have a negative feedback. So after some time v+ and v- should be almost equal. Am I correct?
    But what happens is that v+ goes over 1 V and the first op amp saturates. So at the output I have 12 V. That messes up the second stage (op amp) so the whole thing doesn't work. Am I missing something? Is there a possibility of oscillation or positive feedback in this circuit?

    I have to emphasize that this is the SECOND time I am constructing this part of the circuit on the breadboard (don't ask why, please). First time (couple of months ago) this worked perfectly.

    EDIT: Here is a list of op amps and other stuff from my local electronics store http://www.chipoteka.hr/proizvodi/130516 If you think I should change the LM358 or LM393 for something else just let me know.
     
    Last edited: Jul 20, 2012
  13. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    Here are the circuits (some here don't like pdfs).
    [​IMG]

    [​IMG]
     
    fila likes this.
  14. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    I want to trigger the 555 with a negative spike but it keeps getting damped. For some reason the magnitude of the spike depends on the frequency of the signal from the SenzorOutput line. I am interested in the signals with frequency from 0.2 Hz to 10 Hz. When the frequency of the signal was below 1 Hz 555 got triggered otherwise it didn't. Then I put a 33 μF capacitor instead of a 0.1 μF and 555 got triggered below 3 or 4 Hz. But I am guessing that such high values are a bad idea. Or not? :confused:
     
  15. wayneh

    Expert

    Sep 9, 2010
    12,148
    3,058
    Try increasing the ohms of R17 by 10X or more, or even removing it.
     
  16. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    OK I will try it on Monday. I don't have access to the laboratory during weekends. What do you think about the saturation of the first op amp? Is the negative feedback strong in this circuit or is it unstable?

    Here is the simulation. After you start it up it should look like this.
    1st_INVERTING is the inverting input of the first op amp and 1st_OUTPUT is the output. Voltage at the inverting input should settle down at around 1 V. After that the output should go down to 1 V also because for DC values op amps act as voltage followers. Don't they?
     
    Last edited: Jul 20, 2012
  17. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    Just to update you wayneh, the sensor is working. The triggering is also OK but I've got another problem. Once in a while the circuit starts to oscillate. I am 99% sure what is the cause and I would like a suggestion how to fix that.

    It will be easier to explain with a picture. This is a simulation of what is actually happening in the circuit. The signal is measured on the SensorOutput line.

    555_problem.PNG

    From 0 to 3 seconds you see a typical response of the PIR sensor (after amplification) when somebody passes next to it or moves his hand in front of it. The signal comes to a steady state at approximately 3 seconds ( sometimes later ). Problem is that negative spike at t = 5 seconds. It shouldn't be there! I spent some time thinking what could be the cause of this and than remembered that I've selected the 555 time constant (R*C) to be 5 seconds. So I measured the signals on the pins of the 555 and discovered that the negative spike appears exactly when the voltage at the DISCHARGE pin hits the threshold voltage and drops to zero. So my problem is that the 555 is creating spikes on the Vcc line in regular intervals of 5 seconds. That is exactly equal to the time constant I have selected for the 555. Those spikes then get amplified and lower the voltage on the SensorOutput line below 2 V which then again triggers the 555.

    Please tell me how to fix this. Thanks.

    EDIT: Is this the solution to the problem -> http://forum.allaboutcircuits.com/showthread.php?t=45583
     
    Last edited: Jul 24, 2012
  18. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    I started working on my sensor again few days ago. I am now 100% sure that 555 timer is generating huge disturbance on the Vcc line (I read somewhere that it really does that). I looked at the 555 datasheet and it clearly stated that you have to put some bypass capacitors across Vcc and GND pins. So I did that (0.1u and 22u in parallel). That sort of attenuated the spike but not to the degree that I wanted to. Could someone look at the circuit diagram and advise me where to put some more bypass capacitors and why? With there values, types, etc.

    Thank you.
     
  19. donpetru

    Active Member

    Nov 14, 2008
    186
    25
    I really do not understand that this time is also complicated the world operational amplifiers, when all the above circuit could be implemented, for example, a microcontroller Attiny13! Really hard to be?

    You need to mount the power supply bypass capacitors on each integrated circuit. For example, 0,1uF is is an appropriate value. If you are looking for someone to help you realize PCB can tell me. I can help with wiring fee, for example, in PDF format, scale or I can give you 274X Gerber files, but they are more expensive.
     
  20. fila

    Thread Starter Member

    Feb 14, 2011
    64
    5
    donpetru

    I am not allowed to work with microcontrollers, and I have to design the PCB myself using Kicad. I already have a version of my PCB. I would only like to know what are the best places to put the bypass caps. Thanks for the reply.
     
Loading...