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 [crayon-666c85b990903836039114-i/] method.

Learn More: What’s a library?

A library is a saved set of [crayon-666c85b99090c231031011-i/]  and variables that provide users with improved functionality when coding.

Any code that starts with [crayon-666c85b99090d193057917-i/]  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, [crayon-666c85b990910784482982-i/]  it will either be [crayon-666c85b990911156039118-i/] or [crayon-666c85b990912506248789-i/] .

Next, inside  [crayon-666c85b990915215978183-i/] , 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  [crayon-666c85b990919279610512-i/] , we will now set the bodyPresent boolean variable.
The [crayon-666c85b99091b423835552-i/]  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 [crayon-666c85b99091d915098239-i/]  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.



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.