Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

ESP32 Code: Connect ESP32 to Bluetooth, work  and write and read commands

 

This code example shows whatyou can connect an ESP32 microprocessor to a smartphone and then send commands to control the application and read the jam.

 

ESP32 WROOM32 nodeMCU, Arduino, DevBoard, Serial Bluetooth

 

Example : Send Start via theSerialBluetooth connection to start the application on ESP32 nodeMCU

 

Then you start the app on your smartphone: Serial Bluetooth Terminal and connect the application of the smartphone to ESP32

 

 

Then you can enter a command like "Start" in the input line of Bluetooth Serial Terminal

 

Entering commands

After sending the text: Start

Shows the received text on the Serial Monitor  of Arduino IDE.

 

 

 

ESP32 Code: Simple code to test

 

#include "BluetoothSerial.h"

 

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)

#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it

#endif

 

BluetoothSerial SerialBT;  //Serial Bluetooth send and receive

String message = "";

 

 

 

void setup() {

    //----< setup() >------

    Serial.begin(115200); //*for local monitor

    SerialBT.begin("ESP32_Bluetooth"); //Bluetooth device name

    Serial.println("The device started, now you can pair it with bluetooth!");

    //----</ setup() >------

}

 

void loop() {

    //----< loop() >------

 

    //-< read Bluetooth >-

    // get command from smartphone

    if (SerialBT.available()) {

        char incomingChar = SerialBT.read();

        if (incomingChar != '\n') {

            message += String(incomingChar);

        }

        else {

            message = "";

        }

        Serial.write(incomingChar);

    }

    //-</ read Bluetooth >-

 

    //-< do command >-

    if (message == "Start") {

        Serial.println("Start");  //serial monitor

    }

 

    //-</ do command >-

    //----</ loop() >------

}

 

Mobile
»
Switch with ESP32 MosFET and high voltages with optocoupler
»
Solved: conversion from void to non-scalar type String requested bei String.replace und toLowerCase
»
Arduino Code: Declare an Enum Type, a Variable and Compare it
»
Connect ESP32 to Bluetooth, work and write and read commands
»
Solved: LCD shows strange signs on ESP32
»
Arduino : switch case

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de