--> Project I - 2. Counter with 7 Segment Based on Arduino | basic arduino tutorial

Thursday, August 24, 2017

Project I - 2. Counter with 7 Segment Based on Arduino

| Thursday, August 24, 2017
Counter with 7 Segment 


How this system works is to calculate the amount of input and data expenditure. The input data is obtained from keystrokes UP, while the DOWN key is used for data counter reduction.
This tool consists of Arduino UNO as the main system & controller of the system. Up button as the number of data counter counters while the DOWN button to reduce the contents of the counter. While 7-Segment is used for display counter.

Hardware Requirement
  • Arduino Uno Board
  • 4 Digit of 7-Segment with Common Anode
  • 3 Push Button 
  • Power supply +5 Volt
  • Jumper

7-Segment | Source


Block Diagram

 Schematic



7-Segment CA Wiring | Source

Arduino - 7 Segment Wiring


Source Code/Sketch

unsigned int count;
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int dig1 = 9;
int dig2 = 10;
int dig3 = 11;
int dig4 = 12;
void setup() {
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
digitalWrite(A2,1);
}
void loop() {
char seg1 = int(count)/1000;
char seg2 = (int(count)%1000)/100;
char seg3 = (int(count)%100)/10;
char seg4 = (int(count)%100)%10;
if (count < 10){
seg1=10;
seg2=10;
seg3=10;
}
else if (count < 100){
seg1=10;
seg2=10;
}
else if (count < 1000){
seg1=10;
}
digitalWrite(12,1);
digitalWrite(9,0);
displaySeg(seg1);
delay(5);
digitalWrite(9,1);
digitalWrite(10,0);
displaySeg(seg2);
delay(5);
digitalWrite(10,1);
digitalWrite(11,0);
displaySeg(seg3);
delay(5);
digitalWrite(11,1);
digitalWrite(12,0);
displaySeg(seg4);
delay(5);
if (digitalRead(A0)==0 && count < 9999){
count++;
delay(200);
}
else if(digitalRead(A1)==0 && count != 0){
count--;
delay(200);
}
else if(digitalRead(A2)==0){
count=0;
}
}
void displaySeg(char segment){
switch (segment){
case 0: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,1);
break;
case 1: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 2: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,1);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 3: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 4: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 5: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 6: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 7: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 8: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 9: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 10: digitalWrite(segA,1);
digitalWrite(segB,1);
digitalWrite(segC,1);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
}
}

How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script program above to your arduino.
5. The first view on the 7 segment, displaying of number 0



6. Press UP button, so counter counts the number of keystrokes, and the results are displayed on 4  
    seven segments


7. Next, to reduce the counter count press DOWN button.

8. RESET button is used to zero back the contents of the counter.


Video for Project I - 2. Counter with 7 Segment Based on Arduino





Required file


Related Posts

No comments:

Post a Comment