-A +A

 

Attendance

We need to talk about this …

A reminder of the rules spelled out at the beginning of class:

  • Students are required to attend every class meeting (unless excused by the instructor with prior notice, a valid medical excuse or personal emergency) and arrive on time.
  • Two late arrivals are equivalent to one absence.
  • More than 2 unexcused absences will result in a failing grade for the class.
  • More than two absences even with reasonable excuse require that you make an appointment with the instructor.
  • Leaving early without permission counts the same as arriving late.
  • Projects are required to be complete at the start of class on critique days. Late assignments will only be accepted up to one week after the due date and will be assessed the loss of one full grade. After the one-week grace period, late assignments will not be accepted.

Passive InfraRed (PIR) Sensor/Detector

From Parallax

& available at RadioShack


Looks like R2D2 doesn't it?

Designed by Parallax to go with their Basic Stamp microcontroller, they're relatively inexpensive ($9.99 @ RadioShack) and are great for detecting moving bodies at long (20ft) ranges.

They work by using a pyroelectric sensor chip mounted to a circuit board with controlling circuitry on it. The translucent dome on the sensor is transparent to infrared energy, and has the ability to focus the energy onto the sensor (hence the faceted look to the dome). The pyroelectric sensor (pyro = Greek for fire or heat) is like an infrared camera that remembers the amount of infrared energy focused on its surface. If the amount of infrared energy focused on the sensor changes within a set period of time, the device will output a control signal (~ +5V). This sensor has a jumper pin on the back which you can set so the output goes HIGH when the sensor is re-triggered repeatedly then goes LOW after a few seconds, or so the output goes HIGH then immediately LOW when triggered. The output is LOW when idle. The HIGH for a few seconds will probably work best for our uses.

Coding the PIR

BIG TEXT | SMALL TEXT

Download test_pir01.txt file

// Reading Passive InfraRed (PIR) Motion Sensor

// Note: The PIM can take from 10 to 60 seconds to warm up when 
// first started. 


int ledPin = 2;
int sensorPin = 3;

void setup() {
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
}

void loop() {
  Serial.println(digitalRead(sensorPin));
  if (digitalRead(sensorPin)) {
    digitalWrite(ledPin, HIGH);
  }else{
    digitalWrite(ledPin, LOW);
  }
}				

A handy thing you can do is make the sensor more directional by making a simple paper tube and attaching it to the dome. Works great!

Code to fire off function but not re-trigger until it is finished

BIG TEXT | SMALL TEXT

Download test_pir02.txt file

// Reading Passive InfraRed (PIR) Motion Sensor
// Added ability to turn on a function only once and
// no restart it until it's finished. 
// Note: The PIM can take from 10 to 60 seconds to warm up when 
// first started. 

int ledPin = 2;
int sensorPin = 3;
int sensorFlag = 1;

void setup() {
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
}

void loop() {
  Serial.println(digitalRead(sensorPin));
  if (digitalRead(sensorPin)) {
    if (sensorFlag) { doBlink(); }
  }
}

void doBlink() {
  sensorFlag = 0;
  for(int i=1; i <= 5; i++) {
    Serial.print("blinking: "); Serial.println(i);
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(250);
  }
  sensorFlag = 1;
}