Home mbed Nucleo-F334R8 and PIR example

Nucleo-F334R8 and PIR example

In this example we connect a low cost PIR to our NUCLEO-F334R8 board and if an intruder is detected we will display a message. A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors.

The most common PIR that is used in many projects particularly in Arduino projects looks like this

PIR module

PIR module

We use a low cost PIR something similar to the following, very common and easy to connect up. Lets take a look at a schematic

 

Schematic

Nucleo and PIR_bb
Code

We need the library for the freetronics LCD shield, I’m using a sainsmart one. There are many clones on the internet. What we are doing is waiting for the PIR to stabilize for 30 seconds, then if anything is detected the PIR output will go high and we will display a message on the LCD, real world could be flashing led’s or a siren of some description like an intruder alarm but the LCD could simulate the status display

 

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "freetronicsLCDShield.h"


freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D1, A0);

DigitalIn PIRSensor(D3);

int n=0;

int main() 
{
lcd.cls();
//allow 30 seconds for PIR to stabilize
lcd.printf("Stabilizing");
lcd.setCursorPosition(1, 0);
for (n=0; n<30; n++)
{
wait_ms(1000); // 1sec delay
}

//loop constantly
while(1)
{
lcd.cls();
if (PIRSensor == 1)
{ 
lcd.setCursorPosition(1, 0);
lcd.printf("INTRUDER ALERT");
wait(10);
}
}
}

[/codesyntax]

 

You may also like