RGB value 0 to 255 value

hi guys

i use thisapplication in my smartphone:

and in my arduino i use this code:

const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // make the pins outputs:
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

}

void loop() {
  // if there's any serial available, read it:
  if (Serial.available() > 0) 
  {
    int red = Serial.parseInt();

      analogWrite(redPin, red);
      analogWrite(greenPin, 0);
      analogWrite(bluePin, 0);

  }
  Serial.println(Serial.parseInt());
  delay(100);
}

i get never 1,2,3,4,5,6,7,8,9,10,11,12,13..................,255

somtimes i get 10 or 100 or 240... but never 1,2,3,4,5,6,7,8,9,10,11,12,13..................,255 with my bluetooth HC-05

what ill change in my arduino code ? thanks

what ill change in my arduino code ? thanks

Look at that code. If there is serial data to read, you read the next int, and assign the result to red, and to a pin.

Then, you read the next int, even if there isn’t anything, and pretend that that is useful information to send back to the phone.

Please explain WHY you do that.

How are you using the app to send data?

shell_traywnd:
what ill change in my arduino code ? thanks

you need to know how data is being transmitted to the bluetooth device in order to build a parsing algorithm.

there is a whole parsing sketch on the website, did you start with that?

hi

relax guys am already tested this code:

int R = 6;
int G = 5;
int B = 3;

int number = 0;

void setup() {
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);  
  Serial.begin(9600);     
}
void loop() {
while(Serial.available() > 0)
{
number = Serial.read();
Serial.println(number);
delay(10);
}
analogWrite(R, number);
analogWrite(G, 0);
analogWrite(B, 0);

  delay(100); 
}

without any result :confused:

i want turn on the red color from number 1 then 2 then3... then 255 with the seekbar not with a simple button

http://tr1.cbsistatic.com/hub/i/2015/05/07/e90584b3-f4ab-11e4-940f-14feb5cc3d2a/seekbar_2.png

shell_traywnd:
relax guys am already tested this code... without any result :confused:

No result - at all?

byte R = 6;
byte G = 5;
byte B = 3;
byte number = 0;
void setup() 
{
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);  
  Serial.begin(9600);     
}
void loop() 
{
  if (Serial.available() > 0)
  {
    number = Serial.read();
    Serial.println(number, DEC);
    analogWrite(R, number);
    analogWrite(G, 0);
    analogWrite(B, 0);
  }
}

Please dump what the phone sends here so we can see what the phone actually "sends".

Use this code:

void setup(){
Serial.begin(115200);
}


void loop(){


if (Serial.available){

Serial.println(Serial.read());


}

It may not be just sending a single byte...it may have some other protocol stuff...

Are you 100% sure of the baudrates btw?

Johnny010:
It may not be just sending a single byte...it may have some other protocol stuff...

It sure looks like that's correct. The code in this post looks nothing like the example code: ArduDroid: Simple Bluetooth control for Arduino and Android - TechBitar

Just a quick look at the example shows that the code is first looking for a start character, then a command character, and then more data. That's not happening in this sketch.

shell_traywnd: Have you read the documentation about the code that runs on the Arduino side? Do you understand it? If not, it's too early to be trying to write a sketch, you need to understand what's going on before you get to that point.

Johnny010:
Please dump what the phone sends here so we can see what the phone actually "sends".

Use this code:

void setup(){

Serial.begin(115200);
}

void loop(){

if (Serial.available){

Serial.println(Serial.read(),HEX);

}




It may not be just sending a single byte...it may have some other protocol stuff...

Quick edit...I hate whitespace.

Anyway, the app the guy has written sends multiple bytes.

IMHO, it is a bit messy in a way...but it works. You may need more experience first before trying a protocol based comms system.

Try just learning about sending a simple 1 byte via the bluetooth first....before dealing with "strings" of bytes.

Really? Notice anything wrong?

void setup(){Serial.begin(115200);}void loop(){if(Serial.available){Serial.println(Serial.read(),HEX);}

How about now?

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    if ( Serial.available )
    {
        Serial.println(Serial.read(), HEX);
    }

Ok…good mess up.

#include <SoftwareSerial.h>

// Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);

void setup()
{
    Serial.begin(115200);
    bluetoothser.begin(9600);
   
}

void loop()
{
  
    if ( bluetoothser.available() )
    {
        Serial.println(bluetoothser.read(), HEX);
    }
}

i do a video on youtube guys

i still dosn’t know why i havent the values :confused:

thanks

shell_traywnd:
i do a video on youtube guys

video test - YouTube

i still dosn't know why i havent the values :confused:

thanks

Probably because you still have not made the necessary code corrections.

thanks for your reply

i copy and past your code

#include <SoftwareSerial.h>

// Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);

void setup()
{
    Serial.begin(115200);
    bluetoothser.begin(9600);
   
}

void loop()
{
  
    if ( bluetoothser.available() )
    {
        Serial.println(bluetoothser.read(), HEX);
    }
}

I connect the bluetooth module on

RX to pin ~9
TX to pin ~10

and still have no nombers :’(

i get nombres now but there is no 0,1,2,3,4,5,6,7…255 still the same problem with this code:

#include <SoftwareSerial.h>

const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

// Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);

void setup()
{
    Serial.begin(115200);
    bluetoothser.begin(9600);
   
}

void loop()
{
  
    if ( bluetoothser.available() )
    {
        Serial.println(bluetoothser.read(), DEC);


      analogWrite(redPin, bluetoothser.read());
      analogWrite(greenPin, 0);
      analogWrite(bluePin, 0);
    }
}

i record a video here:

You check to see if there's at least one character to read, and then read two characters.
Don't do that.

The numbers that are being printed looks like ASCII codes, but you are treating them as raw binary values. Furthermore, you code is reading a character and printing it as a decimal number, then reading ANOTHER character and passing that value to AnalogWrite(). That's going to go one of two ways: either another character is not yet ready, in which case AnalogWrite() will receive a value of -1, or a character will be available, in which case it won't get echoed to the screen so you won't be sure what you're actually getting.

PLEASE load and run the sketch that Johnny010 provided. Then, copy the text from the Serial Monitor window and post it. Don't take a video of it, don't attach a screen capture. Just copy and paste the text.

We already know that you are slowly sliding the slider. We need to see the exact data that is being received, character for character, and then we can tell you what you are getting. I have my suspicions on what is being sent, but I can't be sure until we can clearly see all of the data.

thank you for your reply, i get this:
(code tags added by moderator who got tired of scrolling thru this long list)

2A
31
31
7C
30
33
7C
31
35
23
2A
31
31
7C
30
33
7C
31
36
23
2A
31
31
7C
30
33
7C
31
37
23
2A
31
1
35

2A

31


33

1
36

2A











31
7C
30
33
7C
31
38
23
2A
31
31
7C
30
33
7C
31
39
23
2A
31
31
7C
30
33
7C
32
30
23
2A
31
31
7C
30
33
7C
32
32
23
2A
31
31
7C
30
33
7C
32
33
23
2A
31
31
7C
30
33
7C
32
35
23
2A
31
31
7C
30
33
7C
32
36
23
2A
31
31
7C
30
33
7C
32
37
23
2A
31
31
7C
30
33
7C
32
38
23
2A
31
31
7C
30
33
7C
32
39
23
2A
31
31
7C
30
33
7C
23
31
7C
33
32
2A
31
30
7C
23
31
7C
33
34
2A
31
7C
30
33
7C
33
35
23
2A
31
31
7C
33
33
23
31
30
7C
37
31
7C
33
33
23
31
30
7C
39
31
7C
30
33
7C
34
30
23
2A
31
31
7C
30
7C
31
2A
31
31
7C
30
33
7C
34
32
23
2A
31
31
7C
30
33
7C
34
33
23
2A
31
31
7C
30
33
7C
34
35
23
2A
31
31
7C
30
33
7C
34
36
23
2A
31
31
7C
30
33
7C
34
38
23
2A
31
31
7C
30
33
7C
34
39
23
2A
31
31
7C
30
33
7C
35
32
23
2A
31
31
7C
30
33
7C
35
33
23
2A
31
31
7C
30
33
7C
35
34
23
2A
31
31
7C
30
33
7C
35
35
23
2A
31
31
7C
30
33
7C
35
38
23
2A
31
31
7C
30
33
7C
36
30
23
2A
31
31
7C
30
33
7C
36
33
23
2A
31
31
7C
30
33
7C
36
36
23
2A
31
31
7C
30
33
7C
36
38
23
2A
31
31
7C
30
33
7C
36
39
23
2A
31
31
7C
30
33
7C
37
30
23
2A
31
31
7C
30
33
7C
37
31
23
2A
31
31
7C
30
33
7C
37
32
23
2A
31
31
7C
30
33
7C
37
33
23
2A
31
31
7C
30
33
7C
37
34
23
2A
31
31
7C
30
33
7C
37
35
23
2A
31
31
7C
30
33
7C
37
36
23
2A
31
31
7C
30
33
7C
37
37
23
2A
31
31
7C
30
33
7C
37
38
23
2A
31
31
7C
30
33
7C
37
39
23
2A
31
31
7C
30
33
7C
38
30
23
2A
31
31
7C
30
33
7C
38
31
23
2A
31
31
7C
30
33
7C
38
32
23
2A
31
31
7C
30
33
7C
38
33
23
2A
31
31
7C
30
33
7C
38
35
23
2A
31
31
7C
30
33
7C
38
36
23
2A
31
31
7C
30
33
7C
38
37
23
2A
31
31
7C
30
33
7C
38
38
23
2A
31
31
7C
30
33
7C
38
39
23
2A
31
31
7C
30
33
7C
39
30
23
2A
31
31
7C
30
33
7C
39
31
23
2A
31
31
7C
30
33
7C
39
32
23
2A
31
31
7C
30
33
7C
39
33
23
2A
31
31
7C
30
33
7C
39
34
23
2A
31
31
7C
30
33
7C
39
35
23
2A
31
31
7C
30
33
7C
39
36
23
2A
31
31
7C
30
33
7C
39
38
23
2A
31
31
7C
30
33
7C
39
39
23
2A
31
31
7C
30
33
7C
31
30
30
23
2A
31
31
7C
30
33
7C
31
30
31
23
2A
31
31
7C
30
33
7C
31
30
32
23
2A
31
31
7C
30
33
7C
31
30
33
23
2A
31
31
7C
30
33
7C
31
30
34
23
2A
31
31
7C
30
33
7C
31
30
35
23
2A
31
31
7C
30
33
7C
31
30
36
23
2A
31
31
7C
30
33
7C
31
30
37
23
2A
31
31
7C
30
33
7C
31
30
39
23
2A
31
31
7C
30
33
7C
31
31
31
23
2A
31
31
7C
30
33
7C
31
31
32
23
2A
31
31
7C
30
33
7C
31
31
34
23
2A
31
31
7C
30
33
7C
31
31
35
23
2A
31
31
7C
30
33
7C



1
31
7C
30
33
7C
31
31
35
23

1
31

0
33

31
31
36
23
2A
31
31
7C
30
33
7C
31
31
38
23
2A
31
31
7C
30
33
7C
31
32
31
23
2A
31
31
7C
30
33
7C
31
32
32
23
2A
31
31
7C
30
33
7C
31
32
33
23
2A
31
31
7C
30
33
7C
31
32
34
23
2A
31
31
7C
30
33
7C
31
32
36
23
2A
31
31
7C
30
33
7C
31
32
38
23
2A
31
31
7C
30
33
7C
31
32
39
23
2A
31
31
7C
30
33
7C
31
33
32
23
2A
31
31
7C
30
33
7C
31
33
33
23
2A
31
31
7C
30
33
7C
31
33
35
23
2A
31
31
7C
30
33
7C
31
33
36
23
2A
31
31
7C
30
33
7C
31
33
37
23
2A
31
31
7C
30
33
7C
31
33
38
23
2A
31
31
7C
30
33
7C
31
33
39
23
2A
31
31
7C
30
33
7C
31
34
30
23
2A
31
31
7C
30
33
7C
31
34
31
23
2A
31
31
7C
30
33
7C
31
34
32
23
2A
31
31
7C
30
33
7C
31
34
33
23
2A
31
31
7C
30
33
7C
31
34
34
23
2A
31
31
7C
30
33
7C
31
34
36
23
2A
31
31
7C
30
33
7C
31
34
37
23
2A
31
31
7C
30
33
7C
31
34
38
23
2A
31
31
7C
30
33
7C
31
35
30
23
2A
31
31
7C
30
33
7C
31
35
31
23
2A
31
31
7C
30
33
7C
31
35
34
23
2A
31
31
7C
30
33
7C
31
35
37
23
2A
31
31
7C
30
33
7C
31
35
38
23
2A
31
31
7C
30
33
7C
31
36
31
23
2A
31
31
7C
30
33
7C
31
36
32
23
2A
31
31
7C
30
33
7C
31
36
36
23
2A
31
31
7C
30
33
7C
31
36
37
23
2A
31
31
7C
30
33
7C
31
36
38
23
2A
31
31
7C
30
33
7C
31
36
39
23
2A
31
31
7C
30
33
7C
31
37
30
23
2A
31
31
7C
30
33
7C
31
37
32
23
2A
31
31
7C
30
33
7C
31
37
33
23
2A
31
31
7C
30
33
7C
31
37
36
23
2A
31
31
7C
30
33
7C
31
37
37
23
2A
31
31
7C
30
33
7C
31
37
38
23
2A
31
31
7C
30
33
7C
31
38
31
23
2A
31
31
7C
30
33
7C
31
38
34
23
2A
31
31
7C
30
33
7C
31
38
36
23
2A
31
31
7C
30
33
7C
31
38
39
23
2A
31
31
7C
30
33
7C
31
39
32
23
2A
31
31
7C
30
33
7C
31
39
33
23
2A
31
31
7C
30
33
7C
31
39
36
23
2A
31
31
7C
30
33
7C
31
39
37
23
2A
31
31
7C
30
33
7C
32
30
30
23
2A
31
31
7C
30
33
7C
32
30
32
23
2A
31
31
7C
30
33
7C
32
30
33
23
2A
31
31
7C
30
33
7C
32
30
34
23
2A
31
31
7C
30
33
7C
32
30
35
23
2A
31
31
7C
30
33
7C
32
30
36
23
2A
31
31
7C
30
33
7C
32
30
38
23
2A
31
31
7C
30
33
7C
32
31
30
23
2A
31
31
7C
30
33
7C
32
31
31
23
2A
31
31
7C
30
33
7C
32
31
34
23
2A
31
31
7C
30
33
7C
32
31
36
23
2A
31
31
7C
30
33
7C
32
32
34
23
2A
31
31
7C
30
33
7C
32
32
37
23
2A
31
31
7C
30
33
7C
32
32
38
23
2A
31
31
7C
30
33
7C
32
33
30
23
2A
31
31
7C
30
33
7C
32
33
31
23
2A
31
31
7C
30
33
7C
32
33
33
23
2A
31
31
7C
30
33
7C
32
33
34
23
2A
31
31
7C
30
33
7C
32
33
35
23
2A
31
31
7C
30
33
7C
32
33
37
23
2A
31
31
7C
30
33
7C
32
33
38
23


1
31

0
33


33
37



31


33


33
38

2A
31
31
7C
30
33
7C
32
33
39
23
2A
31
31
7C
30
33
7C
32
34
30
23
2A
31
31
7C
30
33
7C
32
34
31
23
2A
31
31
7C
30
33
7C
32
34
32
23
2A
31
31
7C
30
33
7C
32
34
34
23
2A
31
31
7C
30
33
7C
32
34
35
23
2A
31
31
7C
30
33
7C
32
34
37
23
2A
31
31
7C
30
33
7C
32
34
38
23
2A
31
31
7C
30
33
7C
32
34
39
23
2A
31
31
7C
30
33
7C
32
35
30
23
2A
31
31
7C
30
33
7C
32
35
32
23
2A
31
31
7C
30
33
7C
32
35
33
23
2A
31
31
7C
30
33
7C
32
35
35
23

@OP
Pasting 1800 lines into a thread is not smart!
Edit: Code tags is more responsible, thanks to the moderator.