Tabla de contenido:
- Suministros:
- Paso 1: Reúna todas las piezas que necesita
- Paso 2: Conectar las piezas
- Step 3: The Seven Segment With 12 Pins
- Step 4: How It Should Work
- Step 5: The Code
- Step 6: You Might As Well Need the Newping Library
En este instructivo conectamos el arduino nano a un sensor de ping y exportamos los resultados a una pantalla de 7 segmentos de 7 dígitos.
Suministros:
Paso 1: Reúna todas las piezas que necesita
1 - Breadboard
2 - cables de puente
3 - arduino nano v3
4 - sensor de ping
Decodificador de 5 a 7 segmentos (podría ser 74ls47 o cmos 4511)
Ángulo común de visualización de 6 a 7 segmentos con cuatro dígitos
7 - 7 resistencias según 7 segmentos (350 Ohm estarían bien)
8 - Resistencia 1k para el decodificador.
Paso 2: Conectar las piezas
Conecte las partes como se muestra en la imagen.
Usé vbb para planearlo, pero no tengo el segmento de servicio (ver más abajo)
1 - el nano al decodificador a0 / a1 / a2 / a3
2 - the nano to the select pins of 7 segment y1/ y2/y3/y4
3 - the nano to the buzzer
4 - the nano to the ping sensor
5 - the decoder 3 pins conectet to common point and to vcc throu 1k resistor
6 - the decoder to vcc and ground
7 - the decoder to 7segment a/b/c/d/e/f/g through 350 ohm resistors
be very carefull to follow the conection diagram!
Step 3: The Seven Segment With 12 Pins
if you have a four digit 7 segment this is the image on how to connect it
a-b-c-d-e-f-g is as stated the elements
y1 - y2 - y3 - y4 are the select pins on which of the four to display
dp is the dot display. we don need that.
Step 4: How It Should Work
the seven segment must dispaly the sensor distance in cm
below 10cm you will hear the buzzer lightly
below 5cm you should hear the buzzer more intense
you may skip the decoder if you know what you are doing in the code
Step 5: The Code
#include < NewPing.h >
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int protonoumero;
int deyteronoumero;
int tritonoumero;
int tetartonoumero;
int tetrapsifios=0;
void setup(){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(13,OUTPUT);
}
void loop(){
unsigned int uS = sonar.ping();
tetrapsifios=(uS / US_ROUNDTRIP_CM);
if (tetrapsifios<=9){
digitalWrite(13,1);
delay(10);
if (tetrapsifios<=5){
delay(20);
}
tetartonoumero=tetrapsifios;
tritonoumero=0;
deyteronoumero=0;
protonoumero=0;
}
if(tetrapsifios>9 && tetrapsifios<=99){
tritonoumero=tetrapsifios/10;
tetartonoumero=tetrapsifios-(tritonoumero*10);
deyteronoumero=0; protonoumero=0;
}
if(tetrapsifios>99 && tetrapsifios<=999){
deyteronoumero=tetrapsifios/100;
tritonoumero=((tetrapsifios-(deyteronoumero*100))/10);
tetartonoumero=(tetrapsifios-(deyteronoumero*100))-(tritonoumero*10);
protonoumero=0; }
if (tetrapsifios>999){ tetartonoumero=0; tritonoumero=0; deyteronoumero=0; protonoumero=0; } for (int t=0; t<10; t){
digitalWrite(13,0);
digitalWrite(8,1);
digitalWrite(7,0);
digitalWrite(6,0);
digitalWrite(5,0);
anama(tetartonoumero);
delay(5);
digitalWrite(8,0);
digitalWrite(7,1);
digitalWrite(6,0);
digitalWrite(5,0);
anama(tritonoumero);
delay(5);
digitalWrite(8,0);
digitalWrite(7,0);
digitalWrite(6,1);
digitalWrite(5,0);
anama(deyteronoumero);
delay(5);
digitalWrite(8,0);
digitalWrite(7,0);
digitalWrite(6,0);
digitalWrite(5,1);
anama(protonoumero);
delay(5);
t=t+1;
}
}
void anama(int noumero){
switch (noumero){
case 0:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
break;
case 1:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
break;
case 2:
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(9,0);
break;
case 3:
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(9,0);
break;
case 4:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(9,0);
break;
case 5:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(9,0);
break;
case 6:
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(9,0);
break;
case 7:
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(9,0);
break;
case 8:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,1);
break;
case 9:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,1);
break;
}
}
Step 6: You Might As Well Need the Newping Library
et VOILA!
Im sorry the code doesnt have comments or some terms are in greek its my first publish, but its easy to follow and its tested and demostrated. as long as you make the connections right it will work. feel free to ask anything!
JOHN SARIGIANNIS ASPAITE ELECTRICAL ENGINEER