Introduction: Home Automation

Turn your home into a smart home, with this you can control all electronic devices in your home within a single app. But for this project, i catered to only controls all lighting at home. Everything made easily with Raspberry pi 3 and relay for controlling the physical switches and an app build from scratch to control the relay for the remote control.

REQUIRED MATERIALS

  • Raspberry pi 3
  • 8-Channel 5v Relay Module
  • Micro sd card (8GB)
  • Female-to-Female Jumper wire

SOFTWARE USED

  • Win32DiskImager

Step 1: Wring Raspberry Pi With 8-channel Relay

Wire according to the diagram provide above

Step 2: Setup Raspbian Lite on Raspberry Pi

Visit https://www.raspberrypi.org/downloads/raspbian/

Scroll down and download latest Raspbian Lite (current - Buster)

unzip the .zip file and you'll get an .img file

run Win32DiskImager

browse for .img file under "Image File" option

select correct drive "Device" (e.g E:\)

click on "Write" button to start the burning process

click "YES" when prompt

once done, insert your sd card into raspberry pi and power it on

Step 3: Update Raspbian

Set static IP to Raspbian before update, HOW?

Login into raspbian terminal

User: pi
Password: raspberry

type

sudo nano /etc/dhcpcd.conf

scroll down to all the way down and paste this lines of code

interface eth0

static ip_address=<your static ip>/24

static routers=<ip of your router>

static domain_nameservers=<(ip of your router) 8.8.8.8>



interface wlan0

static ip_address=<your static ip>/24

static routers=<ip of your router>

static domain_nameservers=<(ip of your router) 8.8.8.8>

save it by pressing "ctrl+x" and "y"

finally reboot your pi, with "sudo reboot"

after success reboot, run these command to update raspbian to latest version

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade<br>

Step 4: Install Packages

Time to install all dependencies required

in terminal run these commands

sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install git
sudo npm install pm2 -g

Check if everything install correctly by running these commands

node -v
npm -v
pm2 -v
git --version

Step 5: Clonning "HomeAutomationServer" Repository

Clone "HomeAutomationServer" repository from github

git clone https://github.com/khairmuhammad-ybh/HomeAutomationServer.git

once cloned, go into "HomeAutomationServer" directory and run this

npm install

All required dependencies required for the project will be install automatically

Step 6: Run Server With Pm2

Run server with pm2

type this in terminal to generate the path for pm2

pm2 startup

copy the generated command and paste into the terminal and execute it

lastly, start server with pm2, type this command, you should be in the right directory by now

pm2 start server.js --name "HomeAutomationServer" --watch

run this command to save the server into pm2 so pm2 will auto run your server on every boot

pm2 save

Step 7: Reboot Server

Reboot server with this command

sudo reboot

once rebooted, type this command to check if server automatically run after reboot

pm2 list

With that you have completed the tutorial for setting up the server running with pm2

BUT BEFORE TO END THE ENTIRE TUTORIAL, let me tell you that this is just half of the application, so, where is the remaining tutorial you ask, visit https://github.com/khairmuhammad-ybh/HomeAutomati... for the final tutorial to install the app on your device.

UPDATES

Download and install the apk provided here : HomeAutomation and give it a try