💻 Programacion de Hardware

ESP32 usando Bluetooth clásico (Serial Bluetooth).

ESP32 usando Bluetooth clásico (Serial Bluetooth).

JH
Jorge Henao · 26 de marzo de 2026 · 5 min de lectura · 3 visitas
Bluetooth.ino
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

int ledPin = 2; // GPIO donde está el LED

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_BT"); // Nombre del Bluetooth

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  Serial.println("Bluetooth listo, esperando datos...");
}

void loop() {
  if (SerialBT.available()) {
    char dato = SerialBT.read(); // Lee un carácter

    Serial.print("Recibido: ");
    Serial.println(dato);

    if (dato == 'A') {
      digitalWrite(ledPin, HIGH); // Enciende LED
    } else {
      digitalWrite(ledPin, LOW);  // Apaga LED
    }
  }
}
1) Ejercicio Enviar "A" alterna (toggle) → apaga / enciende
Bluetoothuno.ino
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

int ledPin = 2;
bool estadoLED = false; // false = apagado, true = encendido

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_BT");

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
}

void loop() {
  if (SerialBT.available()) {
    char dato = SerialBT.read();

    if (dato == 'A') {
      estadoLED = !estadoLED; // Cambia estado

      digitalWrite(ledPin, estadoLED ? HIGH : LOW);

      Serial.print("Estado LED: ");
      Serial.println(estadoLED ? "ENCENDIDO" : "APAGADO");
    }
  }
}