A node.js based home automation system based around the Raspberry Pi. For background around this project:


To get started, clone the repository and install the required dependencies.

git clone https://github.com/anders94/raspberry-pi-home-automation.git
cd raspberry-pi-home-automation
npm install



The Raspberr Pi needs a little bit of circuitry to protect and amplify its GPIO ports. Here's schematics of the circuits I created for this project.

Protected Pull-Up Switch

If you want to read from the GPIO pins on the Raspberry Pi, you shouldn't just switch the pin between 3.3v+ and nothing. Rather, you should either pull it up to 3.3v+ through a small (1k) resistor or drain it down to ground through a larger (10k + 1k = 11k) resistance.

Relay Driver

The GPIO pins on the Raspberry Pi run at 3.3v which isn't really enough to solidly throw relays. (in my case, I'm using a solid state relay but the theory is the same) This circuit uses an NPN transistor to amplify the 3.3v GPIO output to a 5v output which is enough to throw the relay.


The server uses MQTT, a lightweight messaging channel over TCP, and presents a pub-sub like interface to clients. Clients connect and can publish messages which get copied to all other connected clients.

To start the server:

node server

It will connect and listen to by default.


Clients read from and optionally write to the GPIO pins on the Raspberry Pi. Light switches are directly attached to 3.3v GPIO pins pushing them either high or low. Solid state relays to switch 120v AC loads are driven via 3.3v GPIO pins which are up-converted to 5v with a transistor. (3.3v isn't quite enough to solidly switch the Sharp S216S02 solid state relays I'm using) You may need to access GPIO pins as root depending on how you have things set up.raspberry-pi-home-automation


Fires a callback when the GPIO pin state changes. Use this to test GPIO input functionality.


Blinks GPIO pins on and off for 5 seconds so you can get your SSR setup working.


Simple on / off lightswitch example linking input and output. It does exactly what you think it does.


For more detail: raspberry-pi-home-automation

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top