Connect ESP32 to Smartphone via Bluetooth

Bluetooth 12-11-24
45 0

Tutorial plan

1- The ESP32 board and Bluetooth

2- Why do we use App Inventor to create a mobile application capable of communicating the smartphone with the ESP32 board ?

3- Necessary components

4- Mounting the ESP32 board with SSD1306

5- ESP32 MicroPython Code

6- Develop  mobile application using MIT App Inventor

 

 

The ESP32 board and Bluetooth

The ESP32 is a popular microcontroller board that is known for its versatility and capabilities. It is based on the Espressif ESP32 system-on-chip (SoC), which includes both Wi-Fi and Bluetooth capabilities.

One of the key features of the ESP32 is its built-in support for both classic Bluetooth (often referred to as Bluetooth Classic) and Bluetooth Low Energy (BLE). This makes the ESP32 a powerful choice for projects that require wireless communication.

Here are some key points about using Bluetooth with the ESP32:

Bluetooth Classic (BR/EDR): This is the traditional Bluetooth protocol used for things like audio streaming, file transfer, and other applications. The ESP32 supports this protocol, allowing it to communicate with other devices that use Bluetooth Classic.

Bluetooth Low Energy (BLE): BLE is a power-efficient version of Bluetooth that is designed for applications like sensors, fitness trackers, and other low-power devices. The ESP32 includes support for BLE, which enables it to act as a BLE peripheral or central device.

Dual-mode Bluetooth: The ESP32 can operate in both Bluetooth Classic and BLE modes simultaneously. This means it can communicate with a wide range of devices using different Bluetooth protocols.

Bluetooth Profiles: The ESP32 supports various Bluetooth profiles, which define how devices communicate with each other. Common profiles include Serial Port Profile (SPP) for classic Bluetooth and Generic Attribute Profile (GATT) for BLE.

Programming the ESP32 for Bluetooth: To use Bluetooth functionality on the ESP32, you typically use a development environment like the Arduino IDE with the ESP32 board package installed, or use the Espressif IDF (IoT Development Framework) if you need more advanced control.

Libraries and SDKs: There are libraries and SDKs available for both Arduino and ESP-IDF that simplify the process of working with Bluetooth on the ESP32. These libraries provide high-level APIs for tasks like setting up a Bluetooth server, connecting to other devices, and exchanging data.

Applications: With Bluetooth capabilities, the ESP32 can be used in a wide range of projects. For example, you can create IoT devices that communicate with smartphones or other Bluetooth-enabled devices, build wearable devices, or even create custom controllers for applications like home automation.

 

Why do we use App Inventor to create a mobile application capable of communicating the smartphone with the ESP32 board ?

MIT App Inventor is a visual mobile app development platform used to create applications for Android devices. It's often utilized for building mobile applications that can communicate with ESP32 boards or other IoT devices for several reasons:

Ease of use: MIT App Inventor is designed to be user-friendly and intuitive, making it accessible even to individuals without advanced programming expertise. It employs a drag-and-drop programming approach, reducing the learning curve.

Rapid development: MIT App Inventor allows for the quick creation of mobile applications. This is particularly important in the IoT field where projects can evolve rapidly. You can rapidly design and test applications for interacting with your ESP32.

Connectivity support: MIT App Inventor provides pre-defined components and libraries for wireless communication, including Bluetooth communication. This makes it easy to create applications that can connect and interact with ESP32 boards through Bluetooth.

Cross-platform: Applications created with MIT App Inventor are intended for Android but can be used on various Android devices, making it a versatile solution for communicating with ESP32 boards that support Bluetooth communication.

Customization: While MIT App Inventor focuses on simplicity, it still offers a degree of customization. You can personalize the appearance and behavior of your application using the available components and programming blocks.

Community and resources: There is an active community around MIT App Inventor, with many online resources, tutorials, and examples available. This makes learning and troubleshooting easier.

 

Necessary components

To use a SSD1306 display with the ESP32 board, you'll need the following components:

ESP32 Board:

ESP32 card

The ESP32 is a powerful microcontroller developed by Espressif Systems. It's renowned for its integrated Wi-Fi and Bluetooth capabilities, making it a popular choice for various IoT (Internet of Things) applications.

SSD1306 display:

The SSD1306 display is a type of OLED (Organic Light-Emitting Diode) display that uses the SSD1306 driver chip.

Jumper Wires:

Jumper wires

To make the physical connections between the components.

Breadboard:

Test plate

A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering .

Mounting the ESP32 board with SSD1306

ESP32 board wiring diagram with SSD1306 displayESP32 board wiring diagram with SSD1306 display

Connect the SSD1306 Display to your ESP32 as follows:

1- Connect the SDA (data line) of the SSD1306 display to GPIO 21 of the ESP32 board.

2- Connect the SCL (clock line) of the SSD1306 display to GPIO 22 of the ESP32 board.

3- Connect the VCC pin of the SSD1306 display to the 3.3V pin of the ESP32 board.

4- Connect the GND pin of the SSD1306 display to GND pin of the ESP32 board.

 

ESP32 MicroPython Code

This example demonstrates how to set up the ESP32 to receive data from a smartphone using BLE and display it on the SSD1603.

The word ‘connect’ is displayed if the ESP32 board is connected to the smartphone and the word ‘disconnect’ otherwise.

1- Flash your ESP32 with MicroPython using this file esp32-20210902-v1.17.bin.

2- import this three libraries : ble_uart_peripheral.pyble_advertising.py and ssd1306.py

 

Develop  mobile application using MIT App Inventor

1. Creating the application with App Inventor:

Create a mobile app with App Inventor.

Use the available Bluetooth components to establish a connection with the ESP32.

- Add button Scanner to search ESP32 board.

- Add button Stop to stop the search.

- Add button Connect to connect to ESP32 board.

- Add button Disconnect to disconnect from ESP32 board.

Here is the Designer part of the application with App Inventor :

2. Programming the application with App Inventor:

a- Use the available blocks in App Inventor to establish a Bluetooth connection with the ESP32.

- Starting with Android 12, Bluetooth permissions have been enhanced to improve security and user data protection. This is why we must declare the authorizations that your application needs in the AndroidManifest.xml file. For Bluetooth, you'll need to include ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, and possibly BLUETOOTH_CONNECT permissions, depending on the features you're using.

- Use these programming blocks to connect the smartphone to the ESP32 board via Bluetooth:

Download project Download application

 

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info