small problem with arduino uno+ bluetooth module HC-05

I built an app using app inventor 2 to communicate with arduino via the bluetooth module HC-05 I didn't encounter any problems using the arduino mega 2560, but when i tried the code on the uno r3 the code didn't act as it's suppose to, as you can see below the led on pin 13 is supposed to turn ON when i receive 2 and Off when i receive 3. I did encounter this problem before and I did fix it after long digging and I believe there is something different between the integer definition between the uno and mega or something like that... cant remember but something silly , any help will be appreciated, thank you

The code :

int dim = 10; int long x = 0 ; int long fp,ft,fs = 0;

void setup() { // Begin setup Serial.begin(9600); pinMode(13,OUTPUT);

}

void loop() {

while (Serial.available() > 0) {

delay(10);

x = Serial.parseInt(); if (x == 9) {

fp = Serial.parseInt(); ft = Serial.parseInt(); fs = Serial.parseInt(); int doc = 8; Serial.print(doc);

}

speedBl();

} // for the while

}

void speedBl() {

if ( fs == 1) { dim = 135 ;

} else if ( fs == 2) { dim = 115; digitalWrite(13,HIGH); } else if ( fs == 3) { dim = 95; digitalWrite(13,LOW); } else if ( fs == 4) { dim = 75; } else if ( fs == 5) { dim = 55; } else if ( fs == 6) { dim = 35; } else if ( fs == 7) { dim = 20; } else if ( fs == 8 ) {

dim = 5;

}

else // if x >6 then we exceeded the speed options and we go back to 0 speed or off State { dim = 135; }

I have spent alot of time on this, I need help!

else if ( fs == 8) {
dim = 5;

This is one of reasons source code should be included between
"code"tags (first button, shown as “</>”), like this:

else if ( fs == 8) {
  dim = 5;

sorry about that and that's a page error.

I'm sorry too, I couldn't resist :)

I believe there is something different between the integer definition between the uno and mega

I doubt it. Just to eliminate this potential discrepancy, use uint16_t instead of int.

I tried to use uint16_t instead of int and nothing changed... same problem

maybe its a serial communication problem with the HC-05 using the pins 0 and 1 ..mm

florinc:
This is one of reasons source code should be included between
"code"tags (first button, shown as “</>”), like this:

else if ( fs == 8) {

dim = 5;

…and the second reason is that people get sidetracked by funky control (!) and get off the subject.
Or is it the other way around?

Serial ( class) uses pins 0 & 1 and expecting ANOTHER serial device to use same pins is invitation to trouble.Generally there is no communication between the devices to share same hardware.

Nothing special about serial communication devices connected in parallel on same hardware. .

If you connect TWO LED’s to same output you would not try to turn on just one using only software , would you?

Iam not using the serial pins twice at the same moment, when i want to upload a code ofcourse i take off the HC05 TX,RX pins and upload the code. After the uploading is finished i wire them back or i will have to use software serial which i dont prefer for this project since all the pins are used. The code runs perfectly using the mega 2560 But with the uno r3 board its not working. Even I did use this exact code before but with a different app by using the classical app inventor or app inventor 1. So its maybe a board problem... Im gonna try to upload a sketch using the mega as ISP on an atmega328 chip and i will see... thanks

Does it work with serial monitor (no BT)?

Nothing is working! and I found this thread very informative : http://forum.arduino.cc/index.php?topic=240928.0 They say that the module has a mechanical or manufactural problem... well I did use this exact module before and It did WORK perfectly on almost the same code.... keep digging

ok Software serial will do the job for now...