Hello!
I have an Arduino Mega 2560, with a ZS-040 Bluetooth module, that is wired like this:
Bluetooth RX -> RX15
Bluetooth TX -> TX14
Bluetooth GND -> GND
Bluetooth VCC -> 5V
My goal is to connect the Arduino to my iPhone, and be able to send and receive data from both devices. I'm also using the LightBlue app, to test and connect to the Arduino.
My problem is that I can't manage to send data to the Arduino from the iPhone, even using the writing functionality from LightBlue and sending data to the "TX & RX" service. I have a very simple code, setup to print anything it receives, but it just won't print anything.
I also tried printing the input from the device, even if it isn't available, but it just spams -1 in the Serial Monitor.
Here is the code:
#include <SoftwareSerial.h>
SoftwareSerial BLE(14, 15);
void setup() {
Serial.begin(38400);
BLE.begin(9600);
Serial.println("Done doing setup");
}
void loop() {
if (BLE.available())
Serial.print(BLE.read());
}
Any help would be useful!
I also have a Wifi module, so if you think its easier to do it through Wifi, I can change and try something else.
Thanks!
On the Mega, you should be using hardware Serial3 (instead of software serial) for pins 14 and 15.
Bluetooth RX -> RX15
Bluetooth TX -> TX14
The connections between the BLE module and the Arduino should be crossed Tx>Rx and Rx>Tx.
cattledog:
On the Mega, you should be using hardware Serial3 (instead of software serial) for pins 14 and 15.
Am I supposed to change the SoftwareSerial import to Serial3? Because this file doesn't seem to exist. Otherwise I can just try changing RX and TX to 16/17, it isn't a problem!
cattledog:
The connections between the BLE module and the Arduino should be crossed Tx>Rx and Rx>Tx.
Okay I'll do it thanks!
So right now I have:
Bluetooth RX -> TX2 16
Bluetooth TX -> RX2 17
Bluetooth GND -> GND
Bluetooth VCC -> 5V
#include <SoftwareSerial.h>
SoftwareSerial BLE(16, 17);
void setup() {
Serial.begin(38400);
BLE.begin(9600);
Serial.println("Done doing setup");
}
void loop() {
if (BLE.available())
Serial.print(BLE.read());
}
And still not receiving anything 
Am I supposed to change the SoftwareSerial import to Serial3? Because this file doesn't seem to exist.
Hardware serial is far superior to software serial. It is more reliable and uses less resources. and one of the great advantages of the Mega is the additional hardware serial ports. Use them. If you wish to use pins 16 and 17, that is Serial2.
From the Arduino Reference on Serial
The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.
You use Serial3.begin() to initiate the channel.
void setup() {
Serial.begin(38400);
Serial3.begin(9600);
Serial.println("Done doing setup");
}
void loop() {
if (Serial3.available())
Serial.print(Serial3.read());
}
You still did not get the software serial connections correct in your last effort.
SoftwareSerial BLE(16, 17);
Bluetooth RX -> TX2 16
Bluetooth TX -> RX2 17
The Software Serial constructor pin listing is in the order RX,TX so you have not connected the module with tx>rx and rx.tx.
Bluetooth RX -> TX2 16
Bluetooth TX -> RX2 17
Oh wow it works! Thanks so much 
In case someone has the same problem, here is the solution:
Wiring:
Bluetooth RX -> TX2 16
Bluetooth TX -> RX2 17
void setup() {
Serial.begin(38400);
Serial2.begin(9600);
Serial.println("Done doing setup");
}
void loop() {
if (Serial2.available()) {
Serial.print("Received: ");
Serial.println(Serial2.read());
}
}