Introduction: Iot Based Home Automation System With Speech Recognition

About: I am an engineering student who is very passionate about technology. I like to code a lot, build projects and I am very curious of different tech. things and its working. IoT have been one of my favorite topic…

This project presents the design of the low cost home automation system using the IoT(Internet of Things) technology along with the feature of speech recognition. The Internet of things (IoT) is the inter-networking of physical devices, vehicles, buildings, and other items embedded with electronics, software, sensors, actuators, and network connectivity that enable these objects to collect and exchange data. In this project IoT technology is used to control the home appliances wirelessly over the internet. The computing module used is a Raspberry pi development board. The project also aims to provide a speech control interface to the users to control the appliances. Speech recognition is provided using an online Speech-To-Text platform called wit. The home automation system listens for the user’s speech and whenever a defined phrase is identified it triggers corresponding action to switch appliances on or off. With speech recognition physically challenged people can control appliances with much more ease

Step 1: Why HOME AUTOMATION ?

IoT is one of the fields in computer science which is growing at a rapid pace. With more availability of computing power at low costs the devices connected to the internet is also getting increased. Internet of things (IoT) is the inter-networking of physical devices, vehicles, buildings, and other items embedded with electronics, software, sensors, actuators, and network connectivity that enable these objects to collect and exchange data. IoT BASED HOME AUTOMATION WITH SPEECH RECOGNITION is a project which aims to provide the user the facility to control their home appliances through internet and also control it through their speech.

The main objectives of this project are as follows:

  • Develop a low cost home automation system which is easy to install and configure
  • Provide a secure and reliable web portal for the user to control the home appliances through the internet
  • Embed a speech control interface for controlling the electrical appliances for physically challenged people

Step 2: Hardware Requirements

The main component required is as follows:

1. RASPBERRY PI


A Raspberry Pi is a credit card-sized computer originally designed for education, inspired by the 1981 BBC Micro. Creator Eben Upton's goal was to create a low-cost device that would improve programming skills and hardware understanding at the pre-university level. But thanks to its small size and accessible price, it was quickly adopted by tinkerers, makers, and electronics enthusiasts for projects that require more than a basic microcontroller (such as Arduino devices). The Raspberry Pi is slower than a modern laptop or desktop but is still a complete Linux computer and can provide all the expected abilities that implies, at a low-power consumption level. Fig 6 raspberry pi The Raspberry Pi is open hardware, with the exception of the primary chip on the Raspberry Pi, the Broadcomm SoC (System on a Chip), which runs many of the main components of the board–CPU, graphics, memory, the USB controller, etc. Many of the projects made with a Raspberry Pi are open and well-documented as well and are things you can build and modify yourself. There are a two Raspberry Pi models, the A and the B, named after the aforementioned BBC Micro, which was also released in a Model A and a Model B. The A comes with 256MB of RAM and one USB port. It is cheaper and uses less power than the B. The current model B comes with a second USB port, an ethernet port for connection to a network, and 512MB of RAM. The Raspberry Pi A and B boards been upgraded to the A+ and B+ respectively. These upgrades make minor improvements, such as an increased number of USB ports and improved power consumption, particularly in the B+. The latest release is Raspberry pi 3 (inbuilt wifi and BLE). However, the Raspberry pi used in the project is model 2 B.

2. RELAY MODULE

Relays are switches that open and close circuits electromechanically or electronically. Relays
control one electrical circuit by opening and closing contacts in another circuit. As relay diagrams show, when a relay contact is normally open (NO), there is an open contact when the relay is not energized. When a relay contact is Normally Closed (NC), there is a closed contact when the relay is not energized. In either case, applying electrical current to the contacts will change their state. Relays are generally used to switch smaller currents in a control circuit and do not usually control power consuming devices except for small motors and Solenoids that draw low amps. Nonetheless, relays can "control" larger voltages and amperes by having an amplifying effect because a small voltage applied to a relays coil can result in a large voltage being switched by the contacts . Protective relays can prevent equipment damage by detecting electrical abnormalities, including over current, undercurrent, overloads and reverse currents. In addition, relays are also widely used to switch starting coils, heating elements, pilot lights and audible alarms.

3. WIFI DONGLE

Used to provide wireless internet access. Not to be used with raspberry pi 3 as it has built in wifi module.

4. POWER STRIP

To connect appliances to the power

5. USB SOUND CARD

Connect the sound card to any of the USB port of raspberry pi and ensure its connection using the command: lsusb, check whether the device has been recognized.

Step 3: Software Requirements

1. PHP (Hypertext Preprocessor)

PHP is a script language and interpreter that is freely available and used primarily on Linux web servers PHP , originally delivered from personal home page tools ,now stands for PHP: Hypertext Preprocessor, which the PHP FAQ describes as a “recursive acronym” .PHP is an alternative to Microsoft’s Active Server Page(ASP) technology. As with ASP, the PHP script is embedded within a web page along with its HTML. Before the page is sent to a user that has requested it , the Web server calls PHP to interpret and perform the operations called for in the PHP script.

2. PYTHON

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

3.HTML Hypertext Markup Language (HTML)

is the standard markup language for creating web servers and web applications. With Cascading Style Sheet (CSS) and java script it forms a triad of cornerstone technologies for the world wide web. Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.

4.CSS Cascading Style Sheets (CSS)

is a style sheet language used for describing the presentation of a document written in a markup language. CSS is the language for describing the presentation of Web pages, including colors, layout, and fonts. It allows one to adapt the presentation to different types of devices, such as large screens, small screens, or printers. CSS is independent of HTML and can be used with any XML-based markup language.

5.JAVA SCRIPT JavaScript ("JS" for short)

is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites. It was invented by Brendan Eich, co-founder of the Mozilla project, the Mozilla Foundation, and the Mozilla Corporation.

Step 4: Basic Architecture

The entire system consists of two parts:

1. Speech recognition

The speech recognition uses a python script called speechrecognition.py. This python script uses speech recognition library to record and process speech. It uses the wit API online Speech-To-Text platform to convert the speech to text. When the user provides the speech through the microphone the speech gets recorded by the python script in WAV format and is send to the wit platform along with an unique API key provided by the wit account. Once the audio file reaches wit it converts it in to text using their advanced speech recognition algorithm. The text is then send back to the python script. In the python script it is checked with the predefined commands to turn appliances on or off. If the phrase matches with text received then corresponding string (ON or OFF) is written to the file of respective relay. A python script is used called iot.py. It monitors the content of the files for each relays (relay1.txt – relay4.txt). Based on the content of the file ie either “ON” or “OFF” the python scripts turns the GPIO pin high or low for each of the relay connected to it.

2. Web Interface

The Raspberry pi hosts the web pages to control devices through an Apache web server. The web pages include index.html, controller.php, button.php, checklogin.php, logout.php. There file defined for each relays containing the string “ON” or “OFF”. The index page acts as the home page. Once user logs in with a username and password the checklogin page checks the credential with a preset credential. If a match occurs user will be redirected to controller page with after setting a session variable else user will be redirected to login page. In the controller page user can switch device on or off through buttons. On press of each button a button page is invoked which checks the button id and writes appropriate string to the corresponding relay file. A python script is used called iot.py. It monitors the content of the files for each relays (relay1.txt – relay4.txt). Based on the content of the file ie either “ON” or “OFF” the python scripts turns the GPIO pin high or low for each of the relay connected to it.Thus the relay turns on and off based on user input and any appliance can be connected to it to get controlled via internet.

Step 5: Installing Softwares

Installation of PHP, MYSQL has explained breifly on this link. Please go through the site and install both.

After installation place the following file under the directory /var/www/html

NOTE: you may need root permissions to do so, login as root in raspberry pi or perform copying in sudo

>>> Download the files from here

Step 6: Obtaining IP and Running the Scripts

After installation reboot the pi and obtain it's IP address through the command :

  1. "ifconfig" :check for the inet address in the wlan0, which will be your ip address
  2. Run python script "raspi.py" at the location /var/www/html to start the providing commands to the gpio
  3. Also start the python script "speechrecognition.py" at same location to listen to microphone (before runnig the this script ensure to install speech recognition library on the pi using : "pip install speech_recognition" on terminal
    1. The script uses the wit.ai cloud platfrom to perform speech recognition
    2. Generate your API key from wit.ai and add it to script at line WIT_API=""

Step 7: Hardware Connections

The hardware conncetion is pretty straight forward:

  1. Connect the relay module to Raspberry pi to 5v and GND pins as marked on relay module.
  2. Connect the signal pins of module to GPIO header 5,7,11,13 respectively
  3. Now, tap wires from each switches of power strip and connect it to Normally Open terminals of each relay.
  4. Power the raspberry pi using a 5v micro USB adapter and also connect the power strip to Wall scoket.

Step 8: Controlling the Devices....!

That's it finally we are able to control the device, follow the steps:

  1. Go to the IP address on a local device on same network, you will get the home page
  2. Enter the username:admin and password:iot
  3. You will get a controller page to switch device on and off anlong with current status of device
  4. If you provide voice command like "lighton" then relay connected to gpio 5 will turn on and "lightoff" for switching off
  5. For providing more command you can simply edit the python script to add you own command

That's it NOW YOU HAVE A BASIC HOME AUTOMATION SYSTEM INSTALLED ON YOUR HOME..

Hope you all enjoyed the project....! :)

Internet of Things Contest 2017

Participated in the
Internet of Things Contest 2017