Devices & Components
Arduino Uno Rev3
2.2k Resistor
BD139 Transistor
HC-05 Bluetooth Module
Relay (generic)
Jumper wires (generic)
Hardware & Tools
Hot glue gun (generic)
Soldering iron (generic)
Software & Tools
Arduino Bluetooth Controller
Project description
Code
Control AC load with Voice Command
arduino
1String voice; 2 3#define r1 5 4int relay1 = LOW; 5#define r2 6 6int relay2 = LOW; 7#define r3 7 8int relay3 = LOW; 9#define r4 8 10int relay4 = LOW; 11void setup() 12{ 13 Serial.begin(9600); 14 pinMode(r1, OUTPUT); 15 pinMode(r2, OUTPUT); 16 pinMode(r3, OUTPUT); 17 pinMode(r4, OUTPUT); 18 } 19void loop() { 20 while (Serial.available()) //Check if there is an available byte to read 21 { 22 delay(10); //Delay added to make thing stable 23 char c = Serial.read(); //Conduct a serial read 24 voice += c; //Shorthand for voice = voice + c 25 } 26 27 if (voice.length() > 0) 28 { 29 Serial.println(voice); 30 if(voice == "all off") 31 { 32 digitalWrite(r1,0); 33 digitalWrite(r2,0); //all off 34 digitalWrite(r3,0); 35 digitalWrite(r4,0); 36 delay(250); 37 } 38 else if(voice == "fan") 39 { 40 41 relay1 = ~ relay1; 42 digitalWrite(r1,relay1); 43 delay(250); 44 } 45 else if(voice == "light") 46 { 47 relay2 = ~ relay2; 48 digitalWrite(r2,relay2); 49 delay(250); 50 } 51 else if(voice == "lamp") 52 { 53 relay3 = ~ relay3; 54 digitalWrite(r3,relay3); 55 delay(250); 56 } 57 else if(voice == "tubelight") 58 { 59 relay4 = ~ relay4; 60 digitalWrite(r4,relay4); 61 delay(250); 62 } 63 voice=""; //Reset the variable after initiating 64 }}
Comments
Only logged in users can leave comments