Thursday 25 October 2012

Installing and testing the JY-MCU BT chip (Arduino/Windows)

Today I started with connecting my JY-MCU Bluetooth chip to my Arduino UNO.
You can order these chips really cheap at ebay or DX.com.

I've bought mine at DX.com for only $8.60. They offer a serial Bluetooth (BT) connection within a small range. This is mostly enough for our basic connectivity projects.
Link to DX.com

Connecting to the Arduino and uploading the test sketch:

As you can see it offers limited pins: VCC, GND, TXD and RXD.

If you want to connect it to an Arduino you can do it like this:

5v Arduino -> VCC
GND Arduino-> GND
TX(1) Arduino -> RXD
RX(0) Arduino -> TXD




If you want to test the Bluetooth chip, you can upload this sketch to your Arduino:

char val; // variable to receive data from the serial port
int ledpin = 13; // Onboard LED

void setup() {

  pinMode(ledpin, OUTPUT);  // Onboard LED as OUTPUT
  Serial.begin(9600);       // start serial communication at 9600bps
}

void loop() {

  if( Serial.available() )       // if data is available to read
  {
    val = Serial.read();         // read it and store it in 'val'
  }
  if( val == 'H' )               // if 'H' was received
  {
    digitalWrite(ledpin, HIGH);  // turn ON the LED
  } else { 
    digitalWrite(ledpin, LOW);   // otherwise turn it OFF
  }
  delay(100);                    // wait 100ms for next reading
}


It's inspired on the blog from roboToSH, but with a small change.
It will trigger LED pin 13 to high when you send the character "H" with use of the serial line. If you use another character or value it will turn off.

Pair the BT chip with your PC:

For pairing your JY-MCU to your PC you need to have a Bluetooth USB stick or an embedded BT chip in your laptop or desktop to set up a connection. Pairing is pretty simple in Windows. Just enter the window of the Bluetooth devices and search for a new device. You can enter this Window by clicking the BT logo in your taskbar.


Note: If you're having problems with trying the following up solution. Scroll down and try the different solution! It seems that Windows sometimes has problems with pairing and setting up a com port. Before you start with the different solution you have to remove the existing "linvor"device from the system by right clicking the device.

If it works well you can now find the BT device "linvor". Click on this device and use the code 1234 to get access. Now you can find "linvor" in the devices window.



Testing the BT serial connection:

Testing the BT serial connection is very simple once you paired with "linvor". You can find out the right COM port when you right-click the "linvor" device in the window. Go to properties and search for the COM port number in the hardware tab.

Once you know the COM port number you have to start the Arduino IDE. After that you select the right COM port and you enter the serial monitor. Enter H in the command line. If everything works well you can see the LED near the "L" character on your Arduino turn on.

If the Arduino IDE is not able to find the right COM port you can follow solution 2 in order to set up the connection correctly or you can try to use PuTTY for the serial view. (See solution 2)



Solution 2:

In my case the first solution worked for about 20 seconds. After that the Arduino IDE finds only the wrong serial port and the connection becomes unstable. I think this has something to do with the way how Windows organizes setting up different serial ports. I invested over 5 hours to find this solution, that's why I want to share it with you. :)

First steps:
Hook up your Arduino like in the first solution. Upload the sketch and go to the add bluetooth device screen of windows.

Pairing:
Pairing is different in this solution. You have to pair without telling the password!

Okay, now is your device paired without the code. Good job! 

Viewing the serial monitor:
Even in this way it's still impossible to use the Arduino Serial Monitor. In this case you should try Putty. It was the only free program that did the job correctly for me.


You can download Putty here if you didn't already have it on your computer:

Now it's time to start Putty. You will get a login screen.

  • Select serial, enter the right COM port. (You can find it in the hardware tab of the properties of "linvor" in the device window of Windows)
  • Set the Boud rate to 115200
  • Click Open

If it works correctly a balloon in the corner of your screen will pop up and ask for the code that you didn't enter when pairing. Enter "1234". 

After this the "Putty terminal" will pop-up and you're able to send in commands. Press "H". You won't see anything happening on the screen. But the light of your UNO will turn on. If you press "L" the light will turn off.

Note:
  • Putty is also able to receive values like for instance from a sensor. You will see them correctly. Because the Putty terminal only displays what you get back over serial and not what you send. If you need to send a big message to the Arduino. Copy/paste it in the window.
  • In case of a connection your "linvor" LED will become a solid red colour, if there is no connection it will blink.

13 comments:

  1. Hello, I did everything as you did but it doesn't works, in Bluetooth devices I found two ports COM11 input linvor and COM9 input. I tried to use this ports but doesn't happens. What you think is the problem?
    I made the AT config baud rate 9600kbps.

    ReplyDelete
  2. Did you try the solution with putty? Otherwise deinstall the drivers, reboot and try again.

    ReplyDelete
  3. For me it worked very well.
    Thank you.

    ReplyDelete
  4. hye there
    can i use this module [JY-MCU] to comunicate with android app?
    for example turn on/off a led using android app?

    ReplyDelete
  5. @Imran3:
    This is possible since Android (and most android hardware) supports Serial Bluetooth. You can use a program like Blueterm (It's available in the Play store) so send commands to your arduino from a command line.

    You can also set up a GUI to organize this by making a real application with the Android SDK which sends the commands for you. There are a lot of tutorials available for this. Search for "bluetooth serial android" and you will find some. :)

    There is also an alternative available which uses Scripting Layer for Android and it allows you to make very fast a working "prototype application" with use of HTML/Javascript and Python. You can find a tutorial about this here:
    http://www.instructables.com/id/Androino-Talk-with-an-Arduino-from-your-Android-d/

    ReplyDelete
  6. Thank you for your manual!

    I did like what you wrote but it does not work. A error occurred during compiling process.

    avrdude: stk500_getsync(): not in sync: resp=0x00

    do you know what problem is? :)

    ReplyDelete
    Replies
    1. I didn't include the last curly bracket in the code. I've just added it, so now it should compile fine I think. Let me know if it works now. :)

      Delete
  7. Thank you for this useful and well done tutorial. One question: How do you enter in command mode to setup the BT module? I read what I could find and so far no luck to get in to cmd mode.

    ReplyDelete
    Replies
    1. Hi there.
      Thank you. I'm glad to hear that some people find this helpful.

      About your question.. I don't really understand what you mean. What do you want to achieve? I can't see the context of what you mean with cmd and command mode.

      Please let me know by replying this message. I'll answer your question asap!

      Delete
  8. I've had this board for a week and nothing I do gets it to work on the bluetooth side. The command mode works when it is not paired, but when paired it does absolutely nothing other than turning the led from red flashing to red solid.

    ReplyDelete
    Replies
    1. A solid red LED color means that the Bluetooth module is paired with your device. After that the devices passes through your commands over the TX and RX pin. When it blinks its just waiting for pairing, so it should also not accept any commands since you have no connection.

      Are you using a windows pc? Sometimes these give problems. Try it with an Android Smartphone and it will probably work within seconds! :)

      Delete
  9. Thanks so much for this guide! I initially also followed the one on roboToSH and was frustrated with it not working. Yours worked like a charm. Cheers!

    ReplyDelete
  10. Your tutorial worked greatly for me.What I do not understand is all those forum questions on AT commands. I am a beginner with Arduinos' and am just trying to make my JY-MCU send and receive some serial data and display it in putty.I just can't seem to get those AT command tutorials working.Should I even bother about changing the baud rate on the module? This is as its already set at a default rate of 9600.

    ReplyDelete