Smart Home

Introduction: 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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Setup Overview

After completing the steps in our tutorial, your setup should look like this as seen above.

Step 2: 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

Step 3: 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

Step 4: Setting Up Amazon Web Services (AWS)

  1. Login to AWS, and click on services

  2. Select IoT Core

  3. At the dashboard, go to "Manage" and click on Things

  4. Click on create *Note: If you do not have a thing yet, click on "Register a Thing"

  5. Click on "Create a single thing"

  6. Give your thing a name and click on "Next"

  7. In the next screen, click on "Create certificate" on the first row

  8. Make sure to download all 3 certificates including the root CA

    For root-ca go to this link

    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.

  9. Activate your certificate and click on done

  10. Next, go to "Secure" and click on policies

  11. Create a Policy

  12. While still in the "Secure" tab, go to Certificates

  13. 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.

  14. Now click on the 3 dots again and click on attach a thing and choose the thing you have just created and attach it.

  15. Go back to the thing you have created and click on it, in manage->things.

  16. Go to interact, take now of the https link, this link is used to interact with the aws broker.

  17. Your aws is ready for use now.

Step 5: Setting Up IBM Bluemix

  1. Login to IBM bluemix and go to
  2. Enter a unique app name and host name, you could choose sp-yourstudentid for both of these fields and click create

  3. Wait for the app to start, if your app doesn’t start you may have to restart it

  4. At the dashboard click on iotf-service under cloud foundry services and launch the Watson IoT platform

  5. Take note of the url of the website for my case it is

  6. Under devices, go to the device types first and click add device type

  7. Choose type as gateway and put the name as gw-yourstudentid. Click next then click done

  8. Now go to the browse and add device

  9. 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.

  10. Enter AUTHTOKEN-gw-yourstudentid for the authentication token, then click next and then done.

  11. Take note of the organization id,device type,device id authentication method and authentication token

  12. Bluemix is ready for use now

Step 6: Setting Up IBM Cloudant NoSQL Database

The IBM Cloudant NoSQL Database will be used to store data sent by your sensors. This section will guide you on how to set it up.
  1. Login to IBM bluemix and go to console/dashboard
  2. Click on Cloudant-jy
  3. Click on launch cloudant dashboard
  4. Next navigate to database
  5. Click on create database on the top right
  6. We will be creating 4 databases so you have to repeat the step four times, the four database names (lightsensor1, lightsensor2, humiditysensor1, humiditysensor2)
  7. After this you are ready to send data to the four databases.

Step 7: Setting Up Twilio for SMS Notification

  1. Login to Twilio, sign up for Twilio if you haven’t
  2. Copy your Account SID and Auth Token which is shown on the console dashboard
  3. Navigate to runtime-> api keys then click on create new api key, put any name you want for the friendly name
  4. Click on create api key
  5. Make sure to take note of the sid and secret key
  6. You will be given a random number, just click on choose this number
  7. Make sure to copy down the phone number
  8. Go to this link to add Singapore in the geo-location section.

Step 8: 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.


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":"","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!

Step 9: IBM Node Red Dashboard

  1. Access your IBM Node-Red
  2. Navigate to "Manage Palettes" in the menu on the top right.
  3. Install the Node "node-red-dashboard"
  4. On your IBM Node-Red and import the following flow from the text file attached under this section.
  5. Edit TLS configuration for all MQTT nodes and upload the respective AWS certificates that you have downloaded previously when setting up AWS.
  6. Proceed to click "Deploy"
  7. 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

Step 10: 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.

Be the First to Share


    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Clocks Contest

      Clocks Contest