0

I want to connect a HC-05 Bluetooth module to an ESP8266 and use the input received from the bluetooth module in an if/else statement.

When doing this I can receive data from bluetooth to the serial, but then I cannot use the Arduino IDE serial to println characters. Why doesn't println work anymore for the Serial, if i .begin the bluetoothserial connection?

Tried different baud rates, different Pins

#include <SoftwareSerial.h>

SoftwareSerial BTserial(1, 3); // RX | TX

String reading;

void setup() 
{
    // Arduino IDE serial monitor
    Serial.begin(9600);

    Serial.println("hoihoi");
    // HC-05 default serial speed for AT mode is 38400
    BTserial.begin(9600);  

    // Wait for hardware to initialize
    delay(1000);

    // Print debug string
}

void loop()
{
  Serial.println("hoi");
   // Keep reading from HC-05 and send to Arduino Serial Monitor
   if (BTserial.available())
   {
      String reading = (String)BTserial.read();
      Serial.println(reading);

      //input from mobile is 1 AKA 10% PWM
      if(reading == "1"){
        Serial.println("Input from Bluetooth is 1");
      } 

      //input from mobile is 2 AKA 100% PWM
      else if(reading == "2") {
        Serial.println("Input from Bluetooth is 2");        
      }

      //input from mobile is 3 AKA 0% PWM
      else if(reading == "3") {
        Serial.println("Input from Bluetooth is 3");        
      }  
   }
}

I want to use the data received from the bluetooth module in and if/else statement and output it in the Serial.

However, currently I cannot print anything to the Serial. When I remove " BTserial.begin(9600);" I can output to the Serial.

Bart
  • 21
  • 1
  • 1
  • 2
  • you use the hardware Serial pins for the SoftwareSerial. how can you wire both to the same pins of the esp8266? unless you have a dev board with esp8266 and an USB chip which is wired to pin 1 and 3 on the esp8266 on board. why do you write esp8266 if you have a NodeMcu or Wemos or Huzzah or something similar? – Juraj Aug 16 '19 at 14:20
  • Me see on internet, that's the anwser on your questions. I see I do – Bart Aug 16 '19 at 21:11

1 Answers1

1

I had the same problem a few years ago. You almost got it! But pin 1 is still occupied 'SoftwareSerial BTserial(1, 3)'

Arduino UNO uses by default pin 0 and 1 as RX, TX to communicate with the Serial Monitor. This means that if you have something connected to these pins, you won't be able to print on the Serial Monitor.

Just changing your pins can solve your problem -> 'SoftwareSerial BTserial(2,3)'