PROJECT #7 - Trying Out Bluetooth Classic and Low Energy On ESP32 Dev Board Using The Arduino IDE

Hello there! Welcome to my second to last blog about trying out ESP32 Development Board features. In this blog, I'm going to experiment with Bluetooth features in ESP32 Dev Board, both the classic one and the low-energy one. Now without any more delay, let's get to the experiment!


PART 1: BLUETOOTH CLASSIC

STEP 1: Prepare The Required Software and Hardware

For hardware, you'll need these components:

  • ESP32 Dev Board
  • Breadboard
  • Jumper Cable Male-to-Male
  • LED 
  • 330 Ohm Resistor
  • BMP280 Barometric Pressure Module

For software, you'll need to set up the Arduino IDE. If you haven't set it up yet, you can click here to see the installation process from my first project in the first step of the first part.

Be sure to install the correct library for the BMP280 Module too. You can see the installation here.


STEP 2: Test The Bluetooth Classic Connection

You'll only need your ESP32 Dev Board and your phone for testing the Bluetooth classic connection using the Bluetooth Terminal application. I'm using Serial Bluetooth Terminal app for this experiment.

Serial Bluetooth Terminal Application

I'm going to use the Example source code from the ESP32 Library. You can access the file from File -> Examples -> BluetoothSerial -> SerialtoSerialBT or you can see the code below.

SerialtoSerialBT Source Code

After you uploaded and ran the code to your Dev Board, open the app and go to Devices. Scan for devices and connect to your ESP32 device. In my case, the device's name is ESP32test. Don't forget to turn on Bluetooth on your mobile device. Your app should show that you are connected to your device as in the image below.


First Run Result

Connected To Device

After you have connected to your ESP32 device, you should be able to send messages between the app and the ESP32's terminal. It should look as in the image below.

Send Message To Each Other


STEP 3: Exchange Data Using Bluetooth Classic

I'm going to try sending sensor readings to my mobile device and make the LED turn on and off using my mobile device. Connect the LED and the BMP280 Module to your ESP32 Dev Board on the breadboard. I'm connecting the LED to GPIO 5 and the BMP280 to the I2C communication line (GPIO 22 to SCL pin and GPIO 21 to SDA pin). The connection should be like this:

Hardware Connection

After the hardware is assembled, upload the code. I'm making my code from this reference because I'm using a different sensor from that tutorial. You can see the code here or look at the image below.

BT Exchange Data Source Code (1)

BT Exchange Data Source Code (2)

BT Exchange Data Source Code (3)

If the code works, you should be able to see the sensor readings at 10 seconds intervals and you can turn on and off the LED using the 'led_on' and 'led_off' commands. Look below for the project's result.

Code First Run

Sensor Readings


And that's it for the first part!


PART 2: BLUETOOTH LOW ENERGY (BLE)

STEP 1: Prepare The Required Software and Hardware

For hardware, you'll only need ESP32 Dev Board and a smartphone with a Bluetooth connection. For software, you'll need to set up the Arduino IDE like in the first part. Look above for more information.


STEP 2: Test The BLE Connection

I'm using nRF Connect for Mobile application for this experiment. 

nRF Connect for Mobile Application

The code I'm using for this experiment is from the examples file. You can access the code from File -> Examples -> ESP32 BLE Arduino -> BLE_server or you can see it in the image below.

BLE_server Source Code (1)

BLE_server Source Code (2)

After you uploaded and ran the code to the ESP32 Dev Board, open the app and connect to the ESP32 device. The result should be like in the image below.

Result


And that's it for this week's project! Thank you for reading and happy experimenting! ^^



- Ryu / 18220025

Comments

Popular posts from this blog

PROJECT #5 - Trying Out OLED Display and Pulse-Width Modulation On ESP32 Dev Board Using The Arduino IDE

Getting Started with ESP32 Development Board - Programming "LED Blink" using Arduino IDE