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!
pd: the module works perfectly with Arduino Uno by using the same first code!