Issue with Serial Comm HC-05 - Uno Rev 4 wifi

Using Bluetooth RC car app in effort to control Uno rev4 wifi w/8channel relay module to control 12 vdc ebike motor powered yard wagon with on board 12v battery and relays for isolation . My Android phone pairs with HC-05 module OK but no serial activity when pushing any of the control buttons on phone . I have already run this setup using an Uno rev 3 with an Adafruit motor shield controlling 4 relays but I would like to use 8 relays instead to utilize all 8 of the RC car app buttons . Here is my code below . It compiles OK but says it can't locate IRremote.h header files ? My other setup with the Uno rev3 /motor shield used the <AFMotor.h> and communicated just fine
Not sure about the RingBuffer.h this pops up everytime I have included SoftwareSerial.h leading me to believe maybe it also has to be included.



#include <RingBuffer.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(3,2);


char t;
 
#define relay1 13
#define relay2 12
#define relay3 11
#define relay4 10
#define relay5 9
#define relay6 8
#define relay7 7
#define relay8 6


void setup() 
{

Serial.begin(9600); 
bluetooth.begin(9600); 
pinMode(relay1,OUTPUT);   //motor forward
pinMode(relay2,OUTPUT);   //motor reverse
pinMode(relay3,OUTPUT);   //steer left 
pinMode(relay4,OUTPUT);   //steer right 
pinMode(relay5,OUTPUT);   //headlight button = controller slow speed
pinMode(relay6,OUTPUT);   //taillight button = controller medium speed
pinMode(relay7,OUTPUT);   //horn button = controller fast speed
pinMode(relay8,OUTPUT);   // spare? 
 
}
 
void loop() {
if(bluetooth.available()>0)
{
  t = bluetooth.read();
  Serial.println(t);
}
 
if(t == 'F'){                      //move  forward(motor rotates in forward direction) relay module require reverse logic to assert relay
  digitalWrite(relay1,LOW);
} 
 
if (t == 'B'){digitalWrite(relay2,LOW);  //move reverse direction (motor rotates in reverse direction )
}  
  
 if(t == 'L'){                         //turn left -actuator steers left
  digitalWrite(relay3,LOW);
}
 
 if(t ==  'R'){                       // turn right - actuator steers right
  digitalWrite(relay4,LOW);
}

  if(t == 'W'){                //headlights "ON " (motor controller to second speed step)
   digitalWrite(relay5,LOW);
}

else if(t ==  'w'){           // headlights "OFF" (motor controller back to crawl speed )
  digitalWrite(relay5,HIGH);
}
   if(t == 'U'){                    //backlights "ON"  ( motor controller to 3rd speed step)
  digitalWrite(relay6,LOW);
}

else if(t == 'u'){          //backlights "OFF" (motor controller back to 2nd speed step )
  digitalWrite(relay6,HIGH);
}

if (t == 'V'){                 // horn "ON" (motor controller on 4th speed step)
  digitalWrite(relay7,LOW);
}

else if(t ==  'v'){                                   //  horn "OFF" (motor controller back to 3rd speed step ) 
  digitalWrite(relay7,HIGH);
}

if(t ==  'X'){                                 //turn hazard on or off) spare contact
  digitalWrite(relay8,LOW);
}
else if(t == 'x'){
  digitalWrite(relay8,HIGH);
}
 
else if(t == 'S'){              //STOP (all momentary outputs stop)reverse logic due to relay module (-) to operate
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
}
delay(100);
}
void loop() {
if(bluetooth.available()>0)
{
  t = bluetooth.read(); // single-character variable names are BAD
  Serial.println(t);
  tryDecoding();
}

void tryDecoding ()
{
  if(t == 'F')
  {                      
    digitalWrite(relay1,LOW);
    delay(100);
    digitalWrite(relay1, HIGH);
  } 
 
  if (t == 'B')
  {
    digitalWrite(relay2,LOW);
    delay(100);
    digitalWrite(relay2, HIGH);
  }
}  

Thanks for the response . I changed my code to Switch case and fixed some errors that were not working and then sent/verified all of the commands using Serial Monitor. All of the outputs responded as desired proving the code. The problem I am having now involves lack of serial communication with the HC-05 Bluetooth module . BT Module works fine with a couple of other working projects that are using the <AFMotor.h> library . I tried using my original code with the SerialSoftware library but that did not seem to work so I disabled it .
I tried setting the baud rate up to 38400 from the original 9600 to no avail .
I am probably missing some simple ???

here is my revised code :

[code]

//#include <SoftwareSerial.h> // disabled to testing bluetooth serial comm problem
//SoftwareSerial bluetooth(3,2);

char command;

#define relay1 13
#define relay2 12
#define relay3 11
#define relay4 10
#define relay5 9
#define relay6 8
#define relay7 7
#define relay8 6

void setup()
{

Serial.begin(9600);

pinMode(relay1,OUTPUT); //motor forward
pinMode(relay2,OUTPUT); //motor reverse
pinMode(relay3,OUTPUT); //steer left
pinMode(relay4,OUTPUT); //steer right
pinMode(relay5,OUTPUT); //headlight button = controller slow speed
pinMode(relay6,OUTPUT); //taillight button = controller medium speed
pinMode(relay7,OUTPUT); //horn button = controller fast speed
pinMode(relay8,OUTPUT); // spare?

while(!Serial);{ //added for test
}
Serial.println("Serial link established."); //added for test
}

void loop() {
//if(Serial.available()>0); // disabled for test
if(Serial.available()){
command = Serial.read();
if(command == '1')
Serial.write("on");
else if (command == '0')
Serial.write("off");}

{
command = Serial.read();
Serial.println(command);

digitalWrite(relay1,HIGH); // relay modules require 0 volt LOW signal on individual relay input pins to activate relays
digitalWrite(relay2,HIGH); // this requires signals on these inputs to be normally HIGH forcing relays off until desired
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);

}

switch (command)
{
case 'F':{
digitalWrite(relay1,LOW); //move forward
delay(10);}
break;
case 'B':{
digitalWrite(relay2,LOW); //move backward
delay(10);}
break;
case'L':{
digitalWrite(relay3,LOW); //turn left
delay(10);}
break;
case 'R':{
digitalWrite(relay4,LOW); //turn right
delay(10);}
break;
case 'G':{
digitalWrite(relay1,LOW);
digitalWrite(relay3,LOW); //move forward left
delay(10);}
break;
case 'I': { //move forward right
digitalWrite(relay1,LOW);
digitalWrite(relay4,LOW);
delay(10);}
break;
case'H': { // move backward left
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
delay(10);}
break;
case 'J':{ //move backward right
digitalWrite(relay2,LOW);
digitalWrite(relay4,LOW);
delay(10);}
break;

    case 'W':{
      digitalWrite(relay5,LOW);}
         break;                                //headlights  ON

    case 'w':{  
      digitalWrite(relay5,HIGH);}              //headlights OFF
         break;
    
    case 'U':{
     digitalWrite(relay6,LOW);}           //tail lights ON
          break;
   
    case 'u': {
      digitalWrite(relay6,HIGH); }        //tail lights OFF
           break;
           
    case 'V': {
      digitalWrite(relay7,LOW); }           // horn ON
           break;
    
    case 'v': {                              //horn OFF
      digitalWrite(relay7,HIGH); }
            break;
            
    case 'X': {
      digitalWrite(relay8,LOW); }           //hazard ON
            break;
    
     case 'x': {
      digitalWrite(relay8,HIGH); }      //hazard OFF
           break;

}

       delay(100);

}

[/code] Thanks

uno   bt
tx    rx
rx    tx
gnd gnd

is it?

It's easier to figure things out by trying to do one simple thing first.

I'm not familiar with the R4 and can't check now. It's possible that the TX and RX pins are actually Serial1. So if the HC05 is connected to those pins, try Serial1 instead of Serial.

I saw this, but it didn't sink in that it was 'commented out' --

So, assuming 0, 1 are going to the HC05, those comms should be Serial1 - and any interaction with SerialMon are via Serial

Yes I am using Digital pins 0 and 1 for the Serial

I fixed the code to reflect Serial1 and was able to pair my phone with the HC-05 module at long last but had no response to the commands from my Phone .
Restored the original Serial code I started out with and everything is working now . Thank you both very much for the help ...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.