Control and Monitor Sensor Data on ESP32 Using Blynk BLE

This is my first time trying Bluetooth or BLE in Blynk app.

Introduction

When we talk about Blynk apps, it’s very common with IoT projects. However, do you know that we can also use Bluetooth or BLE in this application?

Video

This video shows how to use BLE in Blynk app with ESP32.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is Arduino sample program for ESP32 to be controlled or monitor via BLE in Blynk.

/*
Tutorial: Control and Monitor Sensor Data on ESP32 Using Blynk BLE
Board: ESP32 Dev Module (Hibiscus Sense ESP32)
https://my.cytron.io/p-hibiscus-sense-esp32-iot-development-board?tracking=idris
External libraries:
– Blynk by Volodymyr Shymanskyy V0.6.1
– Adafruit NeoPixel by Adafruit V1.7.0
– Adafruit BME280 by Adafruit V2.1.2
*/
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <Adafruit_NeoPixel.h>
#include <Adafruit_BME280.h>
#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>
Adafruit_NeoPixel rgb(1, 16);
Adafruit_BME280 bme;
char auth[] = "YourAuthToken";
long prevMillis = 0;
int red, green, blue;
boolean colorChange = false;
BLYNK_WRITE(V0)
{
red = param[0].asInt() / 10;
green = param[1].asInt() / 10;
blue = param[2].asInt() / 10;
colorChange = true;
}
void setup()
{
// Debug console
Serial.begin(115200);
rgb.begin();
if (!bme.begin()) {
Serial.println("Failed to find Hibiscus Sense BME280 chip");
}
Serial.println("Waiting for connections…");
Blynk.setDeviceName("Blynk");
Blynk.begin(auth);
rgb.show();
}
void loop()
{
Blynk.run();
if (colorChange == true) {
colorChange = false;
rgb.setPixelColor(0, red, green, blue);
rgb.show();
Serial.print("RGB color updated!");
}
if (millis() – prevMillis > 2000) {
float pressure = bme.readPressure() / 100;
float humidity = bme.readHumidity();
float temperature = bme.readTemperature();
Serial.print("Barometric Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
Blynk.virtualWrite(1, pressure);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Blynk.virtualWrite(2, humidity);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
Blynk.virtualWrite(3, temperature);
Serial.println();
prevMillis = millis();
}
}

view raw
ESP32BlynkBLE.ino
hosted with ❤ by GitHub

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

micro:bit Quick Start Kit
Design 3D Model Using TinkerCAD and Print
3D Print Lithophane for Hari Raya Aidilfitri
With Raspberry Pi Imager, you can write Raspberry Pi OS and remote SSH easier
3D Printing Pelita Raya
Tutorials of Cytron Technologies Scroll to Top