PIR sensors are great for detecting motion and they are easy to use with CodeBug.
To read the value of a PIR sensor, we need to set up CodeBug to read a digital value.
First click on the blue cog on the start block and tick the checkbox next to extension pins input/output.
Click the cog again to close this window.
Select digital input from the leg 6 as dropdown menu on the start block.
This will allow you to read PIR sensor more than once.
From the If menu, drag in an if block and snap it inside your repeat while true loop.
From the Logic menu, drag in an equals (=) block and snap it to the puzzle piece of your if block.
From the Inputs/Outputs menu drag in a get leg/pin block and snap it into the first gap of your equals block.
Click on the number block inside your get leg/pin block and change the number to 6.
From the Maths menu drag in a number 1 block and snap it into the second gap of your equals block.
This will code will check if the PIR sensor has registered movement.
When motion is sense, we need to display a message
From the Sprite menu drag in a scroll sprite block and snap it inside your if block.
Again from the Sprite menu drag in a get string sprite block and snap it to the puzzle piece of your scroll sprite block.
Click on the Hello world text of your get string sprite block and change it to "Intruder".
Click Download to download your code.
Load your code onto your CodeBug.