Search This Blog

Saturday 17 November 2012

JY MCU Bluetooth Module

Hello!!

Today I'm speaking about the JY MCU Bluetooth Module which I bought several days ago in Deal Extreme. It's a good and cheap option and almost a plug and play device to play with wireless connections using your Arduino.


JY MCU Bluetooth Module

Wiring:

It's very easy. You only have to connect four pins (TX, RX, VCC and GND) in this way:

TX BT Module ------------------> RX Pin Arduino
RX BT Module ------------------> TX Pin Arduino
VCC BT Module <---------------> 3,3V Pin Arduino
GND BT Module <---------------> GND Pin Arduino

JY MCU Bluetooth Module Test Assembly



Testing:

Well, we have our Arduino and our BT Module connected. Remember, I didn't configure anything in our BT Module (the Settings can be configured but now we are going to work with default settings)... but Now we need another device that will connect with our Arduino Nano. In this case, I have used my Android Mobile running a classic BT App (this make it possible to connect and send/receive basic strings that will be interpreted by the embedded software of our Arduino).

The App is Amarino 2.0:



Here, we can send and receive basic strings to our connected device (it connects directly, the default PIN Code is 1234, and de baudrate is 9600)... but We need to do something with de data sent by the mobile, so we need the Arduino Code.


Code:

I have done a basic programme with the following features:

  • If I send the number "1" the led switchs on.
  • If I send the number "2" the led switchs off.
  • If I send the number "3" the led blinks once.

And the code is:


char lecturaSerie = Serial.read();
int led = 13;

void setup() {                

  pinMode(led, OUTPUT);  
  Serial.begin(9600);
}

void loop() {
  if( Serial.available() )       // if data is available to read
  {
    lecturaSerie = Serial.read();         // read it and store it in 'val'
  }
  if ( lecturaSerie == '1' )
  {
  digitalWrite(led, HIGH);   // set the LED on
  }
  if ( lecturaSerie == '2' )
  {
  digitalWrite(led, LOW);   // set the LED on
  }
  if ( lecturaSerie == '3' )
  {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  }
  
  delay(100);                    // wait 100ms for next reading
}



Note: To upload the code to the Arduino you need to disconnect the BT Module. 
Note2: When your BT Device isn't connected, a red led will be blinking, and if it's "pair" this led will be swiched on.




See you!!


No comments:

Post a Comment