As of the Raspbian Jessie release, Scratch provides easy access to the Raspberry Pi’s GPIO pins. This project incorporates the new GPIO server to build a motion detector.
The release of Raspbian “Jessie” introduces a new version of Scratch (September 2015) that enables access to the Pi GPIO (general purpose input/output) pins by default. I’ll demonstrate the new built-in features by creating a motion detector so you can sense when something or someone moves; it’s perfect for keeping tabs on your bedroom or the cookie jar, or catching your dog eating off the counter when you’re not home. In addition to an updated version of Scratch, you will need two LEDs, resistors, a passive infrared (PIR) sensor, and your breadboard to build a motion detector.
Accessing the Pi’s GPIO pins from within Scratch has been possible for several years, but it previously required a separate installation of Scratch called ScratchGPIO, which I’ve used in previous Raspberry Pi articles, from Simon Walters (aka cymplecy). The Scratch GPIO server now enables access from the default installation of Scratch. In addition to the GPIO pins, you gain access to several other commands to get the time, IP address, and photos from the camera module.
The Scratch GPIO server – like the ScratchGPIO and Mesh features I’ve covered in previous Raspberry Pi Geek articles – rely on broadcast messages to communicate outside of the Scratch interface. This puts a special emphasis on using carefully constructed commands (syntax) to make Scratch do what you expect. In a Scratch programming environment, the focus on syntax creates a more advanced deviation from the drag-and-drop interface that makes Scratch so easy to understand.