El visualizador de siete segmentos (llamado tambin display por calco del ingls,
aunque no recomendado en espaol1 2 ) es una forma de representar nmeros en
equipos electrnicos. Est compuesto de siete segmentos que se pueden encender o
apagar individualmente. Cada segmento tiene la forma de una pequea lnea. Se
podra comparar a escribir nmeros con cerillas o fsforos de madera.
Pruebe con letras Ideas para que aplicaciones se puede usar esto
int A=2;
int B=3;
int C=4;
int D=5;
int E=6;
int F=7;
int G=8;
void setup()
{ pinMode(A,OUTPUT);//A
pinMode(B,OUTPUT);//B
pinMode(C,OUTPUT);//C
pinMode(D,OUTPUT);//D
pinMode(E,OUTPUT);//E
pinMode(F,OUTPUT);//F
pinMode(G,OUTPUT);//G
}
void borra()
{ digitalWrite(A,LOW);//A
digitalWrite(C,LOW);//C
digitalWrite(D,LOW);//D
digitalWrite(E,LOW);//E
digitalWrite(F,LOW);//F
digitalWrite(G,LOW);//G
}
void cero()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,HIGH);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,LOW);//G
}
void uno()
{ digitalWrite(A,LOW);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,LOW);//D
digitalWrite(E,LOW);//E
digitalWrite(F,LOW);//F
digitalWrite(G,LOW);//G
}
void dos()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,LOW);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,HIGH);//E
digitalWrite(F,LOW);//F
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -248
digitalWrite(G,HIGH);//G
}
void tres()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,LOW);//E
digitalWrite(F,LOW);//F
digitalWrite(G,HIGH);//G
}
void cuatro()
{ digitalWrite(A,LOW);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,LOW);//D
digitalWrite(E,LOW);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,HIGH);//G
}
void cinco()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,LOW);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,LOW);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,HIGH);//G
}
void seis()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,LOW);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,HIGH);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,HIGH);//G
}
void siete()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,LOW);//D
digitalWrite(E,LOW);//E
digitalWrite(F,LOW);//F
digitalWrite(G,HIGH);//G
}
void ocho()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -249
digitalWrite(E,HIGH);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,HIGH);//G
}
void nueve()
{ digitalWrite(A,HIGH);//A
digitalWrite(B,HIGH);//B
digitalWrite(C,HIGH);//C
digitalWrite(D,HIGH);//D
digitalWrite(E,LOW);//E
digitalWrite(F,HIGH);//F
digitalWrite(G,HIGH);//G
}
void loop()
{ //cero(); //uno(); //dos(); //tres(); //cuatro(); // cinco(); //seis(); // siete(); //ocho();
nueve();
delay(10);
}
Modifique el programa que cuente en forma regresiva, que se ingrese por el puerto
serial
Modifique
void loop()
{ //cero(); //uno(); //dos(); //tres(); //cuatro(); // cinco(); //seis(); // siete(); //ocho();
int i;
for (i=0;i<8;i++ )
{ digitalWrite(2+i,HIGH);//
delay(100);
digitalWrite(2+i,LOW);//
}
int fila,col;
// {a,b,c,d,e,f,g letras
int A[11][7]={1,1,1,1,1,1,0,//0
0,1,1,0,0,0,0,//1
1,1,0,1,1,0,1,//2
1,1,1,1,0,0,1,//3
0,1,1,0,0,1,1,//4
1,0,1,1,0,1,1,//5
1,0,1,1,1,1,1,//6
1,1,1,0,0,0,0,//7
1,1,1,1,1,1,1,//8
1,1,1,1,0,1,1,//9
0,0,0,0,0,0,0};//10 es para borrar
void setup()
{for(col=0;col<7;col++) pinMode(col+2,OUTPUT);
}
void loop()
{ // for(fila=0;fila<10;fila++)
for (fila=0;fila<=9;fila++)
{ for(col=0;col<7;col++)
digitalWrite(col+2,A[fila][col]);
delay(200);
for(col=0;col<7;col++)
digitalWrite(col+2,A[10][col]);
delay(20);
}
}
Resultado lo mismo
Que solo cuente cuando se presiona el pulsador
CODIGO EN ARDUINO
int A[11][7]={1,1,1,1,1,1,0,//0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // dos
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, //4
1,0,1,1,0,1,1, //5
1,0,1,1,1,1,1,// 6
1,1,1,0,0,0,0,// 7
1,1,1,1,1,1,1,// 8
1,1,1,1,0,1,1,// 9
0,0,0,0,0,0,0 // para borrar el cero
};
int C1 = 9,C2 = 10;
int cont=0;
int unidades, decenas,i;
int pulsador =A0;
void setup() {
for (i=2; i<9;i++)
pinMode(i, OUTPUT);
pinMode(C1, OUTPUT);
pinMode(C2, OUTPUT);
pinMode(pulsador, INPUT);
}
void imprimir(int fnro, int valor)
{
switch(valor)
{case 0:
digitalWrite(C1,1); // turn the LED on (HIGH is the voltage level)
digitalWrite(C2, 0); // turn the LED on (HIGH is the voltage level)
break;
case 1:
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -253
void loop() {
int resultado=0;
decenas=cont/10;
unidades=cont % 10;
for (i=1;i<=10;i++)
{ imprimir(decenas,1);
delay(10);
imprimir(unidades,0);
delay(10);
}
resultado=digitalRead(pulsador);
delay(10);
if (resultado==LOW)
{borrar();
if (cont <99)cont++;else cont=0;
}
}
}
Tierra es en el medio
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -254
int A[11][7]={1,1,1,1,1,1,0,//0
0,1,1,0,0,0,0, // 1
1,1,0,1,1,0,1, // dos
1,1,1,1,0,0,1, // 3
0,1,1,0,0,1,1, //4
1,0,1,1,0,1,1, //5
1,0,1,1,1,1,1,// 6
1,1,1,0,0,0,0,// 7
1,1,1,1,1,1,1,// 8
1,1,1,1,0,1,1,// 9
0,0,0,0,0,0,0 // para borrar el cero
};
int CUnidades = 9; // unidades
int CDecenas = 10;// decenas
int CCentenas= 11; // centenas poner en su lugar para que funcinone
int pulsador=A0;
int reset =A1;
int i,cont=0;
int lectura =0;
void setup() {
for (i=2; i<9;i++)
pinMode(i, OUTPUT);
pinMode(CUnidades, OUTPUT); // unidades
pinMode(CDecenas, OUTPUT);//decenas
pinMode(CCentenas, OUTPUT);//centenas
pinMode(pulsador, INPUT);
Serial.begin(9600);
}
void imprimir(int fnro, int valor)
{
switch(valor) // si es unidades , decenas, o cengenas
{case 0: // unidades
digitalWrite(CUnidades,1); // turn the LED on (HIGH is the voltage level)
digitalWrite(CDecenas,0); // turn the LED on (HIGH is the voltage level)
digitalWrite(CCentenas,0); // turn the LED on (HIGH is the voltage level)
break;
case 1: //DECENA
digitalWrite(CUnidades,0); // turn the LED on (HIGH is the voltage level)
digitalWrite(CDecenas, 1); // turn the LED on (HIGH is the voltage level)
digitalWrite(CCentenas, 0); // turn the LED on (HIGH is the voltage level)
break;
case 2: //centenas
digitalWrite(CUnidades,0); // turn the LED on (HIGH is the voltage level)
digitalWrite(CDecenas, 0); // turn the LED on (HIGH is the voltage level)
digitalWrite(CCentenas, 1); // turn the LED on (HIGH is the voltage level)
break;
}
digitalWrite(2, A[fnro][0]);
digitalWrite(3, A[fnro][1]);
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -255
digitalWrite(4, A[fnro][2]);
digitalWrite(5, A[fnro][3]);
digitalWrite(6, A[fnro][4]);
digitalWrite(7, A[fnro][5]);
digitalWrite(8, A[fnro][6]);
}
void borrar()
{ // es al revez por que estrada
for(int col=0;col<7;col++)
digitalWrite(col+2,A[10][col]);
}
void loop()
{ lectura=digitalRead(pulsador);
delay(10);
if (lectura==LOW)
{ borrar();
if (cont <999 ) cont++;
}
if (digitalRead(reset)==LOW)
{ cont=0;
}
int Unidades = cont %10 ;
int Decenas = (cont % 100) / 10 ;
int Centenas = (cont % 1000) / 100 ;
{ imprimir( Unidades, 0);//unidades
delay(10);
imprimir( Decenas, 1);//unidades//
delay(10);
imprimir( Centenas, 2);//unidades//
delay(10);
}
}
LCD Revisar
http://elcajondeardu.blogspot.pe/2013/12/tutorial-conectando-una-pantalla-lcd.html
Esta pantalla funciona gracias al famoso y superconocido chip HD44780 que se utiliza
en infinidad de proyectos.Bien, veamos los pines:
VSS que es el pin de negativo o masa o 0 volts o GND.
VDD es la alimentacin principal de la pantalla y el chip, lleva 5 volts.
VO es el contraste de la pantalla, debe conectarse con un potenciometro de unos
10k ohms o una resistencia fija una vez que encontremos el valor deseado de
contraste. Tengan en cuenta que si no conectan esto, no vern nada.
RS es el selector de registro (Register select).
RW es el pin que comanda la lectura/escritura. En nuestro caso siempre estar en
0 (conectado a GND) para que escriba en todo momento.
E es enable, habilita la pantalla para recibir informacin.
D0~D3 no los vamos a utilizar. Como pueden ver la pantalla tiene un bus de datos
de 8 bits, de D0 a D7. Nosotros solamente utilizaremos 4 bits, de D4 a D7.
A y K son los pines del led del backlight de la pantalla. A se conectar a 4 o 5 volts
y K a gnd.
Habiendo conocido los pines del modulito HD44780, conectemoslo a Arduino, primero
el hardware:
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -258
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
Luego podemos utilizarla como en cualquier otro proyecto:
void setup() {
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Hola! ");
}
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -259
#include <LiquidCrystal.h>
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -260
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
void setup() {
lcd.begin(16, 2);
lcd.print("HOLA MUNDO");
}
void loop()
{
}
CODIGO EN ARDUINO
char Str[12] = {'H', 'o', 'l', 'a', ',', ' ', 'M','u','n','d','o','!'};
int posicion = 0;
#include <LiquidCrystal.h> // incluimos la libreria LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// inicializamos los pines
void setup() {
lcd.begin(16, 2); //Cofiguramos el tamao de la LCD
}
void loop() {
while (posicion < 12) { //Configuramos la estructura con la
//cantidad de posiciones de la cadena
lcd.cursor(); //Activamos el apuntador
lcd.setCursor(posicion, 0); //Rotamos las columnas
lcd.print(Str[posicion]); //imprimimos la posicion de la cadena
delay (100); //Retardo entre posiciones
posicion++; //Rotamos la posion de la cedena
}
posicion = 0; //Colocamos la posicion de la cadena
delay(100); //Retardo de impresion del mensaje
lcd.clear(); //Borramos todos los datos de la lCD
}
5 .Ejemplo de autoscroll
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -262
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
}
void loop() {
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
lcd.setCursor(16,1);
// set the display to automatically scroll:
lcd.autoscroll();
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear();
}
6 Cursor no cursor
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -263
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
lcd.noCursor();
delay(500);
// Turn on the cursor:
lcd.cursor();
delay(500);
}
7 Caracteres personalizados
8 Scrooll
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -264
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
byte frownie[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};
byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};
byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -265
0b01110,
0b00100,
0b00100,
0b01010
};
void setup() {
// create a new character
lcd.createChar(0, heart);
// create a new character
lcd.createChar(1, smiley);
// create a new character
lcd.createChar(2, frownie);
// create a new character
lcd.createChar(3, armsDown); // create a new character
lcd.createChar(4, armsUp);
// set up the lcd's number of columns and rows:
lcd.begin(16, 2); // Print a message to the lcd.
lcd.print("I "); // lcd.write(0);
lcd.print(" Arduino! ");
}
void loop() {
// read the potentiometer on A0:
int sensorReading = analogRead(A0);
// map the result to 200 - 1000:
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
// set the cursor to the bottom row, 5th position:
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(3);
delay(delayTime);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(4);
delay(delayTime);
}
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -266
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
const int numRows = 2;
const int numCols = 16;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(numCols,numRows);
}
void loop() {
// loop from ASCII 'a' to ASCII 'z':
for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
// loop over the columns:
for (int thisCol = 0; thisCol < numRows; thisCol++) {
// loop over the rows:
for (int thisRow = 0; thisRow < numCols; thisRow++) {
// set the cursor position:
lcd.setCursor(thisRow,thisCol);
// print the letter:
lcd.write(thisLetter);
delay(200);
}
}
}
}
9. Direccion de texto
void loop() {
// reverse directions at 'm':
if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}
// print the character
lcd.write(thisChar);
delay(1000);
thisChar++;
}
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
void setup() {
lcd.createChar(0, smiley);
lcd.begin(16, 2);
lcd.write(byte(0));
}
void loop() {}
#include <LiquidCrystal.h>
float x=2.34,y=3.1;
float suma;
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
void setup() {
lcd.begin(16, 2);
suma=x+y;
}
void loop() {
lcd.setCursor(0,0); lcd.print("X=");
lcd.setCursor(3,0); lcd.print(x);
lcd.setCursor(9,0);
lcd.print("Y=");
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -269
lcd.setCursor(12,0);
lcd.print(y);
lcd.setCursor(0,1);
lcd.print("SUMA=");
lcd.setCursor(8,1);
lcd.print(suma);
}
#include <LiquidCrystal.h>
#include <stdio.h>
char s1[10][16]={"0000000**#00000",
"000000***00000",
"0000******0000",
"00*0*******000",
"00**********00",
"00#**********0",
"0*#*#*********",
"##############",
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -270
"0############",
"00#########0"};
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
void setup() {
lcd.begin(16, 2);
}
void loop() {
int fila;
for (fila=0;fila<9;fila++)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print(s1[fila]);
lcd.print(s1[fila+1]);
delay(200); lcd.setCursor(0,1);
}
}
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
int entrada = A0;
void setup() {
lcd.begin(16, 2); //nci
}
void loop() {
float x,y;
lcd.print(" X Y");
for (x=-3;x<=3;x=x+0.1)
{ y=x*x;
lcd.print(x);
lcd.print(y);
delay(200);
}
}
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -271
#include <LiquidCrystal.h>
#include <string.h>
const int np=400;
int lc;
char cadena[np]="**UNIVERSIDAD NACIONAL DE SAN AGUSTIN DE AREQUIPA
INGENIERIA INDUTERIAL AUTOMATIZACION INDUsTRIAL 2014 B ***";
LiquidCrystal lcd(11, NULL, 12, 7, 8, 9, 10);
void setup() {
lcd.begin(16, 2); //nci
lc=strlen(cadena);
}
void loop() {
int i,j;
for(i=0;i<lc;i++)
{ //lcd.clear();
for (j= 0 ; j<=15;j++)
{lcd.setCursor(j,0);
lcd.print(cadena[i+j]);
}
delay(200);
}
}
Tarea.
Hacer otras aplicaciones
Como se puede leer un archivo de texto
Tarea se revisara esto mas antes de los sensores : 16.581.375 colores posibles.
Ejercicio Aleatorio Sicodelico
Programa
int Azul=9;
int Verde=10;
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -273
int Rojo=11;
void setup()
{ pinMode(Azul, OUTPUT);
pinMode(Verde, OUTPUT);
pinMode(Rojo, OUTPUT);
}
void loop()
{
Color(random(255), random(255), random(255)) ;
delay(500);
}
19 TECLADOS MATRICIALES
Arduino y los keypads de 4x4
Un antiguo telfono mvil roto se puede desmontar y usar su teclado adems de otras
cosas, y se puede utilizar de la forma que hemos descrito.
5 4 3 2
10 7 8 9 /
9 4 5 6 X
8 1 2 3 -
7 * 0 = +
void loop()
{ char pulsacion = Teclado1.getKey() ;
if (pulsacion != 0) // Si el valor es 0 es que no se
Serial.println(pulsacion); // se ha pulsado ninguna tecla
}
Alcanzara hasta de 6 x 6 osea 36 teclas (sobrando las analgicas
#include<Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
const byte filas = 4;
const byte columnas = 4;
byte pinesF[filas] = {11,10,9,8};
byte pinesC[columnas] = {7,6,5,4};
char teclas[filas][columnas] = {
{'7','8','9','/'},
{'4','5','6','X'},
{'1','2','3','-'},
{'*','0','=','+'}
};
Keypad teclado = Keypad(makeKeymap(teclas), pinesF, pinesC, filas, columnas);
char tecla;
void setup() {
// lcd.begin(16, 2);
lcd.print("HOLA MUNDO");
// Serial.begin(9600);
}
void loop() {
tecla = teclado.getKey();
//switch(tecla)
if (tecla != 0) // lcd.print(tecla);
{ if (tecla =='*')
lcd.clear();
else
lcd.print(tecla);
}
}
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -277
PROGRAMA
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
char Cadena[10]="R123";
char dato;
char letra;
int nro,i;
int Rojo=11;
int Verde=10;
int Azul=9;
int valor=0;
void setup() {
pinMode(Rojo,OUTPUT);
pinMode(Verde,OUTPUT);
pinMode(Azul,OUTPUT);
lcd.begin(16, 2);
lcd.print("COLORES RGB");
Serial.begin(9600);
}
void loop()
{ i=0;
if (Serial.available() > 0)
{ valor=1;
while (Serial.available() > 0)
{
dato= Serial.read();
delay(5);
if (i==0 )
letra=dato;
else
Cadena[i-1]=dato;
i++;
}
Cadena[i-1]='\n';
Serial.println(Cadena);
nro = atoi(Cadena) ;
i=0;
}
if (valor==1)
{
Serial.print(letra);
// Serial.println(Cadena);
lcd.clear();
lcd.setCursor(0, 0);
switch(letra)
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -278
ESQUEMA
13 TRANSISTORES
EL TRANSISTOR
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -279
Los grifos, tiene tres partes: entrada, salida y control. Los transistores igual, pero se
llaman emisor, colector y base (E, C, B).
: P2N2222.
INDUCTORES O BOBINAS
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -281
Inductancia
Propiedad de los circuitos elctricos por la cual se produce una fuerza electromotriz
cuando vara la corriente que pasa, ya por el propio circuito (autoinduccin), ya por otro
circuito prximo a l (induccin mutua).
"la inductancia se mide en henrios"
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -282
Oposicin al paso de una corriente alterna que ofrece una inductancia pura o una
capacidad en un circuito; se expresa en ohms.
La bombilla tarda un poco en encenderse, mostrando que lleva algo de tiempo
para la corriente a travs de un Inductor para aumentar a su nivel mximo.
. Mediante una seal de control de poca intensidad que excite la bobina podemos
conmutar grandes tensiones o intensidades.
RELES
En este nuevo post vamos a hablar de como hacer funcionar un rel con Arduino, en
primer lugar necesitamos saber que un rel es un dispositivo que funciona como un
interruptor, permitiendo la activacin o des-activacin de un circuito elctrico
independiente, es decir, podemos activar aparatos electrnicos de mayor voltaje y gran
consumo a travs de nuestros microcontroladores (como por ejemplo encender una
bombilla que funciona a 220V a travs de nuestro microcontrolador).
Yo para este tutorial he empleado unos rels de la casa HUI KE que funcionan a 5V y
comprados por ebay a un precio muy reducido, en concreto HUI KE HK4100F-DC5V-
SHG, os pongo unas imagenes y las conexiones interiores:
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -284
Como podis ver estos rels son de muy reducido tamao y perfectos para trabajar con
nuestro microcontroladores, ya que funcionan a 5V, sin necesidad de disponer de
fuentes externas para activar su bobina. Os dejo el esquema de conexin realizado en
Fritzing y un esquemtico realizado en Eagle:
Hardware:
1. Un Arduino Yun.
2. Un rel de 5V.
3. Cables macho-hembra para conectar el rel a nuestro arduino.
4. Un cable micro usb para transferir el sketch y darle corriente al Yun.
5. Una bombilla.
6. Un dispositivo Android (telfono, tablet) para programar.
7. Una red local (nuestra red domstica sirve) con posibilidad de conexin Wifi.
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -285
https://vimeo.com/121592511
Ejemplo de Relay 3 Esto muestra el mismo efecto que el circuito 2, pero si el valor de
la resistencia variable es demasiado grande, entonces la corriente a travs de la bobina
del rel no es lo suficientemente grande para activar el rel y la luz en el el circuito
secundario no est encendido.
http://electroprofano.blogspot.pe/2013/01/proyecto-relee-control-lampara.html
CON ARDUINO
Programa en arduino
int reset = 9;
int paro = 10;
int clock = 11;
int boton=2;
void setup() {
pinMode(reset, OUTPUT);
pinMode(paro, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(boton, INPUT);
}
void loop() {
if (digitalRead(boton)) digitalWrite(paro, HIGH);
else digitalWrite(paro, LOW);
digitalWrite(clock, HIGH);
delay(20);
digitalWrite(clock, LOW); // turn the LED on (HIGH is the voltage level)
delay(20);
}
20 BUZZERS O ZUMBADORES
Sonido bsico con Arduino
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -291
Cuando se acciona, la corriente pasa por la bobina del electroimn y produce un campo
magntico variable que hace vibrar la lmina de acero sobre la armadura. (Fuente:
Wikipedia)
Cristales de cuarzo
Si conectamos un piezo con una seal digital, vibran a una frecuencia sigue bastante
fielmente la variacin elctrica con que los excita, y si vibran a la frecuencia audible,
oiremos el sonido que producen. A un componente que hace esto, le llamamos Buzzer
o zumbador.
Qu pasa si quiero generar seales de tono variable para hacer una meloda? Bueno
pues Arduino dispone de la funcin tone() que genera una seal de la frecuencia
indicada, y notone() que la corta:
Ahora vayamos un poco ms all. Si tienes nociones bsicas de msica ser fcil
trastear con el cdigo consiguiendo que nos reproduzca melodas de forma digital.
// Introducimos la variable por donde saldr nuestra seal digital hasta el zumbador
int speakerPin = 12;
// Definimos una variable con el nmero de tonos que va a reproducir
int numTones = 10;
int song[] = {261, 349, 392, 440, 392, 330, -10, 261, 349, 392, 440, 392, -10, -10, 261,
349, 392, 440, 392, 330, -10, 330, 349, 330, 261, 261};
// int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};
// mid C C# D D# E F F# G G# A
// Arriba se muestran las equivalencias entre frecuencias y Notas de la escala natural,
no estn todas declaradas pero existen. Uso una frecuencia de -10 para generar un
sonido que apenas se oiga y que sustituya al silencio que debera sonar en la meloda.
Os invito a que compartis una solucin mejor para evitar que suene el buzzer en esa
posicin.
Arduino - Generando Sonido
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -294
Anteriormente realice una practica con arduino, la cual era prender y apagar un LED,
aqui una nueva entrada, donde explicare como realice otra practica con arduino, el cual
consiste en generar sonido con un Buzzer de 12mm y un Potenciomentro rotacional
Lineal.
Material
Arduino Uno
Un Buzzer 12 mm 2.048kHz
Potenciometro
Cables
Protoboard
Nuevamente, fue necesario hacer uso de un protobard para abarcar mas espacio para
mas conexiones.
Montaje de Circuito:
MODIFICADO
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, NULL, 6, 5, 4, 3, 2);
int ERojo =A0;
GP DE AIL 2017B\4 7SEG.-LCD Teclado Matricial\-Ismael Vliz Vilca -296
int NRojo=20;
void setup() {
pinMode(ERojo,INPUT);
lcd.begin(16, 2);
}
void loop() {
int VRojo;
lcd.clear();
VRojo=analogRead(ERojo);
NRojo=map(VRojo,0,1024,0,255);
lcd.setCursor(0,0);
lcd.print("R:");
lcd.setCursor(4,0);
lcd.print(NRojo);
delay(10);
MODIFICADO
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, NULL, 6, 5, 4, 3, 2);
int ERojo =A0;
int EVerde =A1;
int EAzul =A2;
int VRojo, NRojo,VVerde, NVerde;
void setup() {
pinMode(ERojo,INPUT);
pinMode(EVerde,INPUT);
lcd.begin(16, 2);
}
void loop() {
lcd.clear();
VRojo=analogRead(ERojo);
NRojo=map(VRojo,0,1024,0,255);
lcd.setCursor(0,0);
lcd.print("R:");
lcd.setCursor(2,0);
lcd.print(NRojo);
VVerde=analogRead(EVerde);
NVerde=map(VVerde,0,1024,0,255);
lcd.setCursor(6,0);
lcd.print("V:");
lcd.setCursor(8,0);
lcd.print(NVerde);
delay(10);