Arduino Uno and HC-05: Not showing any output on serial monitor

631 views Asked by At

Arduino Uno - HC-05

Connections are: TX-RX, RX-TX, LED-D13, 5V-5V+

For this project, we can supply power to the Arduino through any +5V power source. You can use a USB port from your computer to power the Arduino, but in this project I used my laptop.

while (Serial.available()) is returning 0 and Serial.read() is returning -1.

Need Help!

Used Bluetooth voice recognition tool from playstore-"Arduino Voice Control"

#include <SoftwareSerial.h> //Replace (' ') with (< >)

SoftwareSerial BLU(0,1);
String voice;
int Green = 13; //Connect To Pin #13
//int Yellow = 2; //Connect To Pin #2
//int Red = 3;    //Connect To Pin #3

void allon() {
  //digitalWrite(Red, HIGH);
  //digitalWrite(Yellow, HIGH);
  Serial.print("start");
  digitalWrite(Green, HIGH);
}

void alloff() {
  //digitalWrite(Red, LOW);
  //digitalWrite(Yellow, LOW);
  digitalWrite(Green, LOW);
}

void setup() {
  Serial.begin(9600);
  BLU.begin(9600);

  //pinMode(Red, OUTPUT);
  //pinMode(Yellow, OUTPUT);
  pinMode(Green, OUTPUT);
}

void loop() {
  //Serial.print("start loop");
  //Serial.print(Serial.available());
  while (Serial.available()) { //Check if there is an available byte to read
    //Serial.print("start");
    delay(10); //Delay added to make thing stable
    char c = Serial.read(); //Conduct a serial read
    //Serial.print(Serial.read());
    if (c == '#') {
      break; //Exit the loop when the # is detected after the word
    }
    //Serial.print(c);
    voice += c;
    //Serial.print(voice+"\n");
  }

  if (voice.length() > 0) {
    Serial.print("Start");
    Serial.print(voice);
    if (voice == "*turn on all LED") {
      allon();
    } 
    else if (voice == "*turn off all LED") {
      alloff();
    }
    /*else if(voice == "*switch on red") {
      digitalWrite(Red,HIGH);
    }
    else if(voice == "*switch on yellow") {
      digitalWrite(Yellow,HIGH);
    }*/
    else if(voice == "*switch on green") {
      digitalWrite(Green,HIGH);
    }
    /*else if(voice == "*switch off red") {
      digitalWrite(Red,LOW);
    }
    else if(voice == "*switch off yellow") {
      digitalWrite(Yellow,LOW);
    }*/
    else if(voice == "*switch off green") {
      digitalWrite(Green,LOW);
    }
    voice=""; //Reset variable
  }
}
1

There are 1 answers

0
astrick On

You need to check for the app output first. If you already know it then mention that in comment otherwise do the following for printing app output first:-

const int LED = 5;

void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);

}

void loop() {
    while(Serial.available()>0){
     
    switchstate = Serial.read();
  
    Serial.print(switchstate); // First check what output are you getting from the application
    
    Serial.print("\n");
    
    delay(15);
   
    if(switchstate == '1'){ // Compare your app output accordingly 
     digitalWrite(5, HIGH);
    }
    else if(switchstate == '0'){
     digitalWrite(5, LOW);
    }
    }
}