--> Project I - 3. 4 Digit Stopwatch using 7-Segment Display Based on Arduino | basic arduino tutorial

Thursday, August 24, 2017

Project I - 3. 4 Digit Stopwatch using 7-Segment Display Based on Arduino

| Thursday, August 24, 2017
4Digit Stopwatch using 7-Segment Display


Such a stop watch in general that is calculate the time of initial emphasis (start) until the final emphasis (stop) with time lag is in milli seconds.

This tool uses Arduino UNO as its system processor. The START button is used to start timing calculations. STOP button to stop timing. RESET button to zero back stop watch value. While the seven segment 4 digits is use as the viewer of the results of stopwatch calculation.

Hardware Requirement
  • Arduino Uno Board
  • 4 Digit of 7-Segment with Common Anode
  • 2 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

char stopWatch;
char menit, pulDetik, satDetik, ratMilli;
int sisaBagi;
unsigned long pengurang, dataStopWatch, dataPaus;
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int segH = 9;
int dig1 = 10;
int dig2 = 11;
int dig3 = 12;
int dig4 = 13;
void setup() {
for(char i=2; i<14; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
}
void loop() {
pengurang=millis();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 1;
while(stopWatch){
dataStopWatch = ((millis() - pengurang)/100)+ dataPaus;
displaySeg();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 0;
dataPaus = dataStopWatch;
}
}
}
else if(digitalRead(A1)==0){
dataStopWatch = 0;
dataPaus = 0;
}
displaySeg();
}
void displaySeg(){
menit = dataStopWatch / 600;
sisaBagi = dataStopWatch % 600;
pulDetik = sisaBagi / 100;
sisaBagi = sisaBagi % 100;
satDetik = sisaBagi / 10;
sisaBagi = sisaBagi % 10;
ratMilli = sisaBagi;
digitalWrite(dig4,1);
digitalWrite(dig1,0);
Seg(menit);
delay(6);
digitalWrite(dig1,1);
digitalWrite(dig2,0);
Seg(pulDetik);
delay(6);
digitalWrite(dig2,1);
digitalWrite(dig3,0);
digitalWrite(segH,0);
Seg(satDetik);
delay(6);
digitalWrite(segH,1);
digitalWrite(dig3,1);
digitalWrite(dig4,0);
Seg(ratMilli);
delay(6);
}
void Seg(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;
}
}

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 display on the seven segment


6. Press the Start / Pause button, so stopwatch will start counting time


7. Press the same button once again to Pause for certain time



7. To continue the stopwatch calculation press the Start / Pause button again.

8. If you want to Reset the stopwatch time just make sure the stopwatch is in PAUSE condition then

     Press the RESET button, it will make the stopwatch data to zero again.

Video for Project I - 3. 4 Digit Stopwatch using 7-Segment Display Based on Arduino



Required file

Related Posts

No comments:

Post a Comment