Agus Suparman
Published © CC BY

Menyalakan Lampu Dengan Perintah Suara

Menghubungkan arduino ke android melalui bluetooth dan kemudian menggunakan perintah suara untuk mengendalikan perangkat menggunakan relay

IntermediateFull instructions provided3 hours24,330
Menyalakan Lampu Dengan Perintah Suara

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Relay Module
Tessel Relay Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×11
Android device
Android device
×1
Bluetooth Low Energy Module
Tessel Bluetooth Low Energy Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

fps60cehxez6sw7_medium_Ryhdkd4pFx.jpg

Code

Untitled file

C/C++
String voice; 
#define relay1 3    //Connect relay1 to pin 3 
void setup() 
{ 
 Serial.begin(9600);            //Set rate for communicating with phone 
 pinMode(relay1, OUTPUT);       //Set relay1 as an output  
 digitalWrite(relay1, LOW);     //Switch relay1 off 
} 
void loop() 
{ 
 while(Serial.available())    //Check if there are available bytes to read 
 { 
   delay(10);                 //Delay to make it stable 
   char c = Serial.read();    //Conduct a serial read 
   if (c == '#'){ 
     break;                   //Stop the loop once # is detected after a word 
   } 
   voice += c;                //Means voice = voice + c 
 } 
   if (voice.length() >0) 
   { 
     Serial.println(voice); 
     if(voice == "*switch on"){ 
       switchon(); 
     }               //Initiate function switchon if voice is switch on 
     else if(voice == "*switch off"){ 
       switchoff(); 
     }               //Initiate function switchoff if voice is switch off 
     else if(voice == "*lamp on"){    
//You can replace 'lamp on' with anything you want...same applies to others 
       digitalWrite(relay1, HIGH); 
     } 
     else if(voice == "*lamp off"){ 
       digitalWrite(relay1, LOW); 
     }  
     voice=""; 
   } 
} 
void switchon()               //Function for turning on relays 
{ 
 digitalWrite(relay1, HIGH);  
} 
void switchoff()              //Function for turning on relays 
{ 
 digitalWrite(relay1, LOW);  
}

Credits

Agus Suparman

Agus Suparman

1 project • 0 followers

Comments

Add projectSign up / Login