Documentos de Académico
Documentos de Profesional
Documentos de Cultura
debes saber
by Admin | Jun 25, 2018 | Tutoriales Arduino | 8 comments
Casi cualquier aparato electrónico hoy en día incluye una tecla, botón, pulsador o
switch. Los proyectos con arduino no son la excepción y virtualmente cualquier
idea que desarrollemos dispondrá de al menos un par de botones.
En este tutorial hablaremos sobre como se puede conectar un botón al
arduino y como podemos hacer para procesar correctamente las señales que
envían. Además veremos como realizar aplicaciones más avanzadas con
botones, por ejemplo: como detectar pulsaciones largas, doble o triple clic,
etc.
Materiales necesarios para las prácticas
Para completar los ejercicios propuestos en esta página recomendamos adquirir
los siguiente materiales:
Arduino Uno R3 o compatible
Protoboard
Resistencias de 10 K ohms
Botones pulsadores o push-buttons
Utilizaremos el led en el pin 13 del arduino para realizar las prácticas sin la
necesidad de conectar leds externos.
¿Cómo conectar un botón a arduino?
Para conectar un botón al arduino conviene tener en mente ciertos puntos:
Un botón puede conectarse a cualquier pin de arduino (digital o analógico,
ya que los analógicos usualmente funcionan también como digitales).
Existen dos configuraciones posibles: con resistencia pull-up o
resistencia pull-down.
Configuraremos el pin seleccionado como entrada digital.
Debemos tomar en cuenta los rebotes y el ruido eléctrico en el software.
Es necesario utilizar una resistencia pull-up o pull-down, ya sea interna o
externa.
Las dos formas que existen para conectar un botón al arduino se visualizan en los
siguientes diagramas:
// ASIGNACION DE PINES
const int pinon = 2;
const int pinoff = 3;
const int pinled = 13;
void setup() {
// CONFIGURAR PINES COMO ENTRADAS
pinMode(pinon, INPUT);
pinMode(pinoff, INPUT);
// CONFIGURAR PIN DE LED COMO SALIDA
pinMode(pinled, OUTPUT);
}
void loop() {
// LEER EL ESTADO DE PINES DE BOTON A VARIABLES
estaon = digitalRead(pinon);
estaoff = digitalRead(pinoff);
// ASIGNACION DE PINES
const int pinon = 2;
const int pinoff = 3;
const int pinled = 13;
void setup() {
// CONFIGURAR PINES COMO ENTRADAS
pinMode(pinon, INPUT);
pinMode(pinoff, INPUT);
// CONFIGURAR PIN DE LED COMO SALIDA
pinMode(pinled, OUTPUT);
}
void loop() {
// LEER EL ESTADO DE PINES DE BOTON A VARIABLES
estaon = digitalRead(pinon);
estaoff = digitalRead(pinoff);
#include "GFButton.h"
// Create two button instances on pins 2 & 3
GFButton buttonOn(2);
GFButton buttonOff(3);
/**
PROGRAM INITIALIZATION
*/
void setup() {
// Prepare serial interface
Serial.begin(9600);
Serial.println(F("-------------------------------------------
---------"));
Serial.println(F(" GFBUTTON LIBRARY TEST PROGRAM
"));
Serial.println(F(" http://www.geekfactory.mx
"));
Serial.println(F("-------------------------------------------
---------"));
}
/**
MAIN PROGRAM LOOP
*/
void loop() {
// Check if "on" button is pressed
if (buttonOn.isPressed()) {
Serial.println(F("On button is pressed"));
// Turn on the led
digitalWrite(13, HIGH);
}
void setup() {
// PREPARAR COMUNICACION SERIAL
Serial.begin(9600);
Serial.println(F("-------------------------------------------
---------"));
Serial.println(F(" PROGRAMACION DE BOTONES CON LIBRERIA
GFBUTTON "));
Serial.println(F(" http://www.geekfactory.mx
"));
Serial.println(F("-------------------------------------------
---------"));
}
void loop() {
// SIEMPRE DEBEMOS LLAMAR AL METODO PROCESS DE CADA
INSTANCIA
btn1.process();
btn2.process();
void setup() {
// PREPARAR COMUNICACION SERIAL
Serial.begin(9600);
Serial.println(F("-------------------------------------------
---------"));
Serial.println(F(" PROGRAMACION DE BOTONES CON LIBRERIA
GFBUTTON "));
Serial.println(F(" http://www.geekfactory.mx
"));
Serial.println(F("-------------------------------------------
---------"));
}
void loop() {
// SIEMPRE DEBEMOS LLAMAR AL METODO PROCESS DE CADA
INSTANCIA
btn1.process();
btn2.process();