Hello,
I'm making a smart room with relays controlled by your voice with an Audeme MOVI shield. I also want the option to control it by phone with the hc-05 bluetooth module but I can't get the code to work, sometimes only voice controll works and then I change the code a litle then only bluetooth works. Please help me.
(NOTE: I did not completely write this code on my own, some parts i coppied from the internet)
Here is my code: (in this code voice control works but bluetooth doesn't)
#include <MOVIShield.h>
#include <SoftwareSerial.h>
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_PIC32)
#endif
MOVI recognizer(true); // Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins on AVR architecture
SoftwareSerial Genotronex(10, 11); // RX, TX
int Relay1=2; //set relays
int Relay2=3;
int Relay3=4;
int Relay4=5;
int BluetoothData; // the data given from Computer
void setup() {
pinMode(Relay1,OUTPUT); // set all relays as an output
pinMode(Relay2,OUTPUT);
pinMode(Relay3,OUTPUT);
pinMode(Relay4,OUTPUT);
digitalWrite(Relay1,1); //set all relays high
digitalWrite(Relay2,1);
digitalWrite(Relay3,1);
digitalWrite(Relay4,1);
Genotronex.begin(9600);
recognizer.init(); // Initialize MOVI (waits for it to boot)
recognizer.setSynthesizer(SYNTH_PICO); //changes voice of the synthesizer
recognizer.callSign("Arduino"); //reacts if you say this word
recognizer.addSentence("Relay one on"); //sentence 1
recognizer.addSentence("Relay one off"); //sentence 2
recognizer.train(); //train
}
void loop() {
signed int res=recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, negative values denote events
if (res==1) { // Sentence 1.
digitalWrite(Relay2,1); // Turn on relay1
recognizer.say("Relay one is on!"); // Speak a sentence
}
if (res==2) { // Sentence 2
digitalWrite(Relay1,0); // Turn off relay1
recognizer.say("Relay one is off!"); //Speak a sentence
}
if (Genotronex.available()){ //if bluetooth data is available
BluetoothData=Genotronex.read(); //read bluetooth data
if(BluetoothData=='1'){ //if buetooth data is 1, turn relay off
digitalWrite(Relay1,0);
}
if(BluetoothData=='2'){ //if buetooth data is 2, turn relay on
digitalWrite(Relay1,1);
}
if(BluetoothData=='3'){ //if buetooth data is 3, turn relay off
digitalWrite(Relay2,0);
}
if(BluetoothData=='4'){ //if buetooth data is 4, turn relay on
digitalWrite(Relay2,1);
}
if(BluetoothData=='5'){ //if buetooth data is 5, turn relay off
digitalWrite(Relay3,0);
}
if(BluetoothData=='6'){ //if buetooth data is 6, turn relay on
digitalWrite(Relay3,1);
}
if(BluetoothData=='7'){ //if buetooth data is 7, turn relay off
digitalWrite(Relay4,0);
}
if(BluetoothData=='8'){ //if buetooth data is 8, turn relay on
digitalWrite(Relay4,1);
}
}
}
Home_Automation.ino (2.64 KB)