Pages

07 July, 2012

Arduino - JY-MCU Bluetooth


A while back I got a package from Dealextreme with a JY-MCU Arduino Bluetooth Wireless Serial Port Module. This bluetooth device is both cheap and easy to use, and I will now show you how to get it up and running. Later on I will show you how to wirelessly control your lamps using your computer or android device.

Specifications
Dimensions: 4.4 cm x 1.6 cm x 0.7 cm (1.73 in x 0.63 in x 0.28 in)
Weight: 7g (0.25 oz)
Range: ~10 m (~33 ft)
Supply voltage: 3.6-6V
BT-Name: linvor
BT-Pin: 1234
BT-Baudrate: 9600bps (standard)

Before connecting it to your Arduino
Before you hook it up to your Arduino, you should upload your the code you want to use. This is because your bluetooth device will be connected to both the RX and the TX pin of your Arduino, and while it is connected, you will not be able to upload new code using USB. Here is the code I used, I got it from arduino.cc.

char val; // variable to receive data from the serial port
int ledpin = 8; // LED connected to pin 48 (on-board LED)

void setup() {

  pinMode(ledpin, OUTPUT);  // pin 48 (on-board 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
} 
 
Connecting the bluetooth module to an Arduino Uno
The bluetooth module is marked underneath with names of the six different pins. Even though there are six pins, you only need to hook up four of them. GND is of course connected to GND on your Arduino, and the VCC pin can be connected to either 3.3V or 5V. In this example we will be using 5V. Now there are to pins left to connect, the RXD and the TXD. The RXD on our bluetooth module will be connected to TX (digital pin 1) on the Arduino board. The TXD on our bluetooth module will be connected to RX (digital pin 0) on on the Arduino board.

You should also try to connect an LED with a 220Ω resistor in serial, between pin 8 and GND. This is just to indicate whether the bluetooth communication is working or not. You can now power on your Arduino.

Pairing with your computer
Now it's time to turn on bluetooth on your computer, or simply plug in your bluetooth USB stick. After doing so, you should get a bluetooth-sign on the right side of your taskbar. Right click on it, and then choose "Add a Device". Find "linvor" and follow the wizard until your devices are paired. If you are asked for a pin or a password, it will be "1234".

Test it!
To test if it all work, you should first find out which COM port the device is connected to. To do so, you simply double click the bluetooth sign on the taskbar, right click on linvor, select "Properties", and go to the "Hardware" tab. There you will find som text ending with "COM8", or whatever COM you are using. Now open the Arduino program, click on "Tools" and then choose the right serial port. You are now ready to open the "Serial Monitor" (magnifying glass in the upper right corner). Be sure to have the right baudrate selected (9600bps), and then try to write capital "H" or capital "L" in the textbox. Hit "Enter" or the Send-button and watch your LED blink.

Want to take it further? Control your lamps using a PC or your Android phone!

41 comments:

  1. Hi I have the same bluetooth control.I understamnd software but not hardware! Now what I am concerned about is the connection
    The instructables below claims a levelshifter is required ... ???http://www.instructables.com/id/Use-your-android-phone-sensors-on-the-arduino-/step3/The-level-shifter/

    ReplyDelete
    Replies
    1. As I stated in the specifications section, the hardware allows us to use a supply voltage from 3.6V up to 6V. Therefore you should be totally fine without a levelshifter.

      Delete
  2. after connecting the serial monitor to the coms port, i tried to type the command into the Serial monitor, but the whole thing hung. why is this so? thanks

    ReplyDelete
    Replies
    1. Are you sure you used capital letters?

      Delete
  3. Hi, ToSH!
    It's very useful information.
    Many thanks!
    Ming

    ReplyDelete
  4. Where did you get the Frizting part for this?

    ReplyDelete
    Replies
    1. I do not use Fritzing. All my images are created using Photoshop.

      Delete
    2. I had the same question today too Matt. Eventually found one here:
      https://github.com/RafaGS/Fritzing/blob/master/Bluetooth%20HC-06.fzpz

      Delete
  5. The Arduino's RX/TX lines are TTL 5v and the JY-MCU (BT) is 3.3V,
    i guess that TX(BT)3.3v-->RX(Arduino)5v will work, but about the other wayaround the TX(Arduino)5v -->RX(BT)3.3v?
    whould i need to use a voltage divider or a two diodes in a row?

    Thanks

    ReplyDelete
    Replies
    1. I don't use any of that, but it seems to be working fine anyway. Hook it up like the image shows, and you should be good to go. I'm not sure, but there might just be a voltage divider somewhere onboard the JY-MCU PCB.

      Delete
  6. Thanks, it works perfectly.

    ReplyDelete
  7. How can i use more variables, to control 4 outputs?
    Im not so good with software.


    Tnx

    ReplyDelete
    Replies
    1. I have not tested it yet, but I believe something like this should work.

      char val; // variable to receive data from the serial port
      int pin4 = 4;
      int pin5 = 5;
      int pin6 = 6;
      int pin7 = 7;

      void setup() {

      pinMode(pin4, OUTPUT); // pin 4 as OUTPUT
      pinMode(pin5, OUTPUT); // pin 5 as OUTPUT
      pinMode(pin6, OUTPUT); // pin 6 as OUTPUT
      pinMode(pin7, OUTPUT); // pin 7 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 == 'A' ) // if 'A' was received
      {
      digitalWrite(pin4, HIGH); // set pin 4 HIGH
      }
      else if (val == 'a') { // if 'a' was received
      digitalWrite(pin4, LOW); // set pin 4 LOW
      }
      if( val == 'B' ) // if 'B' was received
      {
      digitalWrite(pin5, HIGH); // set pin 5 HIGH
      }
      else if (val == 'b') { // if 'b' was received
      digitalWrite(pin5, LOW); // set pin 5 LOW
      }
      if( val == 'C' ) // if 'C' was received
      {
      digitalWrite(pin6, HIGH); // set pin 6 HIGH
      }
      else if (val == 'c') { // if 'c' was received
      digitalWrite(pin6, LOW); // set pin 6 LOW
      }
      if( val == 'D' ) // if 'D' was received
      {
      digitalWrite(pin7, HIGH); // set pin 7 HIGH
      }
      else if (val == 'd') { // if 'd' was received
      digitalWrite(pin7, LOW); // set pin 7 LOW
      }
      delay(100); // wait 100ms for next reading
      }

      Delete
    2. Thanks, that should help alot!

      Cheers

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Thank you for this clear tutorial. I did not try, because I am new to Arduino, and I have a question: How do you upload back another program, e.g. the blink program, once you don't want to use the bluetooth device anymore? Do you only have to remove the leads to the bluetooth card, and put back in the USB plug and you would be able to use your Arduino with your PC like before? Do you have to press the reset button on the Arduino?

    ReplyDelete
    Replies
    1. All you need to do is to unplug the RX and TX cables,and you can use the USB again.

      Delete
  10. It's an interesting project, I'll try! But I have two questions: 1. To put a LED with resistor should be between GND and VCC or GND? 2. What software you use yo create dragrams like arduino, bluetooth module and your connections?

    Regards.

    ReplyDelete
    Replies
    1. A LED with a resistor should be connected like this (http://arduino.cc/en/uploads/Tutorial/ExampleCircuit_bb.png), but use pin 8 not 13, or you will have to make changes to the code.

      I use the Arduino software (http://arduino.cc/en/Main/Software) to program the Arduino, and Photoshop to make images of it.

      Delete
  11. Hi, I can't get this working, and I wonder if you can help me.

    I have a Belkin F8T013 dongle on my Vista, and the JY-MCU hooked to an Uno as shown above. The LED on the MCU flashes constantly, and my PC can see the Linvor. Right clicking it and selecting Properties brings up a dialogue but there is no hardware tab you mention - just General and Services (which is an empty list, by the way).

    However, if I click the Bluetooth Setting at the top of the window, I get the Bluetooth Radio Properties and there is a COM Ports tab there. Clicking it shows two or sometimes three COM ports for the Linvor. They are labelled "Incoming", "Incoming Linvor" and (when present) Linvor Outgoing". Slecting any of these causes the same behaviour. The Arduino IDE becomes very slow. I can eventually get a Serial window up and type "H" but nothing happens on the Arduino and after that I have to kill the Arduino task on the PC to try again.

    Any ideas?

    Many thanks,
    Chris

    ReplyDelete
    Replies
    1. Hi. I'm sorry I didn't reply earlier. Using another computer I encountered a similar problem. I'm trying to figure it out, and I will let you know if I find a solution.

      Delete
    2. After some research I have come to the conclusion that the described problem only occurs on Windows. Some say that it has something to do with the Windows 7 platform, and that XP should work fine.

      I have tried it on my Mac running OSX, and it works great. But when I do the same using Windows 7, on the same Mac, the problem occurs. Using my Android phone to turn the LED on and off also works fine.

      Delete
  12. I should have said that when there are three ports, the Services tag lists one service: "Serial port (SPP) 'Dev B' on COM24" for the Linvor, but the Arduino IDE does not list this port among those available, so I cannot select it.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. This device won't work for me. The command mode works fine, but as soon as I pair it, it stops communicating. Nothing gets through in Bluetooth mode.

    ReplyDelete
    Replies
    1. make u sure that for bt module refference voltage is 3.3 v
      correct it then its work properly.

      Delete
  15. I have the same problem as Chris Wesley does, the Arduino's IDE starts to hang whenever I try to send any commands and it also doesn't recognize the serial port despite the fact that my computer shows the connection.

    ReplyDelete
  16. Awesome stuff, well done :)

    ReplyDelete
  17. This is nice you have clearly demonstrated the Bluetooth module connection through six different pins.

    ReplyDelete
  18. Have you tried it with http://arduino.cc/en/Reference/SoftwareSerial ?

    ReplyDelete
  19. thanks for the tutorial, but I have a problem! I managed to pair it with my mac, but when I try to launch the serial monitor, I got an error saying that the serial port already in use. I am pretty sure it is not in use..... any idea what may have gone wrong?

    ReplyDelete
    Replies
    1. I'm sorry, I don't know. Have you tried to unpair it, restart your Mac, and pair it again?

      Delete
  20. Great Tutorial! Worked from the start

    ReplyDelete
  21. Guys,
    It worked for me according the tutorial, but I have some other questions,
    1) Currently you have defined PIN8 as output. What if I want Pin7 to be as Input? do I have to add //
    ...
    int ledpinIn = 7; // Function Generator with TTL leveled pulses into pin7
    void setup() {
    pinMode(ledpinIn, INPUT);
    ...//
    Will this then indicates a string reading out on my PC?
    2) How does RX/TX on the Arduino navigates the In-Outputs, in which Pins and at which protocol languages? Does simply a "HIGH" stands for TTL-Level high (>1.4 V) and a "LOW" for a TTL level Low (< 1.2 V).
    I am rather programming in LabView and it worked there too, but this is only due to the first program of yours burned on the Arduino....
    Any comment would be nice to share

    ReplyDelete
  22. Hello,
    I'm having trouble with the JY-MCU. I have hooked it up to a PICKit2 UART tool and paired and established a BT-connection between the JY-MCU and a smartphone using a SPP-terminal. Now, I can send messages from the UART tool (via the JY-MCU) to the smartphone. But I can't send messages from the smartphon to the URT tool. I've hooked up the TXD pin to a scope and it's clear thet the unit won't transmit anything. I've tried the same setup with another JY-MCU and it behaives in the same way. I've also used the same setup with other BT-modules and they work just fine.
    What am I doing wrong here!? Is there a hardware flowcontrol that shuld be pulled high or do need to change some settings (AT)?!?!
    Thanks,
    /Swede

    ReplyDelete
  23. hi everyone i wonder if it's possible to send an information to a blutooth speaker

    phone ==> arduino ==> speaker

    don't ask me why i won't explain !

    ReplyDelete
  24. The bluetooth module turns off as soon as I pair with it...Can u explain ...why?

    ReplyDelete