This project is read-only.

In this example we will show how you can build a gadget that detects the presence of a person. When a person enters the room, the PC will play a sound saying "Hello!".

For this project you will need what is known as a PIR (passive infrared) sensor. The PIR sensor will react on the infrared light radiated by warm objects (such as the human body). Click here to read more about PIR sensors and how they work.

A simple PIR sensor like the one below is only a few US dollars and can be found on most on-line electronics stores. You will also need a small breadboard and three jumper wires.

Top of PIR sensor moduleTop view of the sensor.

Back of PIR sensor moduleBottom view.

The above sensor board is quite small and only measures about 20x30 mm. Notice how there are three pins coming out on the back - from the left these are +5V, OUT and GND.

Wiring the sensor
Connect your sensor like this:

PIR PeekyPokey Description
+5V  +5V Power supply for the sensor
OUT gp0 3.3V sensor output
GND GND Common ground

 When you're done, the setup should look like this:

Red is +5V, green is OUT and black is GND. 

The software
Even though this application does not have any visual representation, we will create a Windows Forms application. Here's what you do:

  1. Download this hello.wav sound file and save it on your harddrive
  2. Start Visual Studio
  3. Choose to create a new Windows Forms application
  4. In the solution explorer, right click "form1.frm" and select "View code"
  5. In the code window that appears, add this code snippet:
private void Form1_Load(object sender, EventArgs e)
    new InputPort(Device.Pin.Gpio0, Port.Trigger.ToggleUp).OnValueChanged += new Port.ValueChanged(Form1_OnValueChanged);

void Form1_OnValueChanged(Port sender, Port.ValueChangedEventArgs e)
    using(var player = new System.Media.SoundPlayer("C:\\hello.wav"))

Note: You will have to change the path for hello.wav to where ever you saved the file after download.

Running the application
Before connecting the PeekyPokey to your PC, make sure the power switch is in the 3.3V position (like in the picture above) or the PeekyPokey will not detect the sensor output.

Now, crank up the volume on your PC and press the green play button in Visual Studio to run the application. Move your body or wave your arms in front of the PIR sensor....

You could use this application to set up an alarm to go off when somebody enters the room. You could also do without the sound effects and simply log any and all events of motion while you're away. Another possibility could be to combine it with the relay project and turn on the lights as you enter the room.

More example projects are available on the Projects page.

Last edited Aug 14, 2013 at 6:35 PM by hanzibal, version 13