Bluetooth HC-05 using Arduino hardware serial communication pin (0,1 RX/TX)

Hello,

New here and pretty noob in Arduino projects.

I wish to use the pin 0,1 (Rx, Tx) of the Arduino UNO because I don’t have anymore spare digital pins for communication with the Bluetooth HC-05 module.

The Blynk project on the App consist of 4 button (Up, Down, LightsON. LightsOFF)

I wish to be able to use the App and a RF remote keyfob to activate the stuffs.

According to my actual research:

  1. I can’t use the software serial standard code used normally in all examples…
  2. if I understand correctly it need to be in AT command mode to work ??
    (HC-05 Not working with Blynk!)
    (https://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/)
  3. Can’t have the USB plugged while having pin 0,1 connected to the BT module. Otherwise it will create interference of some sort.
  4. Baud rate on pin 0,1 is 9600, 115200 or something else ??
  5. I’ve read I should use the 3.3V or having resistances if using the 5V on Vcc but some other places says 5V is fine, especially since the BT board says 3.6 to 6V but Arduino board might use different voltage on pin 0-1… ?

Sometimes I see the BT module on my phone bluetooth devices list, some other times not… red LED on HC-05 is blinking rapidly. tried to pair one time but didn’t work (password 1234)

• Hardware model + communication type. : Arduino UNO with Bluetooth BT HC-05
• Smartphone OS (Android) + version: Galaxy S7, v8.0.0
• Blynk Library version 0.6.1

I know in the code it’s software serial being used but I tried other things as well…

// Table control using AdaFruit RF keyfob remote 
// & Bluetooth (Blynk App with HC-05 module)
// Raising up/down & lighting
// Stepper motor driver used: 2X 4A TB6600
// Stepper motor used: NEMA23
// By quebecois_sti, June 15th 2019

// Blynk App code
#define BLYNK_USE_DIRECT_CONNECT
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>

// Link created by Blynk App
char auth[] = "MyAuthCodeHereFromBlynk";

// defines pins numbers
#define stepPin 6 
#define dirPin 7 
#define enPin 8

#define LTrelay1 3
#define LTrelay2 5
volatile byte relayState1 = LOW;
volatile byte relayState2 = LOW;

#define UPlimitsw 4      // TOP limit switch
#define DWlimitsw 2      // BOTTOM limit switch
#define UPbutton 9       // UP button for raising from RF keyfob Remote-A
#define DWbutton 11      // DOWN button for lowering from RF keyfob Remote-C
#define LTONbutton 10    // ON button for light from RF keyfob Remote-B
#define LTOFFbutton 12   // OFF button for light from RF keyfob Remote-D

void setup() {

  delay(3000);
    
  pinMode(LTrelay1, OUTPUT);
  pinMode(LTrelay2, OUTPUT);
  
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);

  //Debug console
  DebugSerial.begin(9600);
  DebugSerial.println("Waiting for connections...");
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
  
}
void loop() {

  Blynk.run();
  
  //Turn ON the lights
  while(digitalRead(LTONbutton) == HIGH){
  
    if(relayState1 == LOW && relayState2 == LOW){
      digitalWrite(LTrelay1, LOW);
      digitalWrite(LTrelay2, LOW);
    }
    relayState1 = HIGH;
    relayState2 = HIGH;
  }
  
  //Turn OFF the lights 
  while(digitalRead(LTOFFbutton) == HIGH){
  
    if(relayState1 == HIGH && relayState2 == HIGH){
      digitalWrite(LTrelay1, HIGH);
      digitalWrite(LTrelay2, HIGH);
    }
    relayState1 = LOW;
    relayState2 = LOW;
  } 
  
  //Raising table & stop at top
  while(digitalRead(UPbutton) == HIGH && digitalRead(UPlimitsw) == HIGH){
      
    digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
    for(int x = 0; x < 100; x++) {
      digitalWrite(stepPin,HIGH); 
      delayMicroseconds(800); 
      digitalWrite(stepPin,LOW); 
      delayMicroseconds(800); 
    }
  }
  
  //Lowering table & stop at bottom
  while(digitalRead(DWbutton) == HIGH && digitalRead(DWlimitsw) == HIGH){
   
    digitalWrite(dirPin,LOW); //Changes the rotations direction
    for(int x = 0; x < 100; x++) {
      digitalWrite(stepPin,HIGH);
      delayMicroseconds(800);
      digitalWrite(stepPin,LOW);
      delayMicroseconds(800);
    }

  }
    
}

new links found using pin 0,1 but not with Blynk. can’t add in main message because new user…

First of all, your void loop isn’t Blynk friendly. You should read this:
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Secondly, Bluetooth isn’t really the best way to go with Blynk. Not all Blynk functions work with Bluetooth, because there is no direct connection from the Arduino to the Blynk server.

Thirdly, moving to an Arduino Mega would make your life so much easier, as you have more pins and multiple UARTs. An ESP-32, or multiple ESP8266’s with Bridge code would be a better solution if you want to use Wi-Fi.

Moving on to your specific questions (but out of order)…

It’s not just that you can’t have the USB plugged-in, it’s that the Serial UART cant handle data destined for both the HC-05 and the serial monitor, it’s one or the other.

This…

[quote="quebecois_sti, post:1, topic:38037"]
DebugSerial.begin(9600); DebugSerial.println("Waiting for connections...");
[/quote]

isn’t allowed because the Serial UART will be used by the HC-01, which means that there will be NO debug output available (tricky for debugging - see my Mega recommendation).

These two are related…

The baud rate on pins 0,1 is whatever you declare it as in your Serial.begin command. However, the Uno and the HC-05 need to be talking at the same baud rate for them to be able to understand each other. You need to temporarily use the Arduino in “AT mode” to do this, or use an FTDI adapter to connect your HC-05 to your PC and issue the AT commands to set the baud rate.

The Arduino uses 5v logic levels on these pins, so all is good.

In the app you should use virtual pins rather than directly manipulating the GPIO pins on the Arduino, it gives you much more control. Also, you’ll need to update the app widget statuses when you receive an RF command, so that the two stay in sync.

If you’re going to create a smarthome system then you’ll quickly move away from Bluetooth to Wi-Fi and may find that moving to a Node-Red and MQTT system along with Blynk is the best way to go.

Pete.

Thanks for your support Pete.

In the end, since there’s alot of limitations with Blynk/comm. maybe I should not use Blynk and lookout for other apps ?.. I have no idea to do a smarthome/domotic system. I only want to do that table being controlled in a standalone system (using RF remote and app on phone, preferrably by BT since you don’t want to disconnect your WiFi each time on your phone…)

Why is manipulation GPIO pins directly is not good right now ? I don’t really need more control ??

I wish to use the hardware I have in hand. I had to buy alot more parts than expected for this project and wish not to spend more (i know a Mega is not that expensive but…)

I think you misunderstand how the Wi-Fi connection in Blynk works. The Arduino with Wi-Fi adapter (or other MCU with built-in Wi-Fi) connects to your local (home) Wi-Fi system and talks via that to the Blynk server. Your Blynk app on your phone also talks to the Blynk server, via whatever connection is available to it (Mobile data, home Wi-Fi, other Wi-Fi) and controls the Arduino. This means that you can control your Arduino from anywhere ion the world, provided your home Wi-Fi is uo and your phone has internet connectivity.

You do need more control, to mirror the status change from your RF remote to your Blynk app in a meaningful way. Virtual pins give you that control, and remove any issues caused by your Arduino device wanting to set the state of certain pins at boot-up.

I think you’ll end-up realizing that this approach is a false economy. The value of serial debug information is priceless and I’m 100% sure that without it you’ll either abandon the project or eventually bite the bullet and buy a Mega.
Once the system is up and running as you want it then you could swap the Mega out and use the Uno, but developing blind without debug data is difficult enough for those of us who have been doing this for a while.

Good luck with that! If you find something better then please come back and share your findings, we’ve all done the same in the past and all ended-up here for a reason :wink:

Pete.