Alter baud rate after being certain events I'm using my HC-05 (Master) to receive strings from a sensor (Slave). Each string is supposed to have 7 items divided by ',' like so:


  a,b,c,d,e,f,g


But it isn't always received in such a manner. Sometimes it's 1.5 of a string or 2 strings in 1. I have tested the sensor with its native software and others, so the sensor shouldn't be the problem. So I believe it may be a baud rate issue. I tried to increase the HC-05's baud rate to 115200, but wasn't able to test anything because I need to use AT commands at the beginning of the program and for that the baud rate has to be 38400.

Is there any way to change the baud rate for Serial after the fact?

PS: I'm using a Mega 2560 and the sensor has a sample rate of 8Hz.

#include &lt;SoftwareSerial.h&gt;
#include &lt;SD.h&gt;

String test="";
char aux;
File myFile;

void setup() {
  pinMode(22, OUTPUT);
  digitalWrite(22,HIGH);
  Serial1.begin(38400);
  Serial.begin(38400);
  Serial.println("To begin capture press any key and enter");
  while(!Serial.available());
  Serial1.println("AT+INIT");
  while(!Serial1.available());
  Capture();
}

void Capture() {
  while(!Serial1.available());
  for(int i=0;i&lt;2;i++) {
    delay(125);
    while(Serial1.available()) {
      aux=Serial1.read();
      Serial.print(aux);
    }
  }
  Serial.println("END");
}

void loop() {
}
To answer your specific question, yes you can alter the baud rate after an event.  Just use a Serial.end() then a Serial.begin() with the new baud rate.