Arduino Bluetooth Communication [Solved]

Hi. I’m new here and this is my first post. I picked up an Arduino today; for the first time and I have been playing all day. I have been programming Java, C++, C# for half a decade now. I started the morning reading Getting Started with Arduino by Massimo Banzi. Until this afternoon I played with; and have successfully made LEDs, Buttons, Sensors, 7 segment displays, as well as a temperature sensor,’s LM34CAZ/NOPB work. I understand how breadboards work as well as resistors; (I don’t have any capacitors save those on the Arduino itself). I am able to read Schematic Diagrams from others. I am ready to move onto doing something more complicated.

I went to microcenter and purchased a RN-42 Bluetooth module from Sparkfun. I have basic Serial communication working. I have a LED and a resistor on pin 8. I can type H to make the LED go high and anything else to make the LED turn off. (the reason I am saying I have this specific example is shown below)

char val;         // variable to receive data from the serial port
int ledpin = 8; 
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 =;          // 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

I am unable to do this via Bluetooth. (I have played with basic stamps before and I know my Bluetooth stuff works) I found a wiring diagram that is supposed to enable me to cause the LED go on and off via Bluetooth. At

I have my Bluetooth module wired as shown but I’m missing out on something because I don’t have any communication. I am also unsure what they are referencing when they say processing code. Can I get any guidance?

Arduino Type: UNO Version 1.0.3 Is there any information that is needed that I haven’t provided? Thanks for your time, Xnor

Are you using the serial monitor to talk to the Bluetooth module, because that would be wrong. Try putty, it usually works when setup correctly.

Thanks for the advice with Putty! I am now able to send things to the Bluetooth module but I am unable to relay any information back. Incoming information is in a putty window in COM13. While outgoing is on COM8. Typing in to the COM8 window allowed me to control the light I am unsure what I have done wrong in setting up what I have. I have some changes in code reflecting my attempts to receive data. It works when I am hardwired over USB. Have I done something wrong or can anyone point me in the direction I need to head?

simple LED test

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

void setup()
  pinMode(ledpin = 13, OUTPUT);  // pin 13 (on-board LED) as OUTPUT

  Serial.begin(115200);       // start serial communication at 115200bps


void loop() {
  if( Serial.available() )       // if data is available to read
    val =;         // read it and store it in 'val'

  if( val == '0' )               // if '0' was received led 13 is switched off

   digitalWrite(ledpin, LOW);    // turn Off pin 13 off
delay(1000);                  // waits for a second   
Serial.println("13 off");

if( val == '1' )               // if '1' was received led 13 on
    digitalWrite(ledpin = 13, HIGH);  // turn ON pin 13 on
    delay(1000);                  // waits for a second
    Serial.println("13 on");

From my readings on the internet I have determined sort of what the things on the Bluetooth module mean. Can anyone deny what I have here or provide me a location I can learn about PI06? Thanks! RTS: Ready To Send (un-needed) RX: Receive TX: Transmit VCC: 3.3 V CTS: Clear To Send (un-needed) GND: Ground PI06: This pin is mislabeled as 'PIO6', it is actually PIO4. Should you need to reset the Mate, pull this pin high upon power-up, and then toggle it 3 times. Edit 3/5/2013

Thanks very much! Xnor

Does this work?

if( Serial.available() ) // if data is available to read {;}

I use bluetooth myself and your code looks ok to both send and receive. I have the JY-MCU Slave module and I can do both, so i'm not sure why you can't.

You don't need to re-declare ledpin = 13 again, also just put it at the top where you have it, and just leave ledpin inside digitalWrite(ledpin, HIGH/LOW)

It was a lose connection on one of my TX pins. :confused:
I feel really intelligent right about now~
For posterity those who come in future and are using the Sparkfun Bluetooth RN-42 module for communication it works with the example source code above. I am able to enable and disable the light via my cell phone as well as receive serial data. Android 4.2 (it’s still an experimental ROM at this point) using BluetoothSPP from the play store. It’s free and it works wonders. I opened it up in keyboard controller mode and assigned some of the buttons to send my 0 and 1.
I also have this working for a LM34CAZ/NOPB Fahrenheit temperature sensor.

//this is an addition to the previous code it will not run all on it’s own.
It turns on the LED at pin 13
It returns 5 readings of temperatures and then an average.
It turns off the LED at pin 13

    float readings[10];
    digitalWrite(ledpin = 13, HIGH);  // turn ON pin 13 on
    for(int i=0; i <5; i++){
    int x=(analogRead(0));
   float voltage=x*5;
   voltage /=1024;
    Serial.print("Temperature is: "); Serial.println(voltage,DEC);
 Serial.print("Avg Temp: ");
  Serial.println( (readings[0] + readings[1] + readings[2] + readings[3] + readings[4])/5.0,3); 
       digitalWrite(ledpin, LOW);

The oldVal==‘2’ isn’t something that is needed if someone is including this in their project it’s just part of what i’m working on.
Hope someone finds this useful!

(I see that I have a lock this topic option; should I do that because it has been answered or should I leave it open in case someone has a similar question?)