If you are just here for the explanation then you can skip this step but going through it might give you a bit more clarity..

First I am going to build an example project and then I’ll try to explain how it works and how you can replicate the Bluetooth communication. We'll be building a portable temperature sensor that sends a live feed to your smartphone. The build can run for days on a single li-po and easily demonstrates the benefits of BLE.

You can use the module as a coaster to insulate your drinks and get a notification as soon as your beverage reaches the optimal temperature. Because it would be a travesty if you had to sip a tea that was a degree above 40.

The only hardware you need is a ESP32 board and a digital temperature sensor. My board supports external battery so I am using a 3.7v li-po that I salvaged from some old device to make this project portable.

Hardware

The connections for the temperature sensor are simple. The red wire connects to 3.3v, black connects to ground(gnd), yellow connects to GPIO 2 which on my board is marked as D9. Connect a 4.7k ohm resistor between the red and yellow wire. I am not using the resistor, instead i am using a 3 pin plug-able terminal that came with my sensor. It has a built-in pull up resistor.

The li-po should really be connected using a JST connector but I couldn't be bothered to buy one so I just shoehorned in some (female to female) jumper cables into the connector and soldered another pair to the battery terminals. This makes for a reliable connection and a makeshift power switch.

Now as a project enclosure, I am using a Styrofoam disk that has been cut out from a larger sheet. This makes for a great insulator. Another much smaller disk is stuck on top but a bit to the side. This is for wrapping the extra length of wires so they are not dangling all over the place. After a generous employment of your glue and a small hole for the sensor probe, you are ready to proceed to the software.

Software

If you don't already have the arduino IDE installed then go to this link to download it. The arduino software by default doesn't come with the board definitions for the various ESP32 boards. To get them to go this link and download the files in a zip. You need to unzip them to this location:

C:/Users/<user-name>/Documents/Arduino/hardware/espserrif/ESP32

Where <user-name> is your user name on your PC. Make sure that the various files are available under the ESP32 folder and are not under another folder.

Now if you start the arduino software and go to tools->boards you should see various ESP32 boards when you scroll down.

Most digital temperature sensors use the OneWire protocol to communicate with the micro controllers so we need to get the library. Go to sketch->include library->manage libraries and search for onewire and install the library that is by way too many authors. You don't need the onewire hub. Ignore it.

Now you can download and open the code attached to this step (temperature-example.ino).

If you are using a different sensor from me then you will have to change the code accordingly. Replace the code under getTemp(). Just return the final temperature in the form of

Return <variable>;

Where is the float containing the temperature.

Plug in the board, select the correct board and port from under tools and hit upload.

If the code refuses to upload, disconnect the sensor and connect the GPIO 0 to ground. Restore the connections after the upload.

Your ESP should now be screaming the temperature of you coffee to the world but you need someone who can understand it.

The Android App

Sorry iPhone users (...not really).

Download the apk from here and install it. When you start the app you would be greeted with a very simple interface.

If you get a error message saying ‘advertising not supported’, click OK and ignore it but if you get a message that ‘BLE is not supported’ then your phone doesn't have Bluetooth 4.0 or higher and wouldn't be able to run the app.

Make sure that Bluetooth on your phone is on and click ‘Start Scanning’, as long as the esp is in range and powered on you should be receiving some temperature value.

Possible errors: