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");
}
}
}