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

Controlling Lights with electrical circuits


In the following sections, you will find ideas on how to dive into more projects that control other devices in the house.

Electrical appliances

In houses we have electrical appliances, for example, lamps, washing machines, heaters, and other appliances that we only need to turn on or off. In this section, we will learn how to control a lamp connected to the Raspberry Pi Zero, using electrical circuits for interfacing the signal. We will use an optocoupler such as MOC3011, and a Triac. The following figure shows the circuit of the application:

Here we have the final project connected to the Raspberry pi Zero:

Here we have the JavaScript code for controlling the device:

// Modules 
var express = require('express'); 
 
// Express app 
var app = express(); 
 
// Pin 
var lampPin = 12; 

// Use public directory 
app.use(express.static('public')); 
 
// Routes 
app.get('/', function (req, res...