How to setup the PIR Sensor

This lesson will demonstrate how to use the passive Infrared sensor PIR sensor (Please note: this item is not include in the kit and is a tutorial on how to program it should you purchase one)

Wiring setup

You will need three female to female jumper cables and of course the PIR sensor.

The red wire is connected to VCC or 5V depending on what PIR sensor you have gotten. The orange wire in this case is connected to the signal pin which is connected to the smart inventor board on port D pin 2. The yellow wire is connected to the ground “GND” pin.

How to program the PIR sensor

Programming the PIR sensor

First, begin the code by including the smart inventor library.

Enter the following before the void setup(); method.

Learn More: What’s a library?

A library is a saved set of functions()  and variables that provide users with improved functionality when coding.

Any code that starts with SmartInventor._____  is a function in the SmartInventor library.  Any variable that highlights ORANGE, is an initialized variable from an included library.

Learn More

Second we will assign the pin number the PIR sensor will be connected to.

Now we will create the boolean variable, bodyPresent  it will either be  TRUE or FALSE .

Next, inside   void setup(); , enter the following.

This line of code will allow the SmartInventor Board to send data back to the computer at a rate of 9600 bits per second.

Serial.begin( )

Serial.Begin( BAUD rate);

This function will establish a high transfer BAUD connection between the remote and the board. The higher the BAUD number the faster the board will process information, but may yield a high chance for errors. The lower the BAUD number the slower the board will process information, but may yield a low chance for errors.

Acceptable BAUD rates range from 300 to 250000. Make sure that the BAUD rate is a number that is found within the lower right corner of the Serial Monitor.

Next, use pinMode() to assign the PIR Pin

Next, inside   void loop(); , we will now set the bodyPresent boolean variable.

The  digitalRead(PIR_Pin);  reads the pin value which is either HIGH or LOW.

The PIR sensor is a passive infrared sensor it detects infrared heat which activates the sensors circuit. The sensor is actually underneath the white lens which helps redirect infrared to the sensor.

Next, type the following.

This if statement will check if bodyPresent  is TRUE or FALSE and will print to the serial monitor and buzz. If the boolean statement is not true then print out that no movement is detected.

and you are done coding.

 

Activity

Make the buzzer increase its tone every time the PIR sensor is activated.

Final Code

Viewing the Serial Monitor

Once you have uploaded your program, keep the upload cable connected and turn off all dip switches. Now click on the the serial monitor eyeglass icon on the top right.

Make sure you have the baud rate selected at 9600.