Motion Sensing Codebug

Introduction

Ever suspected someone of sneaking into your room and plays with your stuff when you’re not around? Well now you can catch them in the act with your own motion sensing CodeBug.

This activity will show you how to connect a PIR sensor to CodeBug and read its value. If your PIR has a male pin connector, you will need male to female jumper cables. If your PIR has a female socket connector, you will need male to male jumper cables.

You will need
CodeBug CodeBug
Micro USB cable
Computer
PIR Sensor
Jumper cables

1 Question
  • where do you get a PIR sensor? ianyu2008 @ March 30, 2018, 9:48 a.m.


    Answer this question:

  • Ask a new question:

Wiring up your sensor

You may need to check the information sheet of your PIR sensor, however they usually have three pins, labelled (+) (OUT) and (-). Using three jumper cables, connect the positive (+) pin of the PIR to the VCC hole on CodeBug’s black expansion port, connect the negative (-) pin to the GND hole on CodeBug’s expansion port and the output pin to the SDO hole.


  • Ask a new question:

Writing your program

We need to set up one of CodeBug’s legs as a digital input to read your PIR sensor. Follow the tutorial below to write your code.


  • Ask a new question:

Testing your sensor

Test your code by moving your hand in front of the dome shaped sensor and watch the "Intruder" message pass by. Well done, you have made CodeBug see motion! Have a go at adjusting the dials on your PIR sensor to change the sensitivity and test the range of your sensor.


1 Question
  • Why does the battery make it repeat the code indefinitely instead of making it activate by the sensor? Nate Higgers @ Nov. 15, 2018, 4:30 a.m.


    Answer this question:

  • Ask a new question:

What next

Try connecting an LED to CodeBug to light up when it senses motion, just like the security lights.

You could also try connecting a sounder to make a motion alarm. In your code you may want to put a check to see if the motion detector has been triggered and play a note until one of CodeBug’s buttons is pressed. Use it to detect intruders in your sweet cupboard or secret den!

How about connecting your CodeBug to a Raspberry Pi and triggering the Pi Camera to snap a photo of your intruders.


2 Questions
  • Cool, Thomas - where can I buy the two sensors? Got the specs? Karin Hoegh @ June 13, 2016, 10:30 a.m.


    Answer this question:

  • I would also be interested to know which sensor you use...? ines @ April 6, 2017, 10:38 a.m.


    Answer this question:

  • Ask a new question:

Back to top