Bluetooth decoding

so i'm using the HC-06 bluetooth module connected to an arduino UNO and i'm sending signals to it with my phone on the app "dabble". the code i'm using is this:

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

void loop()
{
  if(Serial.available()>0){
    int readString=Serial.read();

    Serial.println(readString);
  }
  
   
}

and every time i send data from the dabble app by pressing a button or something i get this whole list of numbers at once in the Serial monitor:
255

1

1

1

2

0

0

0
how do i check if i receive the signal i want?

It looks like you're using the hardware UART (pins 0 and 1) for the BT module; that will interfere with the serial monitor. You're better off using SoftwareSerial on two other pins.

Note that Serial.read() only reads a single byte, not a string.


Your problem is not related to IDE 1.x and hence has been moved to a more suitable location on the forum.

So you read the char from Serial and then print the result to the same port? Do you think anything good will come out of this?

You have to use a different ports for BT module and Serial Monitor. On Uno you could use a SoftwareSerial as @sterretje advised.

where can i find the softwareserial library? i'm using an arduino UNO.

It is already installed along with the Uno files

Just #include it as normal

okay. so now i have this: but it's still giving a bunch of different numbers. am i doing something wrong?

#include <SoftwareSerial.h>
const byte rx = 2;
const byte tx = 3;
SoftwareSerial mySerial(rx, tx);
void setup(){
  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(rx, INPUT);
  pinMode(tx, INPUT);
}

void loop()
{
  if(mySerial.available()>0){
    Serial.println(mySerial.read());
  }
  
   
}

Try Serial.write(mySerial.read());.

kinda works, but now i get some squares and a '?'
image
image

What exactly are you sending ?

By the way, you don't need the pinMode()s and in any case, why would the Tx pin be an INPUT ?

i'm sending "qwerty" in the dabble app, and i just forget about the tx bc it's not really that important in my project, but thanks!

i fixed it myself. the bluetooth module sends ~9 signals wich i store in an array and then use.
edit for if you want to know exactly the solution:
using softwareserial is good, but it's not required from what i saw.
basically, the bluetooth module sends a couple numbers in succession for every input from your dabble app. these are unique for every button, but there are always 9 of them, so knowing this you can start filling an array with the numbers, until you've got 9 numbers in your array, and then you can look for unique numbers, like in my case pressing the forward button gave me at the 7th number a "1", wich does not occur with other buttons, so if the array has 9 numbers AND the 7th number in the array is a 1, i move my car forward. example code:

#include <SoftwareSerial.h>
const byte rx = 2;
const byte tx = 3;
int array[9];
int order = 0;
SoftwareSerial mySerial(rx, tx);

void setup(){
  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
}

void loop(){
//if i receive a message:
if(mySerial.available() > 0){
    //fill array with messages
    array[order]=mySerial.read();
    order++;
    //print array and execute command based on message when the full message is sent
    if(order == 8){
      order = 0;
      for(int i = 0; i <= 8; i++){
        //print the message for debugging
        Serial.print(array[i]);
      }
      //new line
      Serial.println("");
      if(array[6]==1){
        //do something
        Serial.println("forward!");
      }
}

my initial error was that i treated the numbers as one message, and that just isn't true.

The "Solution" label is used to make it easier for other users to find the most useful message in the thread. Your message is unlikely to be of any use to other participants - you do not write what the error was, nor how you solved it.

is my edit good enough?

How do you know when to start counting the numbers to get nine?

i.e. how do you know that the received signal is the first in the new packet, and not, say, the sixth in the previous one, the beginning of which you missed?
If you make the mistake once - you will never get the packet in the correct order

edit: nvm it isn't random, please reread.
to test this you could just write Serial.println(mySerial.read()); in the if serial.available block to see what messages you get with every press. i got 255 1 1 1 0 1 0 0 when i pressed the forward button. this means my message was 8 long. so knowing this, i should change the array size to 8, and you can do 9 if you wanna be sure. then at "if(order == 8){" change the 8 to the length of your message, in my case 8. Same for the 8 underneath at the for() loop. The "if(array[6] == 1){ do somthing} just depends on the message wich will be unique. if this didn't help please send me the string you're receiving.

I don't have problems with receiving messages, I just wanted to help you improve your solution.
If you didn't quite understand what I wrote to you, think about what will happen if packets of 9 signals are sent multiple times

i don't really get it? the bluetooth module sends (for me so probably also for other people) 8 numbers after each other wich i store and then i read one specific unique number. so, if packets of 9 signals are sent multiple times you change the eights in the code to nines and it should work.