Those are ASCII codes. That represents the characters '1','2','1','2'. If you want to see characters use Serial.println(char(bt.read())); or, like you say, subtract 48 (for characters '0' to '9' only though).
Post your new code. Always post the new code whenever there are changes so we can keep up.
With my HC05 modules I can put them into partial AT mode by holding the button when powering them up and then release the button. I can change some things but not all. To go to full AT mode I can hold the button pressed with a small alligator clip and plug the module in holding the button down all the time. That has worked for every module that I have tried. It is then in full mode and I can make any changes. The LED blinks the same whether it is in full or partial AT mode.
Interesting... so continuous holding is full AT mode? Good to know!
Here are the current codes. The receiving end now gets 1 2 1 2 1 2, etc. Ideally, I'd like to receive 12 12 12 if that's possible. I did some experimentation with storing ID as different data types, but it seems like the problem is with how the Bluetooth modules send strings of info? I saw some discussion of Serial.readString online, but I got an error when I tried to use it.
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
// HC-06 default baud rate is 9600
BTSerial.begin(9600);
}
uint8_t ID = 12;
//int ID = 12;
//char ID = 12;
void loop()
{
BTSerial.print(ID); //send ID value to other Bluetooth module?
Serial.print(ID);
delay(1000);
}
Receiving/Servant #include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
uint8_t ID;
//int ID;
//char ID;
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
Serial.println("Remember to select Both NL & CR in the serial monitor");
// HC-05 default serial speed is 9600
BTserial.begin(9600);
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
ID = BTserial.read();
I recommend that you go study the serial input basics tutorial. All of the principles and methods that apply to Serial apply to software serial. Good reliable methods for receiving (and sending) data over serial ports.
Oof, I misunterpreted the "general guidance" thread as saying I should use ... now that I see the </> button it seems obvious lol. I'd been wondering why I couldn't get my code looking all nice
Regardless, it works! Entirely and completely! I've included the code below and thank you both SO MUCH for your help! This weird little project went outside the knowledge base of the professor I'd been bothering, and it's so cool to me that people are so passionate about something to just help a stranger out on the forums. The only question I really need an answer to now is whether or not I can mark several responses as answers lol
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
void setup()
{
Serial.begin(9600);
// HC-06 default baud rate is 9600
BTSerial.begin(9600);
}
char ID[] = "12"; //string constant
void loop()
{
BTSerial.println(ID); //send ID value to other Bluetooth module?
Serial.println(ID);
delay(1000);
}
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
const byte numChars = 32;
char ID[numChars];
boolean newData = false;
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
Serial.println("Remember to select Both NL & CR in the serial monitor");
// HC-05 default serial speed is 9600
BTserial.begin(9600);
}
void loop()
{
char l;
char endMarker = '\n';
static byte ndx = 0;
while (BTserial.available() > 0 && newData == false) {
l = BTserial.read();
if (l != endMarker) {
ID[ndx] = l;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
} else {
ID[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
Serial.println(ID);
delay(1000);
}