Pages: [1]   Go Down
Author Topic: Dual element PIR for motion tracking  (Read 2273 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, I want to set up a circuit based around a dual element PIR sensor (D203S, datasheet here: http://www.electronikdreamz.com/data/sensor/d203s.pdf)

The idea is to be able to build a device with a servo in order to follow someone around a room. This is why I bought a dual element PIR sensor, in order to sense if the person is moving from left to right and vice versa, and to step the servo accordingly, following the person around the room by keeping them centralized in the sensor.

I assumed this could be done using analogRead in order to get a base number when nothing is in view of the sensor, and a higher(lower) number when someone is to the left of it, and a lower(higher) number when someone is to the right of it.

I don't seem to be seeing any change in value from the sensor though, could this be the code or the hardware wired up wrong?

Here is the code i am using:

Code:
int calibrationTime = 10;

int pirPin = A0;
int ledPin = 13;
int pirVal = 0;


void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }


void loop(){

     pirVal = analogRead(pirPin);
     Serial.println(pirVal);
     delay(200);
}

The code is very basic at the moment, this is just to test if I have wired the device up correctly, and to see the changes in values when I move my hand near it.

Am I doing something wrong?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31431
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code looks fine. How have you got it wired up, the data sheet suggests you need a 72dB gain amplifier, that is a lot of gain you won't get any signal connecting it directly to the arduino. Your amplifier could be saturated with the DC offset if you don't design it correctly.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connected using the arduinos 5v out to a LM358N op-amp using a 10k and a 100k resistor for the amplification.

The sensor itself has a V in of the arduinos 3v3 output, and the op-amp is using the 5v output, which i would hope allow for enough gain to show any significant change in input.

I have the sensor connected up to the Analog input (as shown in the code above) which i hoped would allow me to have a little leeway before performing any action (a sort of jitter elimination method) should this work? does the sensor need to be digital?

Thanks for the reply smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31431
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With those two resistors you can only have a gain of 10, to get what is recommended you need a gain of over 6000 so it is no wonder you are seeing nothing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, it appears to be working, I swapped out the PIR for a D203B sensor instead of the D203S, and swapped out the resistors for a 1ohm and a 10k ohm resistor.

Am I correct in saying this will give me 10000 times gain?

Many thanks, n00bz0rz.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31431
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Am I correct in saying this will give me 10000 times gain?
Only in theory. 1R is too low for the op-amp's output impedance and you are probably just getting the open loop gain. I wouldn't put R1 lower than 100R but R2 can be up to 1M, still you might be limited by the real open loop gain of the amplifier.
Logged

Pages: [1]   Go Up
Jump to: