Appliance Control using IOT and AI Chatbot

IoT (Internet of thing) is one of the burning topics among electronic hobbyists and students due to its various advantage. There are many ways/devices with which you can interface your appliance with the internet, NODE MCU is one of them. Node MCU is very much popular due to its various advantage. Some of them are listed below. Thus we are going to make Appliance Control using IoT and AI Chatbot using NodeMCU.

  1. Smaller size and breadboard friendly
  2. Hardware and pinout are more like Arduino.
  3. Support API in Nodejs style thus speed increased greatly.
  4. Cheaper than any other version of Arduino.

Here in this project, we are going to use IoT and AI to control the appliance. After making this device you can turn on and off the electrical / electronics appliance from any corner of the world through messenger. Another interesting thing is you don’t have to remember the syntax for the device on and off. For this, we had used the term AI. Even if you type some mistake in the switching command it will know what you are trying to say and switch the appliance. The circuit is shown in figure 1.

Components required for the project Appliance Control using IoT and AI Chatbot

Appliance Control using IOT and AI Chatbot

This project requires hardware as well as software parts, let’s see hardware requirements first.

  1. NodeMCU x 1
  2. 5K-ohm resistor x 1
  3. BC548 Transistor x 1
  4. 1N4007 Diode x 1
  5. 6V Relay x 1

If you are new to relay and its driving circuit then please do read the previous article posted on bestengineeringprojects.com

We had already posted a very detailed article and video on the relay switching circuits.

Article Link: How to Make Relay Switch Circuit

Making video link: https://youtu.be/LHtvv0Cara0

Before programming the NodeMCU using Arduino IDE you have to do some setup.

Check out the procedure for setup Arduino IDE for programming Node MCU.

How to Configure Arduino IDE for Node MCU

Before going to the software part let’s set up IOT, Chatbot, and Server.

Step 1: Creating and configuring Facebook page

At first, create a Facebook page (www.facebook.com/pages/creation/) there you will see two options 1. Business and brand 2. Community or public figure. Go with community or public figure select Get Started as shown in figure 5.

Creating facebook page

Figure 5: Creating Facebook Page

Give it a name that says “Best Engineering Projects” and the category says “Science website” and press Continue. You can add another detail like a cover photo or profile photo but here I am skipping it. You have to hide this page because if you don’t do so others can trigger your appliance. For hiding your Facebook page go to Setting>General>Page Visibility. There you will see two options Page Published and Page Unpublished. Mark as Unpublished Page and click on Save Change as shown in figure 6.

unpublished facebook pageFigure 6: Hiding Facebook Page from public

Step 2: Setup your ChatBot

For setting ChatBot you have to make an account in chatfuel (https://dashboard.chatfuel.com/#/bots). Chatfuel is an automatic bot that communicates and responds using bots. Signup with your Facebook page that you have created before. A dashboard will appear as shown in figure 7, click on connect on blank bot which connects it to the Facebook page.

connect to blank botFigure 7: Connect to Blank Bot

A new window of Automate appears there you can edit and configure the welcome messages. You can edit the message according to your requirement. In place of {{First name}} use your name else it will publish the name of the user who sends the message to the chatbot (Figure 8).

welcome message for chatbotFigure 8: Adding Welcome Message to your Chatbot

Now, click on Default Answer located on the right side of the welcome message and edit it. This answer is an automatic response when the user sends a command which is not listed on “Set up AI” (Figure 9).

chatfuel default messageFigure 9: Adding Default Answer to your Chatbot

Now, we are going to create a button for switch ON and OFF for appliances i.e. Appliance ON and Appliance OFF. Click on the “+” button below ADD BLOCK HERE. Rename this as Appliance ON and click on the “Text” button from ADD A CARD (Figure 10). Add some message here which you want to show in response when you switch ON the appliance (Figure 11).

adding appliance buttonFigure 10: Adding Appliance ON button

message for appliance onFigure 11: Adding Message to your Appliance ON button

Do the same thing for the Appliance OFF button (Figure 12).

Adding message to appliance off buttonFigure 12: Adding a message to the appliance off button

Set Up the AI rule, for click on “Set Up AI” for the menu and then click on “+ ADD AI RULE” (Figure 13). At first, I would like to add the AI rule for Appliance OFF in the white box “if the user says something similar to” like turn off the light, light off, appliance off, etc. And then click on BLOCK appear on the right side of the AI rule. A drop-down menu appears select “Appliance OFF” (Figure 14).

adding ai rule to chatbotFigure 13: Adding AI rule to chatbot

adding ai rule for appliance offFigure 14: Adding Rule for Appliance OFF

Similarly, do the same thing for Appliance ON and you have set up the AI rule for both the button Appliance ON and Appliance OFF (Figure 15).

AI rule for appliance ON and Appliance OFFFigure 15: AI rule for both Appliance ON and Appliance OFF

Step 3: Setup the Adafruit IO

At first, make an account in Adafruit IO (https://io.adafruit.com/) for an IoT end. You need to configure this Adafruit IO to execute the command in your NodeMCU. After creating an account, you will be taken to the home screen of Adafruit IO. From the left-side menu click on “Feeds” there you will see the action button, click on it a drop-down menu appears (Figure 16).

create new feed in adafruitFigure 16: Creating new feed-in adafruit IO

Select create “Create a New Feed”. Give it a name as you won’t say “OnOff”, leave the decryption section blank, and click on Create button. Your feed is created (Figure 17).

creating new feedFigure 17: Giving a name to the new feed

Now you have to create a dashboard, click on “Dashboard” from the menu that appears on left, and then select an action. Select “Create a new Dashboard” from the dropdown menu. A blank window with various buttons in different colors appears in the top right corner. Now click on the “+” button (blue background). A new pop-up window will appear, select toggle switch as shown in figure 18 below.

creating a new block on adafruit IOFigure 18: Creating a new block in Adafruit IO

When you choose the toggle to switch it will take you to “Choose Feed”. Tick the feed you have created before (say OnOff) and then click on the “Next Step” button (Figure 19).

choosing feed from existing oneFigure 19: Choosing Feed that you have created before

A window of block setting will appear, there give tour block a title say OnOff and put the value for ON and OFF saying 1 for ON and 0 for OFF. Scroll down and click on the “Create” button and your Adafruit IO setup is finished (Figure 20).

block value selectionFigure 20: Giving the value to the ON and OFF button

Step 4: Setup the IFTTT Server

To set server at first, you have to create an account in IFTTT (https://ifttt.com). Go to “My Applets” there you will see “New Applets” on the right side of the window click on it.

You can set up your server in 6 easy steps.

  • Click on “+ this”, a window appears “Choose a service” there search for a webhook, and select it.
  • Select “Receive a web request”, a window appears there to enter an event name say “light” and then hit the “Create trigger” button. A window appears showing “if (Webhooks symbol) then + that”, click on “+ that”.

ifttt setup 1Figure 21: IFTTT Server (Step 1 and Step 2)

  • In Choose action service window search for “adafruit” and select it.
  • Click on “Send Data to Adafruit”.
  • In this window choose a feed that you have already connected say “OnOff”. Now click on “Add ingredient”, select “value1” and hit “Create Button”.
  • It is the last step here, you have to click on the “Finish Button”

ifttt server setup 2Figure 22: IFTTT Server (Step 3 to Step 6)

Now you need your URL for integrating it with the chatbot. For that click on “My Applets” and select the applets, you had created earlier. A window will appear “If Maker Event “light”, then Send data to OnOff feed”, click on “Learn more” and scroll down. Select “Webhooks” and then “documentation”. These all procedure is summarized in figure 23.

webhooks documentationFigure 23: IFTTT Documentation

On the Documentation page, you will find your IFTTT key and URL, here you can also test if your Server is configured properly or not. Save the URL with the event name and proper value for value1. In place of event name put the name what you had created earlier (light) and for appliance ON value1=1 and for appliance off value1=0.

ifttt key with urlFigure 24: IFTTT Key and URL

Now it’s time for updating your chatbot with API created at the IFTTT server. For that open the chatfuel account that you have created earlier and click on Appliance ON. Select “+” from ADD A CARD, a new popup appears called “Chatfuel Plugins”. Select JSON API. After that select POST in type and paste the URL with value1=1 in Appliance ON block and value1=0 in Appliance OFF block as shown in figure 25.

update json apiFigure 25: Updating JSON API in Chatfuel account

After this, we have to save the Adafruit IO Secret username and password which is used in Arduino programming. To get your secret key open your Adafruit IO dashboard then click on key symbol situated in the top right corner of the display there you will see your username and secret key as shown in figure 26.

adafruit io username and secret keyFigure 26: adafruit io username and secret key 

Software Code Appliance Control using IoT and AI Chatbot:

Everything is set up now it’s time to program your NodeMCU. The software code is written in Arduino programming and compiled using Arduino IDE. You have to do a little change in code before uploading it to your NodeMCU. You have to update SSID i.e. name assign to your WiFi and its password. You have to update your username and secret key given by adafruit IO. Let’s  see the program code

Making video Part 1

Making video part 2

One Thought to “Appliance Control using IOT and AI Chatbot”

  1. Vasudevan S

    I got some error and I can’t able use my COM 3 port it’s not visible even after i installed the driver and using the preferences link board libraries and everything

Leave a Comment