Reader small image

You're reading from  Building Smart Homes with Raspberry Pi Zero

Product typeBook
Published inOct 2016
PublisherPackt
ISBN-139781786466952
Edition1st Edition
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Configuring the smart plug


We are now going to configure the Raspberry Pi so it behaves like a smart plug. As usual, we'll use Node.js to code the software that will control our Raspberry Pi Zero board.

We start by importing all the required modules for the project:

var mcpadc = require('mcp-spi-adc');
var express = require('express');
var app = express();
var piREST = require('pi-arest')(app);

Note that we are using the mcp-spi-adc module here, which will allow us to easily read data from the MCP3008 chip.

Next, we define the channel to which the current sensor is connected:

var channel = 5;

We also set the value of the load resistance we are using for the sensor:

var resistance = 10;

This will allow us to calculate the actual current flowing through the sensor later on.

So far, you might have noticed that we don't measure the voltage in this project. Indeed, even if we could add another circuit to measure the voltage, we can simply set it in the code:

var voltage = 230; // Europe

Note that you will...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Building Smart Homes with Raspberry Pi Zero
Published in: Oct 2016Publisher: PacktISBN-13: 9781786466952

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz