Problems with Jy-mcu module

Guys, I got my Arduino pro micro connected to jy-mcu (1.06).
Arduino pro micro I have=>

And this are the connections I made.

Pro micro || Jy-mcu module

Vcc------>5v->Vcc
GND---------->GND
Tx------------>Rx
Rx------------>Tx

I'm trying to turn on/off a led connected to Arduino pin 3 by sending 1 to turn it on and 0 to turn it off. I'm using a terminal Bluetooth simple app, that can send an string to a Bluetooth device.
This is the code I'm using:

char c;
int ledPin = 3;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);

}

void loop() {

  while (Serial.available()) {
    delay(3);
    c = Serial.read();
    readString += c;
  }

  if (readString.length() > 0) {
    Serial.println(readString);

    if (readString.indexOf('1') >= 0)
    {
      digitalWrite(ledPin, HIGH);
    }

    if (readString.indexOf('0') >= 0)
    {
      digitalWrite(ledPin, LOW);
    }

    readString = "";
  }
}

As I upload it, I opened serial monitor just to verify that the code works, and the led by sending a 1 turns on. It worked. So here is my question, why when I send data via Bluetooth, the arduino don't turn the led on??
Then I searched and I found that arduino pro micro works as a leonardo, and i need to do something with a "serial1", anyone can tell me if this is correct? should I add this to my code?

since I have known that about leonardo, I tried to upload this code:

char c;
int ledPin = 3;
String readString;

void setup() {
  Serial1.begin(9600);
  pinMode(ledPin, OUTPUT);

}

void loop() {

  while (Serial1.available()) {
    delay(3);
    c = Serial1.read();
    readString += c;
  }

  if (readString.length() > 0) {
   

    if (readString.indexOf('1') >= 0)
    {
      digitalWrite(ledPin, HIGH);
    }

    if (readString.indexOf('0') >= 0)
    {
      digitalWrite(ledPin, LOW);
    }

    readString = "";
  }
}

You can see that its the same code but with serial1 instead.
And I do the same as before, but this time, obviously the serial monitor didn't turn on the led because its not declared, but serial1 shall open it by sending data with the Bluetooth terminal, it doesn't!!!

Where is the issue ? there is a way to code it better? to make it work??

I'm not moving from pc without a solution, ask me if you have any questions about this problem and just try to help me, I will answer whatever you need! :smiley:

pd: the module works perfectly with Arduino Uno by using the same first code!

String readString;

What a waste of resources to read "0" or "1".

why when I send data via Bluetooth, the arduino don't turn the led on??

Lots of possible reasons. The bluetooth device might not be paired. It might be operating at a different baud rate, the sending app might not be working...

Get the bluetooth device off the hardware serial port, so you can debug.

You can see that its the same code but with serial1 added.

"Used instead", not "added". Why not use Serial to give yourself a clue?

Why not use Serial to give yourself a clue?

HOW?

Lots of possible reasons. The bluetooth device might not be paired. It might be operating at a different baud rate, the sending app might not be working...

Think about it works nicely on arduino uno, the app works good!

I'm sorry for making that waste of resources, but by making the code this way->

int c = 0;
void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
}
void loop() {
  while (Serial.available()) {
    delay(3);
    c = Serial.read();
  }
  if (c == '0')
  {
    digitalWrite(3, LOW);
  }
  if (c == 1)
  {
    digitalWrite(3, HIGH);
  }
}

it doesn't work.
any other suggestion ? :3

ArroyoBrothers:
pd: the module works perfectly with Arduino Uno by using the same first code!

Tell us how the module was connected to the UNO when the code worked.

My sense is that the second code (with Serial1) should work.

If the module was connected to pins 0 and 1 on the Uno (which are also the pins used by the Serial Monitor) it is hard to know what might have been happening. It would be better to use SoftwareSerial on an Uno to create a separate serial connection for your module. Then you could get your program to show on the Serial Monitor what was being received from the module.

Have a look at the examples in Serial Input Basics - they are simple and reliable ways to receive serial data.

...R

HOW?

Serial.println("This project is WAY beyond my capabilities now");

Do not cross-post. Other thread removed.

Tell us how the module was connected to the UNO when the code worked.

The module was connected the same way(module tx to arduino rx and rx of module to arduino tx), and as I sent a 1 with the pc serial, on the app, I could see the 1 on the terminal (inside the app), and the led turned on the same time.
I will try to change the serial port of Arduino as you said. Gonna tell you something soon!
Thanks for answering this post and been compressive with me, I’m very noob at communication with the serial :S

OKAY! Robin2, I used this code on arduino uno:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

And when I opened serial monitor on pc, as code defines, arduino sends to the bluetooth module (hello, world?)and appears on the app the same text! inside the serial monitor on pc you can see the text (goodnight moon!). So it worked, any suggestion for leonardo(pro micro)??

Now I’m really fed up… (I’m using arduino micro pro)

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
void setup() {
  mySerial.begin(9600);
  mySerial.println("Hello, world?");//Here the code sends hello word to app and I check it , all good.
  if (!mySerial.available()) {
    delay(100);
  }
}
void loop() { // run over and over
  if (mySerial.available()) {
    mySerial.println("SerialProvisional.Avaliable Works!");
    delay(10);
  }
  if (mySerial.read() == '1') {
    mySerial.println("SerialProvisional.READ Works!");
    delay(10);
  }
}

mySerial never is available now! help?

note: I can suppose that Tx serial works nicely, but rx don’t because as I send data via the app, it doesn’t work.
Rx serial its good connected and I tryed to connect it to another pin, nothing…

Did you try the first (working) code on the pro Micro ?

If you change more thanone thing at a time you just get into a mess.

What is the Bluetooth device paired with ?

...R

Yes I did, and it doesn't work. I think that its better to change the serial port of my arduino pro micro as i did before, taking the pins 8/5 and making them the rx and tx(8-rx,5-tx) .Now the problem is that I can send text and data (arduino-Mobile) but I cant recive data from the mobile app!
The bluetooth is paired with my phone(lg g3), it's correctly paired.

ArroyoBrothers:
I think that its better to change the serial port of my arduino pro micro as i did before, taking the pins 8/5 and making them the rx and tx(8-rx,5-tx)

What evidence do you have to support that ?

Have you tried pins 8 and 5 on the Uno ?

...R

I played around with Software Serial library, and I conclude that my Arduino micro pro ports 1 and 0 were busy because of serial pc communication, so I changed them to make thinks easier… now I’m trying to send data with my phone and get it with my Arduino, but it doesn’t work! I tried those pins on my Arduino uno, and the hole think worked, I could make a nice communication between Arduino and my phone. I think the problem is on the rx port on my Arduino pro micro because it doesn’t get any info! I changed it lots of times with Software Serial library, and it keep been like closed :frowning:
So, what should I do now to communicate my phone with my pro micro?
this is the code I’m running now on pro micro to test if the comincation between arduino and my phone works, and it does!:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 8); // RX, TX
char c;
void setup() {
  mySerial.begin(9600);
  if (!mySerial.available()) {
    delay(10);
  }
  mySerial.println("Hello, world?");
}
void loop() { // run over and over
  mySerial.println("SerialProvisional.READ Works!");
}

If I try the same but making a mySerial.read in a good way, the arduino is not able to READ it :S

pd: I am grateful for your attention&cooperation, thank you very much!

ArroyoBrothers:
I played around with Software Serial library, and I conclude that my Arduino micro pro ports 1 and 0 were busy because of serial pc communication,

This is very true but what has it got to do with your decision to use pins 10 and 11 on your Uno and pins 8 and 5 on your Micro.

In Reply #7 you posted this code

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

and you said it works on your Uno.

IMHO that code should work on the Micro. If you want my assistance, let’s just focus on getting that to work.

Start by getting it going on your Uno and telling me step by step what happens on your PC and on your phone when it works. Make a pencil drawing showing how everything is connected to the Uno and post a photo of the drawing.

When you have done both of those we can move on to the Micro.

…R