Today, home automation using Internet of things (IoT) is one of the major domains which is attracting attention from large tech companies.
We all want to own a smart home, but sometimes language becomes a barrier in setting up IOT home automation system. Most of the existing home automation systems support only a few languages, generally English.
Wouldn’t it be nice if we can control our home with multiple languages like Hindi, Bengali, Marathi and so on?
Yes, it’s possible now! In this DIY project, we are going to make an IOT home automation system that will allow you to control your home with voice commands given in your preferred language.
This home automation system uses google assistant to control the smart devices at home. So, it also supports all the languages supported by the google assistant. We will also make an app to control the system.
Let’s start the project –
Bill of Material
Setting Raspberry Pi
The first thing we need to do is to set up an Apache server in Raspberry Pi. To do it, open the terminal window and run the following command.
sudo apt-get install apache2 -y
After successful installation of the server, we can check it by typing the I.P address of your Raspberry Pi in any web browser. If the server is working fine, we will get the Apache page in the web browser. Now, we will use our Apache server to process PHP Files, for this you need to have the latest version of PHP module for Apache. To get this module run this command –
sudo apt-get install php libapache2-mod-php -y
Next, we will create a PHP file to control the GPIO of Raspberry Pi. To do so, open terminal in Raspberry Pi and go to its html directory by this command as you can see in Fig 1.
Next create a PHP file by using “sudo nano lightsoff.php” command
and write the following piece of code in it,
System (“gpio -g mode 27 out”);
System (“gpio -g write 27 0”);
Then press Ctrl+X to save and exit from the editor.
After this create a lightson.php file for turning the lights on and paste the following code in it.
System (“gpio -g mode 27 out”);
System (“gpio -g write 27 1”);
Repeat the same process for controlling other GPIO of Raspberry Pi.
You can download the whole code for turning lights on and off from the link below.
Setting Google Assistant
Now, we are going to prepare the google assistant for our voice command. First open the language settings of google assistant and select the language of your choice. Then open the google assistant settings and go to “Routines” option. You will get a plus floating button in the menu of Routines, click on that and then set the voice command that you want to create. For example, if you want to control lights, you can set the voice commands in your preferred language to turn on the lights. After this, set the action for that voice command in the given format (Refer Fig. 3,4,5,6,7)
“search Rpi IP address/ PHP file name”.
Search 192.168……../ lightsoff.php.
Now connect the components as illustrated below.
Raspberry pi Relay Board
GPIO 13 Relay IN 1
GPIO 15 Relay IN 2
5V Relay 5V
We can also create an app to control the lights. Let’s make the app.
Open Android studio and create a new project with bottom navigation bar and do coding as illustrated below (Refer Fig. 10 ,11,12,13,14).
First of all, set the permission in app to access the internet because we are going to use Wi-Fi to control GPIO of RPi.
Then go to Mainactivity.java and create a WebView and String variables as in the picture below.
Fig 14. Creating Navigation bar
Power the Raspberry Pi with 5V DC. Then connect Raspberry Pi and your phone to your Wi-Fi network or you can also use phone HOTSPOT. Then say “hey google” followed by the voice command that we have set in our preferred language. For example, say “hey google light on kar do”
And it will turn on the lights. You can also control lights with the app we have just created. Open the app and press the icons in navigation to turn the lights on/off