As we all know, Home automation is now trending....
So here I wanted to share this project by which you can control your curtains from anywhere you are sitting or sleeping by giving the command to your google assistant. Well I am using IFTTT with the google assistant and WebHooks(used for making web request) so if you say "OK google" "Open the curtains" then it will sent the API Request to the bolt cloud and bolt cloud sent the data to the bolt device and then bolt device sent it to the Arduino and that is how the data is sent to the Arduino.
As I said above the bolt device sends the data to the Arduino but how?
For understanding this project first you should know what the serial communication is?
Serial communication is the process of sending data one bit at a time, sequentially.
When you complete your connections of hardware as I mentioned in the connections section then think about that what the Tx and Rx pin does?
Well, Tx pin is used to transmit the data and Rx pin is used to receive the data.
So here you know why we connect the Tx pin of bolt IOT device to Rx pin of the Arduino and vice versa. Once the bolt device has the data it will be send to the Tx pin of the bolt IOT device and then it will received at the Rx pin.
Now the 5th and 4th digital pin are connected to the L298 motor driver as shown in the circuit. So that we can run the motor with the 9 volt battery.
I used the phone for powering up the bolt device.
I used hand made thread rollers and connect them to the motors.
Now get your bolt API key by log in into https://cloud.boltiot.com by following steps.
- got to website > select API > Enable > copy it.
if not have API then first generate by clicking GENERATE NEW API it and then copy it.
Well here is the main part of the project where we will use serialWrite()
function
- serialWrite() function is used to perform serial communication between bolt IOT device and Arduino.
serialWrite()
function uses the String as a parameter, where String will be transmitted as ASCII characters and the device name.
For example:
serialWrite('Hello'): this will sent the Hello string from the Tx pin in the form of binary stream.
so the URL format for this function will be
https://cloud.boltiot.com/remote/Api_key/serialWrite?data=Any_string&deviceName=Name_of_the_device
here the paste API_Key is the key which get from bolt cloud and Name_of_the_device is your bolt device name.
Example:
This is how your URL looks:
- https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/serialWrite?data=Hello&deviceName=BOLT8795377
So we will use two similar URL having serialWrite function in it.
1.)https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/serialWrite?data=1&deviceName=BOLT879537
In the above URL serialWrite?data=1 means we are using '1' as a string. So if '1' will be sent to the arduino then it will open the curtains.
Similary We will use below URL for closing the curtains and it uses '2' as a string.
2.)https://cloud.boltiot.com/remote/44b2de6b-7e68-40e7-a27f-814b58afe008/serialWrite?data=2&deviceName=BOLT8795377
As I mention earlier that we are controlling the curtains with the google assistant.
- For this we will use IFTTT, So follow the steps below:
1. Go to https://ifttt.com/create and click on 'This' to set the google assistant
2. search for google assistant and select it.
3. Select 'Say a single phrase'
4. Fill up the commands by which you can control your curtains and what response you want to get from google assistant and then click on 'create trigger'.
5. Now click on 'That' to link it to the webhooks Which makes the web request.
6. Search for the WebHooks and select it.
7. Click on the 'Make a web request' to make the web request to the bolt cloud.
8. Copy the URL which we had learned in the 4th topic which uses the serialWrite function and click on 'create action'.
before this make sure you have replace your API key and device name.
9. So you have completed the IFTTT configuration. Click on finish.
Now repeat all the steps again for closing the curtains by using second URL.
6. Explaining Arduino codeYou can copy the code from code section.
In void setup part serial.begin (9600)
function is used to start the Serial communication with the baud rate of 9600 and I uses the 4th and 5th digital pin as output by using pinMODE()
function.
void setup{
Serial.begin(9600);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}
I uses the Serial.available function which returns values greater than 0 if Arduino receives something from bolt IOT device through Rx pin.
Declaring the character 'a' Which reads the String by Serial.read function.
So when Arduino receives '1' then Serial.available()>0
condition became true and then character 'a' has been assigned by the String '1' and the a=='1'
condition became true and then motors starts rotating and opening the curtains by using digitalWrite()
function. Similarly a=='2'
condition became true and it will close the curtains when the Arduino receives '2'.
void loop() {
if(Serial.available()>0)
{
char a=Serial.read();
Serial.println(a);
if(a=='1')
{
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
delay(1000);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
}
if(a=='2')
{
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
}
}
7 demo:
Comments
Please log in or sign up to comment.