Bluetooth connection

Bluetooth Controlled LED using ESP32

Install from PlayStore:

Open your Arduino IDE, and go to File > Examples > BluetoothSerial > SerialtoSerialBT.

Using the above application, we can modify the code slightly and implement a Bluetooth Controlled LED using ESP32. The aim of this project is to see how easy it is to control GPIO Pins of ESP32 by sending and interpreting the data from Bluetooth.

To keep things simple, let us transmit ‘1’ and ‘0’ from the Mobile Phone App using the macro keys. I assigned ‘1’ for M1 and ‘0’ for M2. You can compare the received data with characters ‘1’ and ‘0’ or their decimal equivalent in ASCII i.e., 49 and 48.

#include <BluetoothSerial.h>

#define ledPIN 2

BluetoothSerial SerialBT;

byte BTData;

/* Check if Bluetooth configurations are enabled in the SDK */

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

void setup(){

pinMode(ledPIN, OUTPUT);

Serial.begin(115200);

SerialBT.begin();

Serial.println(“Bluetooth Started! Ready to pair…”);

}

void loop(){

if(SerialBT.available()){

BTData = SerialBT.read();

Serial.write(BTData);

}

/* If received Character is 1, then turn ON the LED */

/* You can also compare the received data with decimal equivalent */

/* 48 for 0 and 49 for 1 */

/* if(BTData == 48) or if(BTData == 49) */

if(BTData == ‘1’)

{

digitalWrite(ledPIN, HIGH);

}

/* If received Character is 0, then turn OFF the LED */

if(BTData == ‘0’){

digitalWrite(ledPIN, LOW);

}

}

MORE INFO HERE

Bluetooth HC-06-Arduino pdf tutorial by Junta de Castilla y León