how to connect a Bluetooth module to an Arduino based PLC

how to connect a Bluetooth module to an Arduino based PLC

On this post it is showed how to connect a Bluetooth module, HC-05 on this example, to an Arduino based PLC. With all the Industrial Shields equipment it’s possible to add a Bluetooth module as HC-05.

HC-05 is a converter from serial TTL to Bluetooth waves and vice versa. The first step is fix the connections between HC-05 with for example an M-Duino 21. The HC-05 connections available are showed below:

HC-05 has two pins for TTL communication (RX/TX), two pins for power supply (VCC 5V5-3V and GND, WAKEUP(IN) pin to configure the HC-05 and STATE pin (OUT). Next it is showed how to connect HC-05 with an M-Duino, with an Ardbox or an Arduino board the connections would be the same.

Once the devices are connected we can proceed to change the HC-05 default configuration using AT commands. Connecting WAKEUP pin to directly to VCC to put the HC-05 module on AT mode. On AT mode the red LED is blinking slowly. When red led is blinking slowly means that the device is on AT mode and ready to be configured. Below is showed a table with the most important AT . See on your product Bluetooth module for more information.

Command Function
AT Test UART Connection
AT+RESET Reset Device
AT+NAME Query/Set Device Name
AT+PSWD Query/Set Paring Passkey
AT+UART Query/Set UART Parameter

 

Using a simple sketch to read/write from the Serial1 or Serial3 from the M-Duino PLC it’s possible to configure the HC-05 with the AT commands. Then it just needs to send AT commands through the serial monitor. Next is showed the sketch and the serial monitor screen shots:

void setup()
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  Serial1.begin(38400);
}

void loop()
{
  if (Serial1.available())
    Serial.write(Serial1.read());
    
  if (Serial.available()) {
    byte in = Serial.read();
    Serial1.write(in);
    Serial.write(in);
  }
}

 

IMPORTANT!: Use “Both NL and CR” configuration on serial monitor, if not the AT commands won’t accepted for HC-05. For more information see on your device datasheet.

Using AT+NAME:<desiredname> it’s possible to change the device name and using AT+PSWD:<desiredpass> it’s possible to change the device password. Remember that with this device, the default UART configuration is for 38400 baud rate. If after send the simple AT you don’t receive an OK could be that the default values of your device is other that 38400. After configuring the Bluetooth device we are able to contact with it with an external device. 

You must remove the WAKEUP pin and connect it to GND. Then the Bluetooth device will be ready to communicate with other external device (fast red LED blinking). On this example was used an Android smartphone with a Terminal Bluetooth application called HC-05 Terminal. Sending with ASCII code from the smartphone application (Bluetooth Terminal HC-05). 

 

 

See also:

HOW TO USE A MAX3232 WITH ARDUINO BASED PLC

HOW TO USE AN RTC (REAL TIME CLOCK) ON TOUCHBERRY B3 PI

Comments are closed.