(RE-OPENED) Arduino + Bluetooth communitaction

Hello, This is my first post here, and well, I need help, this is the first time that I work with an arduino...

I have this code:

char val; // variable to receive data from the serial port
int rxd = 2;
int txd = 3;
int oPin = 4;
int oPin2 = 5;
int cPin = 6;
int cPin2 = 7;
int alOn = 8;
int isOpen = 9;
int isClosed = 10;
char abierto;
char cerrado;


void setup() {
  pinMode(rxd,INPUT);
  pinMode(txd,OUTPUT);
  pinMode(oPin, OUTPUT);  // pin1 para abir salida
  pinMode(oPin2, OUTPUT); //pin2 para abrir salida
  pinMode(cPin, OUTPUT);  // pin1 para cerrar salida
  pinMode(cPin2, OUTPUT); // pin2 para cerrar salida
  pinMode(alOn, OUTPUT); // siempre prendido
  pinMode(isOpen, INPUT); //pin para saber si esta abierto Entrada
  pinMode(isClosed, INPUT); // para para saber si esta cerrado Entrada
 
  Serial.begin(9600);  // start serial communication at 9600bps
 
}

void loop() {

  digitalWrite(alOn,HIGH);
  abierto = digitalRead(isOpen);
  cerrado = digitalRead(isClosed);
  if( Serial.available() )       // if data is available to read
  {
    val = Serial.read();         // read it and store it in 'val'
   
  } 
 
 
  if(val == '0' && abierto == LOW)
 {
   digitalWrite(oPin,HIGH);
   digitalWrite(oPin2,HIGH);
 } 
 else
 {
   digitalWrite(oPin,LOW);
   digitalWrite(oPin2,LOW);
 }
 
 if(val== '1' && cerrado == LOW)
 {
   digitalWrite(cPin,HIGH);
   digitalWrite(cPin2,HIGH);
 }else{
   digitalWrite(cPin,LOW);
   digitalWrite(cPin2,LOW);
 }
 
 if(abierto == HIGH)
{
  digitalWrite(oPin,LOW);
  digitalWrite(oPin2,LOW);
} 

if(cerrado == HIGH)
{
  digitalWrite(cPin,LOW);
  digitalWrite(cPin2,LOW);
}
 

}

and it's working using an USB COM, but I want to use a bluetooth communication channel to sent the 'O' and 'C' letters. I've tried several codes that I saw in the Internet, but I can not get it work. I'm using a BluetoothMate Clase 2
http://www.5hz-electronica.com/modembluetooth-silver.aspx

When it connects to my laptop, it use the port COM40 but If I try to send a var .. let said "O" using the monitor serial COM40 nothing happen, any ideas? can someone help me with that please.

You can't use the serial monitor to connect to the Bluetooth module, use Putty.

Here is a simplified Bluetooth code.

char val; // variable to receive data from the serial port
int ledpin = 11; // 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();
Serial.println("get data");    // read it and store it in 'val'
  }
  if( val == 'H' || val == 'h' )               // if 'H' was received
  {
    digitalWrite(ledpin, HIGH);  // turn ON the LED
  } 
  if( val == 'L' || val == 'l' ) 
  { 
    digitalWrite(ledpin, LOW);   // otherwise turn it OFF
  }
  delay(100);                    // wait 100ms for next reading
}

Hi, thanks for your answer, I'm trying with putty now, but I'm not able to write anything in the "cmd" displayed on the screen. there's a special configuration to use it?

Additional Information, I'm connecting rx-I to ~3 and tx-O to 2 as showed in OReilly Arduino Coockboock 2nd Edition.

I was able to write... the echo was unabled... but I still not able to communicate with the bluetooth devic :frowning:

Did you pair the BT module to your computer, and did it make a com port? What is the com port for the BT module? Do you know if it has a connection status indicator? All you need to do with that code I gave you, is press H or L, and the led should light. Putty even works wired.

Yes, the bluetooth is Paired to my laptop, it open a COM40 that is what I'm using in putty , when no device is connected to the bluetooth adapter it has a LED that is blinking in yellow, but when a device is connected it stop blinking and another LED is on Green

but when a device is connected it stop blinking and another LED is on Green

So is it connected?

yes, it is connected, but I'm not able to send data

If it is paired you should get something. Put this is setup(), Serial.println("Ready to go"); and then re upload. This should show on the putty monitor that it is connected and ready to send data. If you don't see this then check your baud rate for the putty monitor. Make sure it is set to what is in your code, 9600.

Hi, I tried what you said, I've verified the "baud" and it's the same, I only got that message when I use the usb COM, but with bluetooth I'm not seeing that message :frowning:

What voltage are you supplying to it, 5 or 3.3?

5v, I've verified. the connections, Bluetooth rx to arduino tx and Bluetooth tx to arduino rx and I got nothing :frowning: , I've ready an android app that I've developed to test it but well... it's not working using the pc.. :frowning:

Hey Guys, thanks a lot for your help, I'm not sure why the message is not being displayed, but It's working now :smiley: i'm not sure why didn't work first with putty... I tried this:
1)Started the Monitor Serial in COM40 (the one created for my bluetooth) - The message was not displayed.
2)I tried to turn on the led... it works!!!
3)I tried with putty again.. the message was not displayed, but I can turn on/off the led.
4)Tried with my android app it works nicely :smiley:

Thanks a lot.

Ok so you can send data to it, but you cant get data from it. Maybe it has 2 different com ports, one for sending and one for receiving. But anyways, I'm glad it works.

:frowning: ... not again something should be wrong... I've disconnected it from the a.c and then re-connected and it's not working again...

I need help again... It worked yesterday, but then I've disconnected the AC and then I've reconnected and it stop working.... I'm seeing a strange behaviour, when I connect the bluetooth RN42, the LED labeled with an "L" start blinking, and it does not stop, and the leds labeled with "TX", "RX" seems like are not receiving any signal, any ideas?

With that same code, does it work with the serial monitor? Does the BT module actually connect when using putty?
Did you cross wire the BT module to the Arduino?
BT: tx => Ard: rx
BT: rx => Ard: tx
Even though you are using putty, you can still use the serial monitor, just make sure you use the correct com port number for the Bluetooth com.

With that same code, does it work with the serial monitor? Does the BT module actually connect when using putty?

Yes it worked with your code in the serial monitor, yes there's a green led in the RN-42 that show it as connected.

Did you cross wire the BT module to the Arduino?
BT: tx => Ard: rx
BT: rx => Ard: tx

Yes.

I'm using the port displayed in my computer, also I'm trying with an android device.

Additional Information...

I read in some guides that I found in google, that If I type "$$$" in the first 60 sec when the device is paired, using the serial monitor I gain access to the CMD of the Bluetooth to configure it, well That is WORKING, I'm not sure why or how... but the signals that I send apparently are not handled...

refresh