Introduction: Smart Home Using Amazon Alexa
The Basic idea behind this project is to control an electronic appliance using Amazon Alexa or through its app from anywhere in the world. We will be using a Node MCU V1.0 for this. All the code will be on my Github Page. If at any point you don't understand a step feel free to comment down below and I shall respond to it at the earliest. All Credits for the servers as well as the code goes to kakopappa(https://github.com/kakopappa). I have modified the code to control 4 Relays for the purpose of this tutorial. Well, Lets get started!
Note: This tutorial assumes that you have some knowledge about Arduino IDE and Node MCU.
- Node MCU V1.0
- 4 Relays(Relay Bank)
- Jumper wires
- An External Power Source
Step 1: Create an Account on Sinric.com
The first thing that you have to do is go to sinric.com and create an account(Its Free). Sinric allows you to control your micro-controller over the internet. You will then get an API key which will be unique to your account. You will use this key later in your code. The next thing we have to do is add a device. This is done by Clicking on the "Add" button. Create a name for your device which you will then use to call via Alexa. In device type choose "Switch" and then click Save. This will create a device id for your device which is also going to be used in the code. In the Alexa app enable the Sinric skill for your Amazon echo so that it can discover the newly created devices.
Step 2: Wiring the Circuit
Wire the circuit as Follows or follow the fritizing diagram attached:
JD-VCC-->Positive of external Power Supply
GND------->GND of external Power Supply
Since the NodeMCU cannot power the relay bank alone an external power supply is needed to power it.
The relays are connected in between the appliances by breaking the live wire and inserting them in the each relay like in a switch.
Step 3: Uploading the Code to the NodeMcu
The Code is uploaded here: https://github.com/The-Great-One/Sinric_Relay_Esp...
The libraries you will be needing are ArduinoJson(install version 5.13.2) and Arduino websockets(get it from: https://github.com/Links2004/arduinoWebSockets/re...
Dont forget to configre the Board to Node MCU v1.0.
Based on the number of relays you need you can modify the code to add more. The changes required would be to define a new pin and add another else if loop with the new device id. You can even change the pins as per your liking by reffering to this pin chart at https://github.com/esp8266/Arduino/blob/master/va...
This tells you which GPIO is what in on the Arduino. Basically if you want to change your relay pin from D4 to D3 the change in the code will be as follows:
#define MYPIN2 2 //D4
#define MYPIN2 0 //D3
Anything after // is a comment on the same line and is not considered by the compiler.
Step 4: Configuring the Amazon Echo
To Control the devices using Amazon Echo you need to first set them up. You can do this by saying "Alexa,Discover Devices". It will take 20 seconds and it should discover your switches. You can now say "Alexa, Turn on device name" to turn on your device and vice versa. You can control it from the Alexa app as well by going to the Devices Section of the app.
Step 5: The End
I hope you did not face any problem while following this Instructable. If you have any queries please drop them below in the comments section.
If you want to support me in any way here is my Paypal ID : paypal.me/sahilgoel2001