loading

in this instructable we connect the arduino nano to a ping sensor and we export the results to a 7 segment 4 digit display.

Step 1: Gather All the Parts You Need

1 - breadboard

2 - jumper wires

3 - arduino nano v3

4 - ping sensor

5 - 7 segment decoder ( could be 74ls47 or cmos 4511)

6 - 7 segment display common anode with four digits

7 - 7 resistors acording to 7 segment ( 350 Ohm would be fine)

8 - 1k resistor for the decoder

Step 2: Connect the Parts

connect the parts as shown on the image.

i used vbb to schets it but i hasnt the sevensegment (see below)

1 - the nano to the decoder 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

<p>Thank you for the application. I am Greek too. Egw to eftiaxa mono me Uno kai me substrings kai eixa arketo flikering. Sto diko sou prosthesa 3 'if' prin kalesw thn function 'anama', kai krivw ta arxika tyxon midenika. Eyxaristw kai pali.</p>
ela re patrida! to flickering uparxei apla meiothike me ayto to kodika! pleon xrisimopoio tsip MAX7219 kai ta sxetika module.
Smart idea! Thanks for shearig :)
<p>Interesting. Thanks for sharing this.</p>

About This Instructable

3,418views

20favorites

More by masdsaris:arduino nano 7segment 4digit display ping sensor by sarigiannis 
Add instructable to: