Arduino Uno + Display Siete Segmentos
Como parte de los ejercicios básicos de Arduino, les traigo este sencillo proyecto en el cual utilizaremos un display 7 segmentos (hoja de datos aqui), en el cual vamos a mostrar en el display el voltaje que esta sensando el pin conectado al potenciometro (entre 5-0 voltios). Materiales:- Arduino (aqui use el uno)
- Potenciometro
- Display LMS5161BS
- 7 Resistencias 220 Ohms

Teniendo como referencia los segmentos del display procedemos a cablearlos (dejamos sin cablear el segmento del punto). Quedado de la siguiente manera: Segmento a => Pin 2 Segmento b => Pin 3 Segmento c => Pin 4 Segmento d => Pin 5 Segmento e => Pin 6 Segmento f => Pin 8 Segmento g => Pin 9

Nuestro programa sera el siguiente:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include <math.h> int a = 2; //For displaying segment "a" int b = 3; //For displaying segment "b" int c = 4; //For displaying segment "c" int d = 5; //For displaying segment "d" int e = 6; //For displaying segment "e" int f = 8; //For displaying segment "f" int g = 9; //For displaying segment "g" int entrada=A0; int val = 0; void setup() { // put your setup code here, to run once: 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 Serial.begin(9600); } void displayDigit(int digit) { //Conditions for displaying segment a if(digit!=1 && digit != 4) digitalWrite(a,LOW); //Conditions for displaying segment b if(digit != 5 && digit != 6) digitalWrite(b,LOW); //Conditions for displaying segment c if(digit !=2) digitalWrite(c,LOW); //Conditions for displaying segment d if(digit != 1 && digit !=4 && digit !=7) digitalWrite(d,LOW); //Conditions for displaying segment e if(digit == 2 || digit ==6 || digit == 8 || digit==0) digitalWrite(e,LOW); //Conditions for displaying segment f if(digit != 1 && digit !=2 && digit!=3 && digit !=7) digitalWrite(f,LOW); if (digit!=0 && digit!=1 && digit !=7) digitalWrite(g,LOW); } void turnOff() { digitalWrite(a,HIGH); digitalWrite(b,HIGH); digitalWrite(c,HIGH); digitalWrite(d,HIGH); digitalWrite(e,HIGH); digitalWrite(f,HIGH); digitalWrite(g,HIGH); } void loop() { turnOff(); val = analogRead(entrada); float voltage= val * (5.0 / 1023.0); int a = (int) round (voltage); Serial.println(a); int val=(int) ((a*5)/9); displayDigit(a); Serial.println(val); } |
Creamos una función que nos permite pintar valores de 0 a 9 llamada displaydigit que recibe un valor entero en este rango de números. Utilizando este mismo montaje podríamos crear un cronometro que cuenta de 0 a 9 cambiando el codigo al siguiente:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
#include <math.h> int a = 2; //For displaying segment "a" int b = 3; //For displaying segment "b" int c = 4; //For displaying segment "c" int d = 5; //For displaying segment "d" int e = 6; //For displaying segment "e" int f = 8; //For displaying segment "f" int g = 9; //For displaying segment "g" void setup() { // put your setup code here, to run once: 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 displayDigit(int digit) { //Conditions for displaying segment a if(digit!=1 && digit != 4) digitalWrite(a,LOW); //Conditions for displaying segment b if(digit != 5 && digit != 6) digitalWrite(b,LOW); //Conditions for displaying segment c if(digit !=2) digitalWrite(c,LOW); //Conditions for displaying segment d if(digit != 1 && digit !=4 && digit !=7) digitalWrite(d,LOW); //Conditions for displaying segment e if(digit == 2 || digit ==6 || digit == 8 || digit==0) digitalWrite(e,LOW); //Conditions for displaying segment f if(digit != 1 && digit !=2 && digit!=3 && digit !=7) digitalWrite(f,LOW); if (digit!=0 && digit!=1 && digit !=7) digitalWrite(g,LOW); } void turnOff() { digitalWrite(a,HIGH); digitalWrite(b,HIGH); digitalWrite(c,HIGH); digitalWrite(d,HIGH); digitalWrite(e,HIGH); digitalWrite(f,HIGH); digitalWrite(g,HIGH); } void loop() { for(int i=0;i<10;i++) { displayDigit(i); delay(1000); turnOff(); } } |
Un video con el resultado
Etiquetas:7segments, Arduino, arduino uno, electrónica, LMS5161BS, siete segmentos
"Trackback" Enlace desde tu web.