Introduction: Arduino Counter
Hey, guys, I am Sridhar Janardhan back with another tutorial.As I was passing by a signal I saw traffic signals with a counter beside so I wanted to create a counter of my own using an Arduino.to create this instructable you got to use an Arduino and a 7 segment led.if anyone finds difficulty in following any leave a comment below.
Step 1: Components Required:
the components required are
- Arduino UNO.
- Resistor - 220 Ω.
- 7-segment LED.
- jumper wires.
- Breadboard.
Let's start interfacing.
Step 2: Adding 220 Ohm Resistor:
The 7 Segment led is placed on a breadboard as shown in the figure.Here we are going to add 220-ohm resistor.The top row and bottom row middle pin is a common pin.We need to connect this pin to the resistor leg as shown in the figure.
Step 3: Connecting Remaining Pins:
The remaining pin of the connection is as follows:
- TOP pins(from left side) First pin to digital pin 8
- Second pin to digital pin 9
- Third pin to the resistor
- Fourth pin to digital pin 7
- Fifth pin to digital pin 6
Bottom pins(from left side)
- First pin to digital pin 10
- Second pin to digital pin11
- Third pin to the resistor
- Fourth pin to digital pin 12
- Fifth pin to digital pin 3
Let's start coding.
Step 4: Coding:
int c = 12;
int d = 11;
int e = 10;
int g = 9;
int f = 8;
int a = 7;
int b = 6;
int chrono = 1000;
void zero(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH); }
void one(){
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(g, HIGH);
digitalWrite(f, HIGH);
digitalWrite(a, HIGH);
digitalWrite(b, LOW); }
void two(){
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void three(){
digitalWrite(c, LOW);
digitalWrite(d, LOW)
; digitalWrite(e, HIGH);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void four(){
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(a, HIGH);
digitalWrite(b, LOW); }
void five(){
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void six(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void seven(){
digitalWrite(a, LOW);
digitalWrite(b, LOW)
; digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void eight(){
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void nine(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void setup() {
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(g, OUTPUT);
pinMode(f, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT); }
void loop() {
zero();
delay(chrono);
one();
delay(chrono);
two();
delay(chrono);
three();
delay(chrono);
four();
delay(chrono);
five();
delay(chrono);
six();
delay(chrono);
seven();
delay(chrono);
eight();
delay(chrono);
nine();
delay(chrono);
}