Book Image

Internet of Things Programming with JavaScript

Book Image

Internet of Things Programming with JavaScript

Overview of this book

The Internet of Things is taking the tech world by storm, and JavaScript is at its helm. This book will get you to grips with this exciting new technology. Where do Node.js, HTML5 and Windows 10 IoT Core come in with JavaScript and IoT? Why Raspberry Pi Zero rather than Arduino? How do you configure and build an IoT network from scratch? All your IoT JavaScript questions are answered in this book.
Table of Contents (15 chapters)
Internet of Things Programming with JavaScript
Credits
About the Author
www.packtpub.com
Customer Feedback
Preface

Building an alarm system using the Raspberry Pi Zero


In this section, we will build a simple alarm system with a PIR sensor connected to the Raspberry Pi Zero. This is an important project as it can be added to the home, including other sensors, in order to monitor it.

Motion sensor with Raspberry Pi Zero

For this project we need the Raspberry Pi Zero, a motion sensor PIR, and some cables. The hardware configuration for this project will actually be very simple. First, connect the VCC pin of the motion sensor to a 3.3V pin on the Raspberry Pi. Then, connect the GND pin of the sensor to one GND pin on the Pi. Finally, connect the OUT pin of the motion sensor to the GPIO17 pin on the Raspberry Pi. You can refer to the previous chapters to find out about pin mapping on the Raspberry Pi Zero board.

The following image shows the final circuit with the connections:

Software code

You can now either copy the code inside the folder called Project1, or just get the complete code from the folder for this...