Bluetooth Classic and Low Energy with Arduino IDE and ESP32
Welcome to Another Article...!
Today's article will show how to use both Bluetooth Classic and Bluetooth Low Energy which featured in ESP32. Bluetooth feature in ESP32 allow data to be exchanged between it and an Android smartphone.
STEP 1: Required Hardware and Software
1. ESP32 Development Board
2. PC (with Arduino IDE)
3. BMP280 sensor (any sensor will suffice)
4. Jumper wires
5. Breadboard
6. Android Smartphone (with Serial Bluetooth Terminal)
STEP 2: Circuit Assembling
Since BMP280 using I2C protocol, I will be using 4 pins. The pins are shown in picture below.
The code will be shown below.
We include 3 libraries, those are "Wire.h" for I2C, "Adafruit_BMP280.h" for BMP280, and "BluetoothSerial.h" for bluetooth. Then initialize variable needed.
For the setup, begin the serial and serial Bluetooth. I will be using "ESP32" for its name. Then initialize the BMP280 sensor.
For the loop, it will print in Serial Bluetooth every 5000 ms the measurement from the BMP280 sensor.
STEP 4: Uploading and Connecting
Pair the ESP32 devices in Bluetooth settings then open devices in the app, then select the ESP32.The measurement then will be send into the Android smartphone as shown below.
Bluetooth Low Energy (BLE)
This second section of the article will show how to use the Bluetooth Low Energy using ESP32 and Arduino IDE.
STEP 1: Required Hardware and Software
1. ESP32 Development Board
2. PC (with Arduino IDE)
3. Android Smarpthone (with nRF Connect)
STEP 2: Source Code
Since we will be using only ESP32, there will be no circuit assembly. For the source code, you can go to File > Examples > ESP32 BLE Arduino > BLE_server. The code will open as shown below.
STEP 3: Uploading the Code
After verifying the code, upload it into ESP32. For the smartphone, make sure to install nRF Connect.
After installing the app, open it and go to Scanner section. Find the device name then click connect.
After it connected, go to its tab and open the client. Find the Unknown Service and click it. It should have 2 properties, read and write. Click the download button for the read and it will show the message.
After it connected, go to its tab and open the client. Find the Unknown Service and click it. It should have 2 properties, read and write. Click the download button for the read and it will show the message.
Comments
Post a Comment