A Home Automation System is a smart system that controls the lighting, entertainment systems, and other appliances. This system is very expensive when bought from the market. The Home Automation System is the fastest-growing concept of the modern world. Smart home automation is a concept in which a single component like a relay module is used to control various electronic parameters of a house, for example, switching of home appliances, monitoring of security alarms, garage door automation, etc. The major hurdle that comes while designing the automation system using Google Assistant is Language. The latest automation systems support only a few languages that include mostly English. Hence, in this project, we will design a Multi-Language home automation system that would support multiple languages like Hindi, Urdu, Bengali, etc. After completing this home automation system, we would be able to control the electrical appliances using the voice commands that would be given in different languages. The main backbone behind this project is Google Assistant that would be used to control home appliances. We’ve preferred Google Assistant because it supports almost every language and furthermore, an Android Application would be designed for controlling the appliances.
How To Setup Raspberry Pi And Other Peripherals In Designing The System?
As we know what we want to do in this project, now let us move ahead and gather some more information about the hardware components to immediately start working on this project.
Step 1: Components Needed (Hardware)
The best approach to start any project is to make a list of components and going through a brief study of these components because no one will want to stick in the middle of a project just because of a missing component.
Step 2: Selecting the Raspberry Pi Model
The selection of Raspberry Pi is a very technical task and it should be done carefully so that you don’t suffer in the future. The Raspberry Pi Zero is not preferred because it is the oldest model available in the market with a limited amount of specifications and setting up a network on it is a very tiring job. The latest models like 3A+, 3B+ can be purchased. The Raspberry Pi 3 is the quickest and most dominant gadget the Raspberry Pi Foundation has released to date. So, in this project, we will use the Raspberry Pi 3B+.
Step 3: Setting Up Raspberry Pi
There are two options for setting up Raspberry Pi. First, one is to connect your Pi with LCD and connect all the necessary peripherals and start working. The second one is to set up Pi with the laptop and access it remotely. It depends on the availability of LCD, if you have it at home then you can set up your Pi by using an LCD. Connect the LCD to the HDMI port of the Raspberry by using HDMI to VGA adapter. If you want to access your Pi remotely follow my article named “How To Access Graphical User Interface (GUI) Of Raspberry Pi Using SSH And VNC Viewer?”.
Step 4: Setting Up Apache Server On Raspberry Pi
After setting up Raspberry Pi we would set up the Apache server on it. For setting up we would type the following command in the Terminal window:
sudo apt-get install apache2 -y
We can verify the installation of the server by typing the IP Address of Pi in Web Server. We will open the Apache page in the Web browser and then we will utilize our Apache server to process PHP Files, for this you have to have the most recent version of the PHP module for Apache. Now, run the following command for running the latest version of the apache server.
sudo apt-get install php libapache2-mod-php-y
We need to control General Purpose Input Output (GPIO) pins of Raspberry Pi after setting up the Apache server. For controlling that we need to create a PHP file. Firstly, we would navigate to the HTML directory and then we would create a PHP file by typing the following command:
sudo nano appliancesoff.php
Then, we will write the following code in that file before saving it:
<?php System (“gpio -g mode 27 out”); System (“gpio -g write 27 0”); ?>
After writing the code in the editor file, press Ctrl+X for saving the code and then exit. We’ve created a PHP file for turning OFF the appliances, now we will create a PHP file for turning ON the appliances. The procedure is the same as above with a little bit of change in the Code. Create a PHP file for turning ON the appliances by typing the command given below:
sudo nano applianceson.php
Now, in the editor file paste the code provided below:
<?php System (“gpio -g mode 27 out”); System (“gpio -g write 27 1”); ?>
Step 5: Preparing The Google Assistant
As our automation system would be operated using our voice commands hence we would make some alterations in language settings.
You have to choose the language in which you want your operating system to be operated. Go to the “Routines” option and in the menu of the Routines button, you will find a plus icon. We will create our voice command hence speak the command which would be used to control the appliances. Suppose if you want to control the LED bulb, you would set an appropriate command for turning ON and turning OFF the bulb.
Step 6: Developing A Mobile Application
Now, let us move towards developing a mobile application that will be used to control the electrical appliances attached to our system. As we are going to develop an application for our android operated mobile phone, we will need a platform that allows us to do that. For that purpose we need the following two software:
Step 7: Setting Up Android Studio
Before installing the Android studio on our computers first, another thing is to be installed named JAVA JDK. To install this, click on the exe file that you downloaded from the above link. Keep on clicking the next button until it is installed. Now JAVA is to be recognized as an external or internal command by your computer. To do this, go through the following steps.
- Open Control Panel and click on System and Security.
- Click on System.
- Click on Advanced System Setting and then click on Environmental Variables.
- In the System Variable section, click on the path and then click on edit. A new Edit Environmental Variable box will appear.
- Now go to C:\Program Files\Java in your PC. Open the JDK folder, click on the bin folder and then copy the path of that folder.
- Now go to the Edit Environmental Variable box and click on new to make a new variable. Paste the path that you copied in the above step in the new variable and save it.
- Now to confirm, if it is completely installed, open command prompt and type java –version.
Now as you have successfully installed Java JDK on your computer. Let us now install Android Studio on your computer. Installing this software is very easy. You need to open the downloaded file and click next until your software is fully installed.
Step 8: Making The Layout
Now, here we will make a layout for our application that will be used by the user to send different commands to the raspberry pi. To make a simple layout, go through the following steps.
1. First of all, go to File > New > New Project. A menu will appear. Select Empty Project.
2. Now name the project as Voice Control and set JAVA as your programming language.
3. Since we are going to use the internet to control the pins of the raspberry pi. We will set permission in our app to access local wifi. To do this go to app > manifests > AndroidManifest.xml and add the following command.
<uses permission android:name="android.permission.INTERNET" />-
4. Now go to app > res > layout > activity_main.xml. here we will design a layout. Copy the code given below there to make a text view.
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif-black" android:text="Lights On" android:textColor="#000" android:textSize="36sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <android.support.design.widget.NavigationView android.id="@+id/navigation" android:layout_width="395dp" android:layout_height="50dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" /> </android.support.constraint.ConstraintLayout>
5. Now right click on res and create a new Directory. Name this directory as a menu.
6. Now right-click on menu directory and create a new Android Resource File.
7. Now open this resource file names as menu and copy the following code in it.
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/lighton1" android:title="Light On" /> <item android:id="@+id/lightoff1" android:title="Light Off" /> <item android:id="@+id/fanon1" android:title="Fan On" /> <item android:id="@+id/fanoff1" android:title="Fan Off" /> </menu>
8. Now go to app > java > com.example.voicecontrol > MainActivity. Here we will make a web view and some string variables. To do this, copy the following code in our Main activity. Make sure you replace the IP in the code, with the IP of your Raspberry Pi.
Your layout will look like the picture below:
Step 9: Assembling The Hardware And Giving Final Touches
Now, we have successfully completed the software part of this project. We will assemble the hardware now and then test it.
- Making Connections: We will look for GPIO 13 and 15 pins of the Raspberry Pi in the datasheet. After finding them connect the GPIO 13 pin to the IN1 pin of the Relay module. Connect the GPIO 15 pin to the IN2 pin of the Relay module.
- Testing: As we have made all of the connections we will check whether our hardware is working properly or not. Turn ON the Raspberry Pi and speak “Hey Google”, and we will speak one of the commands that we’ve set in the language settings. For example, we will say “Hey Google Turn On The Light” if we have set the preferred language as English and the light would be turned ON. The appliances can also be controlled through our Android Studio Application. If anyone wants to control the appliances through the application, he/she should open the application and start pressing the icons present in the application for controlling the appliances.
That’s all for today. We’ve successfully completed the multi-language home automation system project and now we can control our electrical appliances through our mobile phone easily.
Appuals.com is a participant in the Amazon Services LLC Associates Program, and we get a commission on purchases made through our links.