DIY VOICE HOME AUTOMATION USING ARDUINO AND ANDROID
- Circuit diagram
- Code for Arduino UNO
//Edison Media
//Thejus B Oommen
String voice;
int RED = 2;
int GREEN = 3 ;
int BLUE = 4;
int YELLOW = 5;
void RedOn(){
digitalWrite (RED, LOW);
}
void RedOff(){
digitalWrite (RED, HIGH);
}
void GreenOn(){
digitalWrite (GREEN, LOW);
}
void GreenOff(){
digitalWrite (GREEN, HIGH);
}
void BlueOn(){
digitalWrite (BLUE, LOW);
}
void BlueOff(){
digitalWrite (BLUE, HIGH);
}
void YellowOn(){
digitalWrite (YELLOW, LOW);
}
void YellowOff(){
digitalWrite (YELLOW, HIGH);
}
void allon() {
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (YELLOW, LOW);
}
void alloff() {
digitalWrite (RED, HIGH);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, HIGH);
digitalWrite (YELLOW, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(YELLOW, OUTPUT);
}
void loop() {
while(Serial.available()) {
delay(10);
char c=Serial.read();
if(c=='#')
{break; }
voice += c;
}
if (voice.length() > 0) {
Serial.println(voice);
if (voice == "on" || voice == "all")
{
allon() ;
}
else if (voice == "switch off" || voice=="switch off all")
{
alloff() ;
}
else if(voice =="tubelight" || voice =="tubelight on"){
RedOn();
}
else if(voice =="switch off tubelight" || voice =="tubelight off"){
RedOff();
}
else if(voice =="bedroom" || voice =="bedroom on"){
YellowOn();
}
else if( voice =="switch off bedroom" || voice =="bedroom off" ){
YellowOff();
}
else if(voice =="bulb" || voice =="bulb on"){
BlueOn();
}
else if(voice =="switch off bulb" || voice =="bulb off"){
BlueOff();
}
else if(voice =="ceiling fan" || voice =="ceiling fan on"){
GreenOn();
}
else if(voice =="switch off ceiling fan" || voice =="ceiling fan off"){
GreenOff();
}
voice="";
}
}
Please subscribe our channel