5
\$\begingroup\$

I am trying to turn ON and OFF a LED with my Android Device through a Bluetooth module (JY-MCU V1.05), I can connect to the module with the key "1234", but when I send a command to the module through the "Bluetooth Terminal" app, there is no respond, no action from the LED.

Here is my installation:

http://uppix.net/HOIKli.png

Here is the Arduino code:

char val;         
int ledpin = 13;  

void setup()
{
  pinMode(ledpin = 13, OUTPUT);       
  Serial.begin(115200);               
}

void loop() {
  if( Serial.available() )            
  {                               
  val = Serial.read();                

  if( val == '0' )                    
  {
    digitalWrite(ledpin, LOW);        
    delay(1000);                      
    Serial.println("13 off");         
  }

if( val == '1' )                      
 {
    digitalWrite(ledpin = 13, HIGH);  
    delay(1000);                     
    Serial.println("13 on");          
  }
 }
}

(Also tried with a serial of 9600)

Any idea why I can't communicate with the Arduino ?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I've just cropped and included your photo, although a schematic would be a lot clearer. You can either use the on-site editor by pressing Ctrl-M or post another image and someone can include it. \$\endgroup\$
    – PeterJ
    Aug 29, 2013 at 12:30
  • \$\begingroup\$ if( Serial.available() ) {;} does not look right... \$\endgroup\$
    – JimmyB
    Aug 29, 2013 at 15:56

2 Answers 2

3
\$\begingroup\$

A few problems that I can see are:

  • The JY-MCU appears to be a 3.3V device and you have it connected to VIN which is 5V. Try connecting to the 3V3 line although be aware this will be available only when running from USB power because it's supplied by the FTDI USB chip.

  • Before doing that though I've found references to it not having 5V tolerant serial lines and found a recommendation to use a voltage divider by connecting a 2.2k resistor to ground from the TX line on the Ardunio and a 1k in series between the TX line on the Arduino and the RX line on the module. That was part of a Success Using the JY-MCU (linvor) Bluetooth Module Instructable that you might like to read as well.

  • The default speed appears to be 9600 BPS so stick with that at the moment.

And a few recommendations that are not likely to be your problem but worth changing:

  • You don't have a current limit resistor in series with your LED. See the question Correct formula for LED current-limiting resistor?

  • Only leave ledpin = 13 near the top line where it is declared, remove it from the calls to digitalWrite. It won't make a functional difference it's just a good habit because at the moment if you change the pin you'll have to do it in several spots when not necessary and may forget to.

\$\endgroup\$
0
1
\$\begingroup\$

Do you have the USB plugged into the arduino? I believe (at least with the Uno), pins 0 and 1 are blocked when the USB is plugged in, so I used the SoftSerial library to use any other Digital I/O pins as the Rx and Tx.

\$\endgroup\$
2
  • \$\begingroup\$ You can definitely compile, but the code won't run. \$\endgroup\$
    – dawnoflife
    Aug 29, 2013 at 19:32
  • \$\begingroup\$ You don't have to change every serial to mySerial. In your code serial.println() is printing to the console not to the Tx pin. So, you have to replace your digitalWrite() and digitalRead() commands with mySerial read and write. \$\endgroup\$
    – dawnoflife
    Sep 3, 2013 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.