HC-05 Bluetooth. Arduino. Change baud rate 38400. Send random to app

Hello friends,

  • To carry out applications with Bluetooth between Arduino and App Inventor, the HC-06 module is usually used. This module can only work as a client, enough for most of the projects that you will see in the tutorials, it is the most used and recommended.
    bluetooth1
  • Another similar module is the HC-05, this can function as a server or a client. You may have to set the speed using AT commands to adapt it to App Inventor. It comes with 38400 baud and you will have to change it to 9600. Note that it has 6 terminals and a button.
    bluetooth2

1.- Change baud rate with AT commands.

  • We are going to change the baud rate from 38400 to 9600 using AT commands.

On the internet you can find many tutorials on how to change the baud rate using AT commands, here I will put a small summary. This is a tutorial in Spanish.

#include <SoftwareSerial.h>
SoftwareSerial BT(10,11);
 
void setup()
{
  BT.begin(38400);
  Serial.begin(38400);
  // BT.begin(9600);
  // Serial.begin(9600);
}
 
void loop(){ 
  if(BT.available()) {Serial.write(BT.read());}
 
  if(Serial.available()){BT.write(Serial.read());}
}
  • Programming in Mode 2

To program in Mode 2, we remove the red wire (5 V) from the module's power supply. We press the small button on the module. We connect the red wire to 5 V by holding down the button. When the red wire is connected, we release the button.

The module's LED will blink slowly.

  • Serial Monitor: 38400 bauds.
    bluetooth4

  • We wrote:

AT response OK
AT+UART? response +UART: 38400,0,0
AT+UART=9600,0,0 response OK
AT+UART? response +UART: 9600,0,0

Now module with 9600 bauds.

4 Likes

2.- Arduino with the HC-05 Bluetooth module sends two random numbers to the app.

p9A0i_bluetooth_aleatorios_V2.aia (3.3 KB)

const unsigned long interval= 3000;
unsigned long previousMillis;
unsigned long currentMillis;

String send_this;

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

void loop() {
 currentMillis = millis();
 if (currentMillis - previousMillis >= interval){
   float t = random(0,10000) / 100.0;
   float h = random(0,10000) / 100.0;

   send_this = String(t,2) + "," + String(h,2);
   Serial.println(send_this);
   previousMillis = millis();
 }
}
  • App Inventor. Blocks.

- Screenshot.

bluetooth8

4 Likes