Friday, 28 January 2011

Processing (Pyroelectric PIR Part3)

I have decided to post the Processing code to render the data from the Arduino. This my first processing project. I have kept the code very simple and with that flexible. This code does not have to be used with a PIR sensor it could be used with any analog sensor on 2 servos.  

// GR0B Basic draw   - Robert Sturzbecher
// This is my first Processing project. The purpose of this project is to render the values received back from a PIR sensor on 2 servos to give a crude image
// server stepping on the Arduino is 3/180 if you use some thing different 
// I have made the code very generic and flexable to suit any project that outputs (X Y Value)

import processing.serial.*;

Serial myPort;                                   // Create object from Serial class
int val;                                         // Data received from the serial port
int ServoStepping = 3;                           // Change this to match the Arduino servo stepping  

void setup() 
  size(555, 550);                                //    ((180x3)+10)
  String portName = Serial.list()[0];            // you will get a error here if port not found or in use. [0] is first serial port found
  myPort = new Serial(this, portName, 19200);      

void draw()
 String xString = myPort.readStringUntil('\n');  // read the serial port until a new line
  if (xString != null) {                         // if theres data in between the new lines
    fill(0);                                     // set fill to black

    String[] SerialLine = split(xString,' ');    // split serial string line into array
                                                 // string from arduino should line like this "X: 90 Y: 80 Val: 154"
    int PosX = int(SerialLine[2]);
    int PosY = int(SerialLine[4]);
    int PIRVal = int(SerialLine[6]);
    PosX = PosX *3;                               // zoom pixel size. 1/180 now equles a 3x3 size
    PosY = PosY *3;

    // define Color   
    int R = (PIRVal - 120);                   // you will need to customise these values to your project
    int G = (PIRVal - 130);
    int B = 25;
    fill(R,G,B);                                 // set color     
    rect(PosX, PosY, ServoStepping*3, ServoStepping*3);                      // Draw colored square  
    //print some debug info to console
    print("RGB: "+R+" "+G+" "+B);
    println(" PIR:"+PIRVal);     

Pyroelectric Infrared sensors (PIR) Part2

Another one of my old posts that I am moving across

Pyroelectric PIR Part2
posted Jan 28, 2011 12:43 AM by robert sturzbecher   [ updated Feb 6, 2011 8:44 PM by robert sturzbecher ]
Woohoo Pictures

I have started to learn how to use Processing to handle the PC side of the image processing. 

The hardware is the same as in pyroelectric infrared sensors project with the exception of a little playdoh around the sensor to act as a lens the rest of the changes are software changes.

Here are some screenshots of the application after doing a full sweep. Can you see me on the right and the light on the left?
Each square is 5 degrees in size. About 2 mins to capture.
from side to side it is a total of 180 degrees and 60 degrees high

2 degrees resolution. And about 5 mins to capture

Monday, 24 January 2011

Pyroelectric Infrared sensors (PIR) Part1

Thought I might start moving some of my old posts across from my old site and put them all here in one place.

Pyroelectric Infrared sensors (PIR) (thermograph)

posted Jan 24, 2011 10:00 PM by robert sturzbecher   [ updated Jan 24, 2011 11:32 PM ]
Pyroelectric sensors are cool and so is thermograph but the main real downside is cost. 
If you don't need it to be accurate here is a cheap and easy way of adding it to your next Arduino project.

For this project I will use a pyroelectric sensor from a PIR motion detector. Of coarse the temperature reading is not going to be very accurate but if you need accuracy then you will need something better then a $2 PIR sensor. 

There are a few things to note about PIR sensors. 
  • Background temperatures and Sensor temperatures influence the output.
    Holding the sensor or heat near the case will also influence the output.
    (So don't put them next to things that can generate heat like motors, LEDs ,ect..)
  • Motion detector types have 2 elements inside them.
    A left and a Right. One will drop the output voltage and the other will increase it.
    (This is why we cover one file with foil tape) These sensors normally have square windows.
  • These sensors see humans, The motion detector PIR sensors have filters built in that are optimized to see the heat emitted by humans. 

Ok lets start

Modding the sensor is done with a small bit of foil tape. Because the sensor has a left&right sides that increase and decrease the output depending upon which side detects the most heat we will cover one side. I used foil tape as the metal is a good IR reflector and a good conductor of heat and will hopefully disperse the heat. I found it was better to block the side the lowers the voltage, but you can do ether.

Wiring the sensor is easy, They only have 3 pins (Drain/Vcc, Source/Out, Ground). To wire to an Arduino you need to connect up as below

  • Drain/Vcc goes to 5Volts.
  • Source connect directly to a Analog pin of the Arduino and needs a 47k resistor that connects to Ground. 
  • Ground goes to ground.
Above is an extract from datasheet with my notes on it.

I didn't have a 47k so I used a 20k, still works well.

The Code to get the sensor value.

                        sensorValue = analogRead(sensorPin);

What did you expect it to be more complex? You can use most of the Arduino demo sketches to use the sensor. The only thing to note it that analogRead works better if you put a delay in front of it to let things settle first. 

Putting to use 
If you want something a little more complex you could try mounting the sensor on servos and use it to track people and their appendages ;) and oh yes that is a wireless camera on top.
You could even use it to map the surrounding environment.

In the video below the head does a sweep reading the PIR sensor values then returns to the strongest point with the lights, then repeats. The values are outputted to the computer if connected.  

The next step for this that I am working on is to process the data computer side to create a 2d PIR image, almost like Thermo graph but without the stupidly expensive price tag. 

Read part 2 for the software.

The Datasheet is also downloadable from the product page above.

You can also get the sensors from other online stores like (I'm not plugging them its just were I shop)