HOW IT WORKS?
When the button in the app is clicked, the speech recognizer is activated. After speaking, the phone sends the speech recognized to Arduino microcontroller via Bluetooth. If the speech recognized is "ON", the LED is turned on. If the speech recognized is "OFF", the LED is turned off.
MATERIALS REQUIRED:
THE CIRCUITS:
THE CODE:
#include <SoftwareSerial.h>
int led1 = 13;
int RX = 5;
int TX = 4;
String readdata;
SoftwareSerial BT(RX, TX);
void setup() {
// put your setup code here, to run once:
BT.begin(9600);
pinMode(led1, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
readdata += c; //build the string- "forward", "reverse", "left" and "right"
}
if (readdata.length() > 0) {
Serial.println(readdata);
if (readdata == "on"){
digitalWrite(led1, HIGH);
}
if (readdata == "off"){
digitalWrite(led1, LOW);
}
readdata="";
} }
THE BLOCKS:
LINK FOR SOURCE CODE:
HOW IT WORKS?
If the "ON" button is clicked, the phone sends inbyte 1 to the Arduino microcontroller. If the "OFF" button is clicked, the phone sends inbyte 2 to the Arduino microcontroller.
MATERIALS REQUIRED:
THE CIRCUITS:
THE CODE:
#include <SoftwareSerial.h>
int TX = 11;
int RX = 12;
SoftwareSerial mySerial(TX, RX); // RX, TX
int led1=13;
void setup()
{
pinMode(led1, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop(){
int inByte;
if (mySerial.available())
{
inByte= mySerial.read();
Serial.write(inByte);
if(inByte==1){
digitalWrite(led1, HIGH);
mySerial.println("on");
Serial.println("on");
}
if(inByte==2){
digitalWrite(led1, LOW);
mySerial.println("off");
Serial.println("off");
}
}
}
THE BLOCKS: