Las entradas digitales son la base de cualquier sistema interactivo con microcontroladores. Entender cómo se interpreta el voltaje, cómo se estabiliza la señal y cómo se evitan lecturas erráticas es clave para diseñar sistemas confiables con ESP32.
Datasheet ESP 32-S3 DevkitC1 v1.1
Código de Arduino IDE:
// ------------------------------
// CONFIGURACIÓN DE PINES
// ------------------------------
const int pinLed = 4;
const int pinBoton = 5;
// ------------------------------
// VARIABLES DE CONTROL
// ------------------------------
bool estadoLed = false;
// Control de evento (evita múltiples toggles)
bool botonProcesado = false;
// Control de tiempo (antirrebote)
unsigned long tiempoInicio = 0;
const int tiempoAntirrebote = 50;
// ------------------------------
// CONFIGURACIÓN INICIAL
// ------------------------------
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinBoton, INPUT_PULLUP);
}
// ------------------------------
// BUCLE PRINCIPAL
// ------------------------------
void loop() {
bool lectura = digitalRead(pinBoton);
// ------------------------------
// DETECCIÓN DE INICIO DE PULSACIÓN
// ------------------------------
if (lectura == LOW && !botonProcesado) {
// Inicia conteo solo una vez
if (tiempoInicio == 0) {
tiempoInicio = millis();
}
// ------------------------------
// VALIDACIÓN DE ESTABILIDAD
// ------------------------------
if ((millis() - tiempoInicio) > tiempoAntirrebote) {
// Verifica si sigue presionado
if (digitalRead(pinBoton) == LOW) {
// Evento válido → toggle
estadoLed = !estadoLed;
digitalWrite(pinLed, estadoLed);
// Marca como procesado
botonProcesado = true;
}
}
}
// ------------------------------
// DETECCIÓN DE LIBERACIÓN
// ------------------------------
if (lectura == HIGH) {
// Resetea control para siguiente pulsación
botonProcesado = false;
tiempoInicio = 0;
}
}
Video explicativo:
![]()



