ESP32 Tutorial (Bluetooth LE Server Receiver + Emitter)

by s4mir32N16 in Circuits > Arduino

250 Views, 4 Favorites, 0 Comments

ESP32 Tutorial (Bluetooth LE Server Receiver + Emitter)

logo.png

This is a guide on how you can use bluetooth LE as a Bluetooth Serial receiver,and sender


in bluetooth LE and Classic there are some differences between them

  • Bluetooth LE has a precision tracking
  • It uses less energy (A regular airtag with a coin battery takes up to 1 year to totally discharge)
  • Its used in alot of devices (Smartwatch,Printer,Wireless keyboard/Mouse,Headphones)


Special functions (I will release a other guide soon)

  1. Can track the battery
  2. Check blood pressure
  3. Alert notification service
  4. Automation IO


Why did i made this guide

 #error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.

 ^~~~~

Supplies

Any esp32 variant with Bluetooth or BLE

Arduino IDE

Optional

mybad.png
gotole.png

If you want to debug your bluetooth device before making your app,intall Serial Bluetooth Terminal by Kai Morich

if you already installed it and your bluetooth device is ready follow the steps

  1. At the upper-left corner at your screen,there will be a logo that opens a sidebar (hamburger icon)
  2. Devices
  3. Bluetooth LE
  4. Scan
  5. then you will find the esp32 bluetooth LE (Default : espcontroller)

Changing Your Code

guide1.png
guide2.png

if you want to customize your code,with your own bluetooth name,know where the message is going,if connected or disconnected,follow the steps provided by images.

At BLEDevice::init You can change your bluetooth device name

There are 3 events on the bluetooth server

  1. onconnect (if someone connected into the server,it will fire the event)
  2. onconnect (if someone disconnected into the server,it will fire the event)
  3. onWrite (if someone has sent data into the server,it converts into string then outputs it)

Compiling Your Android Code

denteazul.png
goodboy.png

The AIA File is from https://ai2.appinventor.mit.edu/

To compile your android code to confirm if its everything alright,follow the steps shown in this image

  • Get your bluetooth address in serial monitor and then paste it on Global address
  • if you want button only event,like lets think you added a single button no inputs,you could add a string block to make it send your own message that esp32 is added (previously said on if(txreceived == "led_on") )
  • Before compiling,test your application on mit ai2 companion and scan your qr code,to get the qr code on the pc press Connect > AI Companion,then connect so you can debug your application
  • After getting everything ready,press Build > Android app (.apk),and scan the qr code for the download link you made



Bonus

if you want to send message to client,add this into your code

    pCharacteristic->setValue("Hi client");
pCharacteristic->notify();

Finishing Everything

thanks.png

And thats how you can use a alternative to bluetooth with less energy use

Thanks for finishing this guide and i hope you have a easy coding!

Fact : First upload i ever made in this site

Source code :

https://www.mediafire.com/file/aehaaf6ojwd5qly/bluetoothle.aia/file

Downloads