Voice Controlled Switch Using Alexa and Arduino

1,505

12

2

Published

Introduction: Voice Controlled Switch Using Alexa and Arduino

About: Keen to know latest technologies


The main aim of this project is to use temperature sensor to control switch (relay) to turn on or off the device.

List of materials

  1. 12V Relay Module == > $ 4.2
  2. Arduino uno == > $ 8
  3. DHT11 temperature sensor == > $ 3
  4. ESP8266 Module == > $ 4.74
  5. N26 optocoupler == > $ 0.60
  6. LM1117 voltage regulator == > $ 0.60
  7. Breadboard == > $ 2.2
  8. Jumper wires == > $ 2.5
  9. Push button == > $ 2.5

Total cost of project is about $ 30 dollars. This project is divided in three parts . First, we use heroku to create an app . Second,we build an Amazon Alexa skill to implement our work (Most important part). Third, we setup our hardware and program it using Arduino IDE.

Step 1: Linking Heroku With GitHub

Heroku is a cloud platform as a service (PaaS) supporting several programming languages that is used as a web application deployment model. First, go to heroku site create a new account or login there. Link is given below

Heroku Website

Lets start with creating a new app.I have given my app name "iottempswitch" when you deploy app, link is generated.

Once app is made go to GitHub.
GitHub/

Login there or signup if you do not have an account. Once logged in create new repository.Give any name you want to choose and then press create repository. On next page click on README, on this page give description you want to share with others. After that click on commit new file. Next, click on upload button.

There are two options either you drag and drop folder or choose file. Download required files from below. After selecting files press commit changes.Open the app which you created at Heroku then go to deploy section. After that Click on GitHub.Give repository name which you created at GitHub side. In my case it is Smart-Relay. Copy that and paste it here. Once your link is shown click on connect. Next, click on deploy branch(manual) . After deploying you can see link in build log or you can see link in settings. We need this link later when we are making Amazon skill.

Step 2: Amazon

On Amazon Developer site we use Amazon skill to control switch trigger by setting temperature and humidity .

  • Go to Amazon Developer Site. Link is given below.

Amazon Developer Website

  • Go to Developer console on top right as shown in figure i4

  • Go to Alexa then select Alexa Skill Kit and then create new skill by clicking on Add new skill.

When you add new skill you will see skill information page.

1. Skill Information (as shown in image i7)

we have to provide skill type,language,name,invocation name.

  • Skill type ==> select custom.
  • Name ==> select any name.
  • Invocation name ==> which you use while communicating with Alexa.For example ;- Alexa, ask sensor to turn switch trigger on or Alexa, ask light on here invocation names are sensor and light.
  • Language ==> English(India) . Select according to your country
  • click save and then next.

2. Interaction Model

Here, we will use skill builder. So,Click on Launch Skill Builder. you will see page as shown in image i8.

  • First we create new intents. Click on Add (on left hand side) and give any name you want i used "smartswitch" .
  • Give slot type name "measurement_type" and slot values "temperature" and "humidity" as shown in image i9.

  • After that add slot type name "query" and slot values are "what" and "is" as shown in image i10.

  • After that add slot type "switchstate" and slot values are "on" and "off" as shown in image i11.

  • Add another slot type "tempscale" and slot values are "fahrenheit" and "celcuis" as shown in image i12.

  • After that add new slot type here we use existing slot type for that we have to click on use existing slot .In existing slot search for amazon.number and select this and add it. After adding it you will see it in slot types as shown in image i13.

So we are done with slot types total slot type we are using is 5. Now, move to next step.Click on intent which we created, in my case it is smartswitch. On right hand side you will see intent slot as shown in image i14.

  • Create a new slot , give it name "Switch_State" and map it to "switchstate" by using drop down button as shown in image i15.
  • Create new slot ,give it name "Sensor_Values" and map it to "measurement_type" as shown in image i16.

  • Create new slot, give it name "query" and map it to "query" as shown in image i17.

  • After that create new slot "tmp_scale" and map it to "tempscale" as shown in image i18.

  • Create new slot "Numbers" and map it to "Amazon.Numbers " as shown in image i19.

Now we are done with Intent slots. We are using 5 intent slots. After this we move to Sample Utterances as shown in image i20.

Add this sample utterances.

  • set switch trigger to {Numbers} percent {tmp_scale}
  • {query} is the switch state
  • {Switch_State} switch trigger
  • set switch trigger to {Numbers} degree {tmp_scale}
  • turn switch {Switch_State}
  • {query} switch {Switch_State}
  • {query} is the current {Sensor_Values}

After this save model and build it. Wait for model to be build after that click on configuration.After building you will see message as shown in image i21 and i22.

3. Configuration

Select HTTPS and add link which was generated while creating heroku app . In my case it is https://iottempswitch.herokuapp.com/ . After adding link click on next as shown in image i23.

4. SSL certificate
Select second option and click on next as shown in image i24.

we have successfully created our skill.

Step 3: Arduino

  • Open Arduino IDE.Then go to File ==> Preference.
  • In Additional Boards Manager, copy and paste the URL and click ok as shown in image i26.

http://arduino.esp8266.com/versions/2.4.0/package_...

  • Open Board Manager by going to Tools ==> Board ==> Board Manager.

  • Open Boards Manager and search for nodemcu as shown in image i27.

  • After that download ESP8266WiFi library .Open library Manager : Sketch ==> Include library ==> Manage Libraries.

  • Search for ESP8266WiFi library and install it.

  • Select board ==> Generic ESP8266 Module.

  • Before uploading the code we need three libraries.

Required libraries

  • Move this libraries to libraries folder of Arduino.

You have to change three things in code SSID , PWD and your heroku app link.
After that upload the code. For ESP Module you have to press flash button while uploading the code and then press reset button one time and then release the flash button. After uploading the code, open the terminal. you will see output.

Step 4: Component Description

1. What is a Relay


Relay is an electromagnetic device which is used to isolate two circuits electrically and connect them magnetically. They are very useful devices and allow one circuit to switch another one while they are completely separate. They are often used to interface an electronic circuit (working at a low voltage) to an electrical circuit which works at very high voltage. For example, a relay can make a 5V DC battery circuit to switch a 230V AC mains circuit.

How it works

A relay switch can be divided into two parts: input and output. The input section has a coil which generates magnetic field when a small voltage from an electronic circuit is applied to it. This voltage is called the operating voltage. Commonly used relays are available in different configuration of operating voltages like 6V, 9V, 12V, 24V etc. The output section consists of contactors which connect or disconnect mechanically. In a basic relay there are three contactors: normally open (NO), normally closed (NC) and common (COM). At no input state, the COM is connected to NC. When the operating voltage is applied the relay coil gets energized and the COM changes contact to NO. Different relay configurations are available like SPST, SPDT, DPDT etc, which have different number of changeover contacts. By using proper combination of contactors, the electrical circuit can be switched on and off. Get inner details about structure of a relay switch.

The COM terminal is the common terminal. If the COIL terminals are energized with the rated voltage, the COM and the NO terminals have continuity. If the COIL terminals are not energized, then the COM and the NO terminals have no continuity.

The NC terminal is the Normally Closed terminal. It is the terminal that can be powered on even if the relay doesn't receive any or sufficient voltage to operate.

The NO terminal is the Normally Open terminal. It is the terminal where you place the output that you want on when the relay receives its rated voltage. If there is no voltage to the COIL terminals or insufficient voltage, the output is open and receives no voltage. When the COIL terminals receive the rated voltage or a little under, the NO terminal receives sufficient voltage and can turn on the device on the output.

2.DHT temperature sensor

DHT11 is a Humidity and Temperature Sensor, which generates calibrated
digital output. DHT11 can be interface with any micro controller like Arduino, Raspberry Pi, etc. and get instantaneous results. DHT11 is a low cost humidity and temperature sensor which provides high reliability and long term stability.

3. ESP8266 Complete Description

The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP
protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application networking functions from another application Each ESP8266 module comes pre-programmed with an AT command.

The ESP8266 supports APSD for VoIP applications and Bluetooth
co-existence interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.

Features

  • 802.11 b/g/n
  • Wi-Fi Direct (P2P),
  • soft-APIntegrated TCP/IP protocol stack
  • Integrated TR switch, balun, LNA, power amplifier and matching network
  • Integrated PLLs, regulators, DCXO and power management units
  • +19.5dBm output power in 802.11b mode
  • Power down leakage current of <10uA
  • 1MB Flash Memory
  • Integrated low power 32-bit CPU could be used as application processor
  • SDIO 1.1 / 2.0, SPI, UART
  • STBC, 1×1 MIMO, 2×1 MIMOA-MPDU & A-MSDU aggregation & 0.4ms guard interval
  • Wake up and transmit packets in < 2ms
  • Standby power consumption of < 1.0mW (DTIM3)

Pin Description as shown in image i34.

For connecting ESP Module with Arduino UNO we need Lm1117 3.3 voltage regulator or any regulator because Arduino is not capable of providing 3.3 v to ESP8266.

Note:- While uploading the code press flash button and then press reset button one time and then release flash button as shown in image i29.

For connecting DHT11 sensor and relay we use two GPIO pins of ESP8266 Module. After uploading the code you can disconnect the RX,TX,GPIO0 pins. I have used GPIO0 for DHT11 sensor and GPIO2 for relays. DHT11 sensor works fine with ESP8266 but for relays we need one extra thing i.e opto isolator or opto coupler. See image i30,i31,i32 and i33.

Step 5: Connections

ESP8266 === > DHT11
GPIO0 === > Output pin

ESP8266 === > Relay
GPIO2 ===> Input

ARDUINO ===> ESP8266

Gnd ===> Gnd
TX === > TX

RX === > RX

Reset Button === > RST

Flash Button === > GPIO0

Step 6: Checking All the Things

We have successfully created our app, skill and our hardware is ready . So, its time to check .

For that your ESP8266 is powered on because our server is running on ESP8266 . Here I have not connected any sensor to ESP8266 I am just checking whether its working or not but you can connect sensor , relay to ESP8266. Once it is connected to Heroku you will see connected. For testing go to Amazon skill which you created, then click on test page. Once it is verified its working I will connect my sensor to ESP8266 . You can see results as shown in images i35,i36,37,38,39,40.

If you use it without connecting ESP8266 you get this error as shown in image i41.

Utterance you can use

  • set switch trigger to {Numbers} percent {tmp_scale}

ex :- set switch trigger to 50 percent humidity

  • {query} is the switch state

ex- on/off is the switch state

  • {Switch_State} switch trigger

ex -on/off switch trigger

  • set switch trigger to {Numbers} degree {tmp_scale}

ex - set switch trigger to 76 degree fahrenheit

ex - set switch trigger to 24 degree celcius

  • turn switch {Switch_State}

ex - turn switch on/off

See image i41 to i46 for results.

While talking to Alexa
Alexa, ask arduino to turn switch trigger on/off

Alexa, ask arduino to set switch trigger to 24 degree celsius.

Alexa, ask arduino to set switch trigger to 50 percent humidity

Alexa, ask arduino to turn switch on/off

Step 7: VUI(Voice User Interface) Diagram

Step 8: Demo


1.Set trigger for temperature and humidity.

2.Set trigger to 20 degree celsius.

3.Set trigger to 80 percent humidity.

Step 9: Schematic

Step 10: Program

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Woodworking Contest

      Woodworking Contest
    • Make it Move Contest

      Make it Move Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments

    That's a neat interface setup :) You should enter this in the Arduino contest too!

    1 reply

    I am currently working on different project for that contest.