Bluetooth on Your ESP32

Bluetooth Terminal Application

Bluetooth is a communication media equipment that can be used to connect a communication device with other communication devices, Bluetooth is generally used in cellphones, computers or PCs, tablets, and others. In this first part, we will make the ESP-32 and our cellphone interact.

  1. ESP-32

Execute The Project on Android

Turn on the bluetooth first, open the bluetooth serial terminal application, open the triple strip at the top left and select devices.

Exchange Data Using Bluetooth Serial

In the second part we will take advantage of messages from the serial bluetooth terminal application on a smartphone in order to change the state of a circuit that is connected via the ESP-32. Exchange data that will be used in the form of on and off LEDs.

  1. LED 3mm
// Load libraries
#include "BluetoothSerial.h"
// Check if Bluetooth configs are enabled
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// Bluetooth Serial object
BluetoothSerial SerialBT;
// GPIO where LED is connected to
const int ledPin = 23;
// Handle received and sent messages
String message = "";
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
// Bluetooth device name
SerialBT.begin("ESP32");
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
// Read received messages (LED control command)
if (SerialBT.available()){
char incomingChar = SerialBT.read();
if (incomingChar != '\n'){
message += String(incomingChar);
}
else{
message = "";
}
Serial.write(incomingChar);
}
// Check received message and control output accordingly
if (message =="led_on"){
digitalWrite(ledPin, HIGH);
}
else if (message =="led_off"){
digitalWrite(ledPin, LOW);
}
delay(20);
}

Bluetooth Low Energy

Bluetooth Low Energy or BLE is the latest protocol from Bluetooth that optimizes Bluetooth performance in terms of effective use of power so that it consumes less power than conventional Bluetooth. Let's try using it at the end of this project.

pCharacteristic->setValue(“Hello, back again with ESP32 tutorial!”);

Feel free to contact me at 18220027@std.stei.itb.ac.id for any questions or advice about this tutorial. Thank You!

Name : Andreana Hartadi Suliman

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andreana Hartadi Suliman

Andreana Hartadi Suliman

4 Followers

If we are afraid of failure, it means we have limited our ability. — Hi, nice to see you here. Have a good day!