1

I can receive serial data from my phone but I can't send serial data to the arduino using bluetooth. I can see my input from serial monitor to my Android but not the other way. I'm using ARF7044A bluetooth module if that matters. Any help would be appreciated please.

Arduino to Android: Working
Android to Arduino: Not working.

Here is the wiring: enter image description here

Here is the code:

char state;
void setup()
{
pinMode(8, OUTPUT);
Serial.begin(9600);
}

void loop()
{

  if(Serial.available())
  {
    state = Serial.read();
    Serial.println(state);
  }
  if (state == 'a')
  {
    digitalWrite(8, HIGH);
  }
  else if(state == 'b')
  {
    digitalWrite(8,LOW);
  }
}
  • Please show us your wiring – chrisl Jun 8 '18 at 6:21
  • @chrisl Hi, I have added the wiring to the post. – Hanafi Mokhri Jun 8 '18 at 7:02
  • To me this looks like the same issue I encountered some time before. In my case the SPP-C bluetooth device was able to receive from my computer but the communication did not work the other way around. – Kwasmich Jun 8 '18 at 8:31
  • @Kwasmich hey thanks. I think my android phone might actually be the problem here. Brb gonna try another phone. – Hanafi Mokhri Jun 8 '18 at 8:34
  • On a second look: You also don't need a voltage divider on Uart_tx. The other one is fine because you want to use the Arduinos 5V TX pin on the 3.3V Uart_rx pin. But you already have a 3.3V output on your Uart_tx and then dividing it further down to 2.2V will be too low for the Arduino RX pin to recognize a signal. – Kwasmich Jun 8 '18 at 8:59
1

Your erroneous level shifting attempt from Bluetooth TX to Arduino RX is the root of your problem.

Pins 0 and 1 are also connected to the on-board USB interface chip via a pair of 1kΩ resistors. These resistors serve two purposes:

  1. To "weaken" the drive of the USB chip's UART interface (actually only needed on the USB chip's TX -> Arduino RX connection), and
  2. To protect both the USB chip and the main MCU from damage should two connected pins be set to opposing levels, which would cause high currents to flow through both output drivers.

The TX pin of the USB chip is actively driven HIGH all the time when idle (stupid design by Arduino, it should be Hi-Z when the port is not open), and the RX pin is pulled up by the internal pullup resistor in the USB chip. Further, when the Arduino's Serial is in use the TX pin of the Arduino is actively driven HIGH when idle (or LOW when transmitting a "1" bit).

The actual circuit you have looks more like this:

schematic

simulate this circuit – Schematic created using CircuitLab

Transmitting from the Arduino to the BT module is straight forward enough - the "high" point of the circuit is the Arduno's TX pin at 5V when idle. Current flows through R2 to the USB RX pin, and through R5 to the BT RX pin, with a portion split off to ground, which is what you want for your level shifting.

Communication in the other direction, however, is different, because you have two balanced "high" points in your circuit - one at the USB TX and one at the Bluetooth TX - and the fact you have 1kΩ resistors in both branches means that neither transmitter is "stronger" than the other. This means that when the BT TX is LOW (0V) you have around 2.5V at the Arduino RX pin (5V over two 1kΩ resistors = 2.5V in the center tap - see here).

Since 2.5V is neither within the Arduino's HIGH nor LOW voltage ranges (which are more than 3.5V for HIGH and less than 1.5V for LOW when running from 5V) the input is completely ignored.

The 3.3V transmitted by the Bluetooth module is a little under the official threshold for a HIGH signal on an Arduino, but in practice, it usually is detected fine. So remove the resistor network from the Bluetooth's TX pin and connect it directly to the Arduino. Since the input threshold voltage is a function of the supply voltage (0.7 * Vcc) it depends very much on your power supply as to whether it will work reliably or not. If you find it doesn't, you should use some upward level shifting. There are simple MOSFET based bi-directional level shifters available cheaply that are a better solution than resistors, and will allow proper operation in both directions, shifting a high voltage to a low one and a low voltage to a high one. These are good for lower frequency communications such as UART. If you should need higher frequency, or you find a simple MOSFET based shifter isn't working for you then a 74HCT08 or similar chip (be sure to use the HCT range not the HC range) or a dedicated level shifting chip may be in order.

-1

For a reliable solution you must move the Bluetooth device to pins other than digital 0 and 1 and use a software serial instance to communicate with it.

Digital pins 0 and 1 are for communication with the host computer, and the USB-serial chip is permanently wired to them, even if you are not trying to communicate with the computer.

There is on many boards a series resistor which allows an external circuit to overpower the USB-serial, but your mis-conceived level shifter has enough resistance itself that it is not able to do this.

Fortunately, while ill-conceived the level shifter is still wired with the idea that the Arduino side is the higher voltage one, so while it adds some load to the Bluetooth, it mostly just adds series resistance. If the Arduino pin were an ordinary high-impedance once, this would probably still work. But instead it is one which the USB-serial is trying to control through its own comparable value resistor, and the result is an invalid logic level or a tug-of-war which the USB-serial wins.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.