paulsmee / rpi-door-sensor

Binary door sensors for Raspberry Pi with an Express web server and visual representation on a house diagram.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rpi-door-sensor

The aim of this project is to use a Raspberry Pi 3 and have 4 simple binary sensors each connected to a door. When a door is opened the state of the sensor will change from 0 to 1 and this data will be presented visually on a webpage showing which door is open and which door/s are closed.

Installation

First thing you need to do is setup your Raspberry Pi and Install Node.js.

  • If you have not setup your Raspberry Pi then Dave Johnson provides a good beginners guide to running through this process.

  • If you have already setup the OS for your Raspberry Pi then you can follow the below to install Node.js

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt install nodejs

To confirm you have correctly installed Node.js and NPM, run the following

$ node -v
v8.9.3
$ npm -v
5.5.1

Next thing to install is pigpio C library, some versions of Raspbian come pre-installed with this so you may not need to install it. If you do need to install it just run the following

$ sudo apt-get update
$ sudo apt-get install pigpio

Now that you have the basics you will then need to do is clone this repo into the desired folder. I like to keep all my code together so it's easier to track of /home/pi/src/

$ git clone https://github.com/paulsmee/rpi-door-sensor.git

This repo has the following dependancies: express pigpio lodash

Install the dependancies by running

$ sudo npm install

If you do encounter error on installing any of the packages - most likely 'pigpio' just run the following

$ sudo npm install pigpio --unsafe-perm

From the software side, you should be all set to go.

Wiring it all up

The wiring on these sensors is quite straight forward. I'm using magnetic reed switches that are N/O (Normally Open) but you can use any 2 wire temporary switch. There are many ways to setup switches however the way that I am showing you will make it so that the board is aware of the switch.

For each door you will need the following

1 x 1k ohm resistor

1 x 10k ohm resistor

1 x magnetic reed switch

Additionally you will need a Bread Board, some jumper wires and of course a Raspberry Pi

You will need to wire up each swith as shown below

Wiring Diagram

Running the Server

To run the server you will need to run it with root permissions

$ sudo node server.js

Now all you need to do is navigate to the the local webpage where it's hosted i.e. 192.168.1.2:8000

About

Binary door sensors for Raspberry Pi with an Express web server and visual representation on a house diagram.


Languages

Language:HTML 73.6%Language:JavaScript 26.4%