Smart Home

This Smart Home application turns on
the light which in this case the LED when it is dark and motion is detected. It helps when the area is dark so users do not need to find the switch for the lights which can be hard in the dark.
In addition, this application can keep track of the surrounding temperature and humidity. If the humidity is high it means rain might be coming soon. This allows the user to stay informed and prepared to keep his/her laundry that is placed outside to dry before the rain comes.
It's web interface uses IBM's Node Red where the user will be able to control the LED as well as view Real Time and Historical data collected by the application.
Setup Overview

After completing the steps in our tutorial, your setup should look like this as seen above.
Hardware Requirements
- MCP3008 ADC x1
- Light-Dependant Resistor x1
- DHT11 Sensor x1
- PIR Sensor x1
- Light Emitting Diode (LED) x1
- 10k Ω Resistor x2
- 330 Ω Resistor x1
Connecting Components




Connecting the parts step-by-step
The images shown above are step-by-step procedures on how to connect all the required components for this application.
Image 1: Connecting MCP3008 ADC & LDR
Image 2: Connecting DHT11 Sensor
Image 3: Connecting PIR Sensor
Image 4: Connecting LED
Setting Up Amazon Web Services (AWS)







-
Login to AWS, and click on services
-
Select IoT Core
-
At the dashboard, go to "Manage" and click on Things
-
Click on create *Note: If you do not have a thing yet, click on "Register a Thing"
-
Click on "Create a single thing"
-
Give your thing a name and click on "Next"
-
In the next screen, click on "Create certificate" on the first row
-
Make sure to download all 3 certificates including the root CA
For root-ca go to this link https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem
Right click anywhere on the web page and save as, put rootca.pem for the file name and for save as type put all files, click save.
-
Activate your certificate and click on done
-
Next, go to "Secure" and click on policies
-
Create a Policy
-
While still in the "Secure" tab, go to Certificates
-
Go to the certificate that you just created, click on the 3 dots and click on attach a policy and choose the policy that you have just created and attach it.
-
Now click on the 3 dots again and click on attach a thing and choose the thing you have just created and attach it.
-
Go back to the thing you have created and click on it, in manage->things.
-
Go to interact, take now of the https link, this link is used to interact with the aws broker.
-
Your aws is ready for use now.
Setting Up IBM Bluemix
- Login to IBM bluemix and go to https://console.bluemix.net/catalog/starters/internet-of-things-platform-starter
Enter a unique app name and host name, you could choose sp-yourstudentid for both of these fields and click create
Wait for the app to start, if your app doesn’t start you may have to restart it
At the dashboard click on iotf-service under cloud foundry services and launch the Watson IoT platform
Take note of the url of the website for my case it is https://gtjbk1.internetofthings.ibmcloud.com/dashb...
Under devices, go to the device types first and click add device type
Choose type as gateway and put the name as gw-yourstudentid. Click next then click done
Now go to the browse and add device
Select the new device type that you have created and put gwid-yourstudentid for the device id and click next all the way until security.
Enter AUTHTOKEN-gw-yourstudentid for the authentication token, then click next and then done.
Take note of the organization id,device type,device id authentication method and authentication token
Bluemix is ready for use now
Setting Up IBM Cloudant NoSQL Database


- Login to IBM bluemix and go to console/dashboard
- Click on Cloudant-jy
- Click on launch cloudant dashboard
- Next navigate to database
- Click on create database on the top right
- We will be creating 4 databases so you have to repeat the step four times, the four database names (lightsensor1, lightsensor2, humiditysensor1, humiditysensor2)
After this you are ready to send data to the four databases.
Setting Up Twilio for SMS Notification




- Login to Twilio, sign up for Twilio if you haven’t
- Copy your Account SID and Auth Token which is shown on the console dashboard
- Navigate to runtime-> api keys then click on create new api key, put any name you want for the friendly name
- Click on create api key
- Make sure to take note of the sid and secret key
- You will be given a random number, just click on choose this number
- Make sure to copy down the phone number
- Go to this link https://www.twilio.com/console/sms/settings/geo-permissions to add Singapore in the geo-location section.
Raspberry Pi Node Red Flow




Start Node Red on your Raspberry Pi
node-red start
Type in the following URL on your computer's browser.
x.x.x.x represents your Raspberry Pi's IP address.
x.x.x.x:1880
Once you are on the Node-Red webpage, navigate yourself to Import > Clipboard through the menu button on the top right.
Paste in the following flow
[{"id":"201c473b.092328","type":"tab","label":"CA2"},{"id":"58439df3.32af14","type":"mqtt out","z":"201c473b.092328","name":"Send light values","topic":"sensors/lightRoom2","qos":"1","retain":"","broker":"15d3961c.c2373a","x":835,"y":453,"wires":[]},{"id":"492090f5.064b3","type":"pimcp3008","z":"201c473b.092328","name":"MCP3008","pin":0,"dnum":0,"x":634.3333129882812,"y":453.3333435058594,"wires":[["58439df3.32af14","7aa659ae.010c18"]]},{"id":"f32da004.b22ee","type":"rpi-dht22","z":"201c473b.092328","name":"dht11","topic":"rpi-dht22","dht":"11","pintype":"0","pin":4,"x":635,"y":397,"wires":[["51405fe7.04fa","7aa659ae.010c18"]]},{"id":"3349c2d2.db691e","type":"rpi-gpio in","z":"201c473b.092328","name":"Motion sensor","pin":"37","intype":"in","debounce":"25","read":false,"x":232,"y":440,"wires":[["42c4625f.db278c"]]},{"id":"51405fe7.04fa","type":"function","z":"201c473b.092328","name":"Sensor Values","func":"msg.payload = msg.payload;\nvar data ={\n Temperature: msg.payload,\n Humidity: msg.humidity\n};\nmsg.payload = data;\nreturn msg;","outputs":1,"noerr":0,"x":813,"y":395,"wires":[["de4a1dae.fc4ce"]]},{"id":"de4a1dae.fc4ce","type":"mqtt out","z":"201c473b.092328","name":"Send Humidity values","topic":"sensors/humidityRoom2","qos":"1","retain":"","broker":"15d3961c.c2373a","x":1021,"y":395,"wires":[]},{"id":"540de5ec.b7777c","type":"function","z":"201c473b.092328","name":"filter command","func":"msg.payload = msg.payload.led\nreturn msg;","outputs":1,"noerr":0,"x":424,"y":598,"wires":[["36a30890.27d608"]]},{"id":"468b2ddb.c3ade4","type":"wiotp in","z":"201c473b.092328","authType":"g","deviceKey":"14d2052f.f0938b","deviceType":"","deviceId":"","command":"led","commandType":"g","qos":0,"name":"","x":219,"y":594,"wires":[["540de5ec.b7777c"]]},{"id":"36a30890.27d608","type":"rpi-gpio out","z":"201c473b.092328","name":"LED","pin":"12","set":true,"level":"0","out":"out","x":628,"y":599,"wires":[]},{"id":"42c4625f.db278c","type":"switch","z":"201c473b.092328","name":"Motion Detected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":1,"x":432,"y":444,"wires":[["492090f5.064b3","f32da004.b22ee"]]},{"id":"7aa659ae.010c18","type":"debug","z":"201c473b.092328","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":836.0694732666016,"y":526.5729141235352,"wires":[]},{"id":"15d3961c.c2373a","type":"mqtt-broker","z":"","broker":"a14uf5vogf921s.iot.us-west-2.amazonaws.com","port":"8883","tls":"c4e69c1b.6445a","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"14d2052f.f0938b","type":"wiotp-credentials","z":"","name":"My raspberry pi gateway","org":"gtjbk1","serverName":"","devType":"gw-1626120","devId":"gwid-1626203","keepalive":"60","cleansession":true,"tls":"","usetls":false},{"id":"c4e69c1b.6445a","type":"tls-config","z":"","name":"","cert":"/home/pi/labs/p11v2/f5cd512a6b-certificate.pem.crt","key":"/home/pi/labs/p11v2/f5cd512a6b-private.pem.key","ca":"/home/pi/labs/p11v2/rootca.pem","verifyservercert":true}]
Your Node-Red flow should be completed after importing the code above.
TLS Configuration
After completing the flow, create a folder on your own Raspberry Pi. Place the AWS certificates you have downloaded previously when setting up AWS inside this folder.
Proceed to edit the MQTT-broker node and edit the TLS configuration.
Copy and paste in the respective file paths on your Pi for "Certificate", "Private Key" and "CA Certificate".
You are now ready to deploy this flow!
IBM Node Red Dashboard




- Access your IBM Node-Red
- Navigate to "Manage Palettes" in the menu on the top right.
- Install the Node "node-red-dashboard"
- On your IBM Node-Red and import the following flow from the text file attached under this section.
- Edit TLS configuration for all MQTT nodes and upload the respective AWS certificates that you have downloaded previously when setting up AWS.
- Proceed to click "Deploy"
- You will now be able to go to the dashboard. On your own browser, enter the following URL where x is your IBM Bluemix's route
x/ui
Downloads
Finish


Congratulations! This is the end of the tutorial.
With the 2 Node-Red flows deployed, 1 of them should be sending the data and the other allowing you to view the data on the dashboard as seen above in the images.