HC05 Module not sending Sensor values

Hello!
I am working on using HC05 modules to connect a flex sensor to a servo motor. I can send values fine if I just write 0-180, but when I read the flex sensor and map it, it prints weird symbols before the data. I tried changing the baud rate but it didn't change anything. The code and sensor themselves work fine, it just is messed up when I send it over Bluetooth.
My question is - what is this symbol? Is there anyway to have the data send better?
Thank you!

-- Serial Moniter

-- CODE

/* MASTER CODE
Should read and send the flex sensor values */

int rawValue = 0;
int sendValue = 0;

void setup() {
  pinMode(A5, INPUT_PULLUP);
  Serial.begin(57600);
}

void loop() {
  delay(500);
  rawValue = analogRead(A5);
  sendValue = map(rawValue, 160,250, 0,180);
  
  Serial.println(rawValue);
  Serial.println(sendValue);

  if (0 <= sendValue <= 180){
    Serial.write(rawValue);
  }
}

Welcome to the forum

Which Arduino board are you using and how is the HC-05 connected to it ?

if (0 <= sendValue <= 180)

This is not how you check whether sendValue is within the range 0 to 180. You need to do 2 comparisons

if (sendValue >= 0 && sendValue <= 180)

Hello! Thank you, I'm more familiar with python so Ill fix that.

I am using an Arduino uno and it is connected using the RX and TX pins. I used this tutorial from How to Mechanics

Your diagram shows a Mega

Please clarify which board you are using

EN should not connect to 5V. EN should only connect to 3.3V and only then to get to AT mode to make changes to HC05 setup.

Hi, yes that is the circuit from the tutorial since I dont have my own diagram but I am using a Uno. I have them programmed and connected, and the bluetooth works fine, I can send a command on one board and it moves the servo on the other. it is only when I try to send my sensor value that it adds those symbols and doesn't work. Do you know what those symbols are? its when I print the rawValue/analogreading.

If you are using a Uno then it is not a good idea to use pins 0 and 1 for the HC-05 as they are used by the Serial interface. This will prevent printing debugging information to the Serial monitor and can interfere with uploading sketches

You should consider using SoftwareSerial on 2 other pins of your choice

Another observation. analogRead() will return a value between 0 and 1023 so rawValue could be between 0 and 1023 but your mapping does not take this into account

If yo were not using pins 0 and 1 then you could print what analogRead() was returning to check its value

Okay thank you! I will try using SoftwareSerial and see if that works.

The mapping is because we are working with making textile flex sensors so it filters out the noise and those are the values I got from fully extended to fully retracted.

tx goes to rx
rx goes to tx

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.