Bluetooth modules paired but not communicating

Hi,

I successfully configured two Bluetooth modules - one as “Mother” and the other as “Son”. The Mother is successfully sending a signal but the Son does not receive it (see picture attached). For the code, the Son’s LED is supposed to light when the Mothers touch sensor is pushed, here is my code:

//Code for Mother module//

#define motherLED 8
#define motherButton 7

int motherButtonVal = 0;
int wordfromSon = 0; //store data from son

void setup()
{
  /*pinMode(motherLED, OUTPUT);
    digitalWrite(motherLED, LOW);*/
  pinMode(motherButton, INPUT);
  //digitalWrite(motherButton, LOW);

  Serial.begin(9600); // Default baud rate of the Bluetooth module
  //9600??
}
void loop()
{
  delay(100);
  motherButtonVal = digitalRead(motherButton);
  
  if (motherButtonVal == HIGH) 
  {
    //Serial.print('1'); // Sends '1' to serialout
    Serial.write('1');
  }
  else 
  {
    //Serial.print('0');
    Serial.write('0');
  }
}
//Code for Son module//

#define ledPin 8
#define sonButton 7
int wordfromMother = 0;

void setup()
{
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  //pinMode(sonButton, INPUT);
  //digitalWrite(sonButton, LOW);

  Serial.begin(9600); // Default baud rate of the Bluetooth module
}void loop()
{
  Serial.println("Hellooo?");
  delay(2000);
  
  if (Serial.available() > 0)
  {
    // if data available at serial port
    wordfromMother = Serial.read(); // assign incoming data to variable state
    Serial.println("Word from mother is:");
    Serial.write(wordfromMother);


    // Controlling the LED
    if (wordfromMother == '1')
    {
      digitalWrite(ledPin, HIGH); // LED ON
      Serial.println("Word from mother = 1");
      delay(2000);
      wordfromMother = 0;
    }
    else if (wordfromMother == '0')
    {
      digitalWrite(ledPin, HIGH); // LED ON
      Serial.println("Word from mother = 0");
      wordfromMother = 0;
    }

 delay(10);
  }
  else
  {
    Serial.println("Serial not available");
  }
}

I have attached a picture of the output I am getting as well as the setup.

I switched RX and TX as I have seen in multiple places as should be done. I usually upload the Mother code first and then Son code after, and I am pretty sure I have a common ground set up too (see the picture attached). The Mother Bluetooth module and the touch sensor are on one Arduino Uno Wifi Rev 2 and the resistor, LED, and Son Bluetooth module are on another and each one is plugged into a USB port which are both then plugged into one laptop.

Please let me know if there is something I am missing. Thanks!!

You are sharing the hardware serial port between Bluetooth and serial monitor. It pains me to say this, but I suggest you move Blueteeth to software serial, leaving the serial monitor commands as they are.

Bluetooth Tx to Arduino Rx, and Arduino Tx to Bluetooth Rx. Anything else defies all logic, and should be contemptuously ignored until properly explained.

Hi!

Thanks so much for your reply. I am relatively new at Arduino - what exactly does it mean that I am "sharing the hardware serial port between Bluetooth and serial monitor"? What are the steps I need to take?

Thank you

Seems that the BT modules are powered from the 3.3volt pin of the Uno.

Did you see the writing on the back of them.
Power: 3.6volt-6volt.
So power them from the 5volt pin.

The RX pins of the modules should have 1k:2k voltage dividers.
Leo..

laine_o:

  • what exactly does it mean that I am “sharing the hardware serial port between Bluetooth and serial monitor”

In the absence of any “Serial1” commands, I assume you are using a plain vanilla Uno or the like.
Therefore your line

  Serial.begin(9600); // Default baud rate

implies you have Bluetooth on hardware serial, pins 0,1. The serial monitor and the pins 0,1 share the same UART. You may have already had grief trying to upload your programme while Bluetooth is connected, which is actually a confirmation of your problem.

Your picture suggests you are trying to communicate Serial monitor<>serial monitor. As an intellectual exercise, this is fine but you need separate communication channels for Bluetooth and Monitor, hence the software serial. You don’t mention which Arduino you are using, but your code is suss irrespective. There may be other options, depending on hardware. Software serial is a means of last resort.

Hi,

I have previously tried the voltage divider and running the BT modules on 5V but it didn't change anything. I have changed my wiring now to account for that but the problem is still there.

What other options do I have, considering that I need to control an LED on a different board with a button from one board?

Thank you all

The voltage divider goes on the Arduino Tx signal line and has nothing to do with powering the board. The divider is good practice, but I have never heard of anyone frying anything because it was omitted. I guess there is something very basic going on here so, if you are prepared to walk before you run, you have a phone, and can resist the urge to flash LEDs, you might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino