Streamline Your IoT Projects: ESP32-S3 Bluetooth to Android Data Exchange

Поделиться
HTML-код
  • Опубликовано: 3 июл 2024
  • Unlock the power of IoT with our guide to using the ESP32-S3 for Bluetooth data exchange with Android devices. Whether you're a student or a beginner eager to enhance your tech skills, this video will show you how to seamlessly integrate ESP32-S3 with an Android application, making your IoT projects smarter and more efficient.
    🔔🔔 SUBSCRIBE 🔔🔔 don't forget to subscribe and click the bell!
    / @bmonsterlaboratory
    Facebook: / bmonster-laboratory-10...
    see this Facebook post by searching #espiot on Facebook
    Twitter: / b_monsterlab
    check out our Arduino play list! We try to make it easy 👍
    • Easy Arduino projects ...
    Chapter:
    0:00 intro
    0:15 Freenove website
    0:34 items used in video
    0:47 what came in the box
    1:07 ESP32-s3 file download
    1:58 set up Arduino IDE preferences
    2:15 install ESP32 - IDE boards manager
    3:21 first setup
    3:39 BLE LED control sketch
    4:42 LightBlue Android App
    5:45 second setup
    6:38 BLE Temp/Humidity sketch
    7:39 LightBlue Android App (again)
    In this tutorial, we dive into the essentials of setting up the ESP32-S3, configuring Bluetooth Low Energy (BLE) communications, and connecting to an Android app to receive and send data. Learn step-by-step how to establish a robust Bluetooth connection and explore practical examples of data exchange techniques that you can implement right away. By the end of this session, you'll not only master ESP32 Bluetooth integrations but also gain valuable insights into streamlining your IoT solutions.
    This video is perfect for anyone interested in leveraging the powerful ESP32-S3 chip for home automation, environmental monitoring, or any smart device projects.
    Tags: #ESP32S3 #BluetoothLowEnergy #IoTProjects #AndroidDataExchange #TechTutorial #SmartDevices #WirelessCommunication #IoTConnectivity #StreamlineIoT #HomeAutomation
  • НаукаНаука

Комментарии • 3

  • @BMonsterLaboratory
    @BMonsterLaboratory  Месяц назад

    You will also want to install CH34SER.EXE if you don't have it. It is part of the Freenove tutorial download. Once you open the file, click the CH343 folder and download from there....I knew I was missing something! This is a nice and easy project to get familiar with the board. The goal is to use the camera and integrate the camera into various projects.....stay tuned 👍

  • @BMonsterLaboratory
    @BMonsterLaboratory  Месяц назад

    Here is the sketch I used in the video for temperature and humidity monitoring. It is not in the tutorial.
    /*
    BLE Environmental Monitor: An Arduino sketch for ESP32S3 that reads
    temperature and humidity using a DHT11 sensor and transmits the data via
    BLE to the LightBlue app for real-time monitoring on a smartphone.
    */
    #include "BLEDevice.h"
    #include "BLEServer.h"
    #include "BLEUtils.h"
    #include "BLE2902.h"
    #include
    #define DHT_PIN 15 // GPIO pin connected to the DHT11 sensor
    #define DHT_TYPE DHT11 // DHT11 sensor type
    // UUIDs for BLE services and characteristics
    #define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
    #define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
    DHT dht(DHT_PIN, DHT_TYPE);
    BLECharacteristic *pCharacteristicTX;
    bool deviceConnected = false;
    BLEServer *pServer;
    class MyServerCallbacks : public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
    deviceConnected = true;
    Serial.println("Device connected");
    };
    void onDisconnect(BLEServer* pServer) {
    deviceConnected = false;
    Serial.println("Device disconnected");
    // Start advertising again to allow auto-reconnection
    pServer->getAdvertising()->start();
    }
    };
    class MyCallbacks : public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
    std::string rxValue = pCharacteristic->getValue();
    if (!rxValue.empty()) {
    String command = String(rxValue.c_str());
    command.trim();
    command.toUpperCase();
    Serial.println("Command received: " + command);
    if (command == "ON") {
    // Handle other commands if needed
    } else if (command == "TEMP") {
    // Read temperature and humidity
    float humidity = dht.readHumidity();
    float temperatureC = dht.readTemperature();
    float temperatureF = (temperatureC * 9 / 5) + 32; // Convert Celsius to Fahrenheit
    // Check if any reads failed
    if (isnan(humidity) || isnan(temperatureF)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
    }
    // Prepare and send the data over BLE
    char tempHumidValue[40];
    sprintf(tempHumidValue, "T: %.1fF, H: %.1f%%", temperatureF, humidity);
    pCharacteristicTX->setValue(tempHumidValue);
    pCharacteristicTX->notify();
    Serial.print("Sent to app: ");
    Serial.println(tempHumidValue);
    }
    }
    }
    };
    void setupBLE(String BLEName) {
    BLEDevice::init(BLEName.c_str());
    pServer = BLEDevice::createServer();
    pServer->setCallbacks(new MyServerCallbacks());
    BLEService *pService = pServer->createService(SERVICE_UUID);

    pCharacteristicTX = pService->createCharacteristic(
    CHARACTERISTIC_UUID_TX,
    BLECharacteristic::PROPERTY_NOTIFY
    );
    pCharacteristicTX->addDescriptor(new BLE2902());

    pService->start();
    // Start advertising
    pServer->getAdvertising()->start();
    Serial.println("BLE advertising started. Waiting for a client connection...");
    }
    void setup() {
    Serial.begin(115200);
    dht.begin(); // Initialize the DHT sensor
    setupBLE("ESP32S3_Env_Monitor"); // Setup BLE with a specific device name for the environment monitoring
    }
    void loop() {
    delay(5000); // Wait for 5 seconds between readings
    // Read temperature and humidity
    float humidity = dht.readHumidity();
    float temperatureC = dht.readTemperature();
    float temperatureF = (temperatureC * 9 / 5) + 32; // Convert Celsius to Fahrenheit
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity) || isnan(temperatureF)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
    }
    // Prepare and send the data over BLE
    char tempHumidValue[40];
    sprintf(tempHumidValue, "T: %.1fF, H: %.1f%%", temperatureF, humidity);
    pCharacteristicTX->setValue(tempHumidValue);
    pCharacteristicTX->notify();
    Serial.print("Sent to app: ");
    Serial.println(tempHumidValue);
    }

  • @BMonsterLaboratory
    @BMonsterLaboratory  Месяц назад

    Here is the sketch for the Bluetooth LED control. You'll find it in the tutorial under Sketch_13.2
    /**********************************************************************
    Filename : BLE_USART
    Description : Esp32 communicates with the phone by BLE and sends incoming data via a serial port
    Auther : www.freenove.com
    Modification: 2022/10/26
    **********************************************************************/
    #include "BLEDevice.h"
    #include "BLEServer.h"
    #include "BLEUtils.h"
    #include "BLE2902.h"
    #include "String.h"
    BLECharacteristic *pCharacteristic;
    bool deviceConnected = false;
    uint8_t txValue = 0;
    long lastMsg = 0;
    char rxload[20];
    #define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
    #define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
    #define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
    #define LED 2
    class MyServerCallbacks : public BLEServerCallbacks {
    void onConnect(BLEServer *pServer) {
    deviceConnected = true;
    };
    void onDisconnect(BLEServer *pServer) {
    deviceConnected = false;
    }
    };
    class MyCallbacks : public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
    std::string rxValue = pCharacteristic->getValue();
    if (rxValue.length() > 0) {
    for (int i = 0; i < 20; i++) {
    rxload[i] = 0;
    }
    for (int i = 0; i < rxValue.length(); i++) {
    rxload[i] = (char)rxValue[i];
    }
    }
    }
    };
    void setupBLE(String BLEName) {
    const char *ble_name = BLEName.c_str();
    BLEDevice::init(ble_name);
    BLEServer *pServer = BLEDevice::createServer();
    pServer->setCallbacks(new MyServerCallbacks());
    BLEService *pService = pServer->createService(SERVICE_UUID);
    pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
    pCharacteristic->addDescriptor(new BLE2902());
    BLECharacteristic *pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE);
    pCharacteristic->setCallbacks(new MyCallbacks());
    pService->start();
    pServer->getAdvertising()->start();
    Serial.println("Waiting a client connection to notify...");
    }
    void setup() {
    pinMode(LED, OUTPUT);
    setupBLE("ESP32test");
    Serial.begin(115200);
    Serial.println("
    The device started, now you can pair it with Bluetooth!");
    }
    void loop() {
    long now = millis();
    if (now - lastMsg > 100) {
    if (deviceConnected && strlen(rxload) > 0) {
    if (strncmp(rxload, "led_on", 6) == 0) {
    digitalWrite(LED, HIGH);
    }
    if (strncmp(rxload, "led_off", 7) == 0) {
    digitalWrite(LED, LOW);
    }
    Serial.println(rxload);
    memset(rxload,0,sizeof(rxload));
    }
    lastMsg = now;
    }
    }