create account

7-Segment counter 0-9 with push buttons up and down by pakganern

View this thread on: hive.blogpeakd.comecency.com
· @pakganern · (edited)
$8.42
7-Segment counter 0-9 with push buttons up and down
#### What Will I Learn?
Today i this instructable we will learn how to make a counter from 0-9 using 1 Digital tube 7 segment Display and Push buttons to calibrate the number up and down, how to program arduino on desktop IDE and how to connect the components with a circuit diagram.

![20180214_144358.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594349/rtnatyh9ud91lkbpzmvg.jpg)


#### Requirements
Write here a bullet list of the requirements for the user in order to follow this tutorial.

- 7 segment display

![20180214_140215.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594360/qdfcwudsx6mtufpui0fj.jpg)


In this tutorial we will use the common cathode type of seven segment, beacause there are 2 types of 7 segment the cathode and anode. most projects of 7 segment  Displays are commonly used in  timers, clock, digital clocks, calculators and watches for this tutorial we are going to use buttons to count numbers on the led display.

- Buttons

![20180214_140146.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594373/xv67dj2eb9ceh1coymso.jpg)


we will use the Momentary Push Button Switch a 12mm Square, These buttons gives a nice soft click every time it's pressed so you know that you've definitely activated it. Their almost instant return make them great for building your own homemade  button pad. it also make a good reset switch or user feedback for a microcontroller circuit.

- Resistor

![20180214_140302.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594384/wve7ahgmfx9gsnxeddow.jpg)


Resistors are electronic components which have a specific measured in ohms, They are passive components, meaning they only consume power it controls the amount of current that flows into the components to protect them from over volume of current that flows through the component

- Jumper wires

![20180214_140431.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594394/shafmhsatlwoxdskrfbk.jpg)


we will use jumpers  to connect on a breadboard or female header connector, size and color to distinguish the different working signals. we will use the male to male jumper for 7 segment and the buttons to connect to arduino,

- Breadboard

![20180214_140331.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594407/mem0rysxstkwvqcgibfs.jpg)


we will use a Single Panel Breadboard it is a solderless device for temporary prototype with electronics and test circuit designs. both side of the breadboard is the power rail it is horizontal lining and the middle is the vertical rail for arduino components.

- Arduino Uno R3

![20180214_140244.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594417/rdqp7ok5eluosmi8eqjo.jpg)


In this tutorial i am using the clone  <a href="https://store.arduino.cc/arduino-uno-rev3">arduino r3 board</a>,<blockquote>It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button.</blockquote> It contains everything needed to support the microcontroller components.

#### Difficulty
- Basic


#### Tutorial Contents

- SOFTWARE

we are going to use the arduino ide, to set the sketch for this, if you dont have make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software

- 7 Segment Displays and Controlling Ways

> seven segment displays contain about 8-segments wherein an extra 8th segment is used to display dot. This segment is useful while displaying non integer number. Seven segments are indicated as A-G and the eighth segment is indicated as H. These segments are arranged in the form of 8 which is shown in the seven segment display circuit diagram below.
reference;  https://www.elprocus.com/types-of-7-segment-displays-and-controlling-ways/

![4.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592769/vz0qymkvtpq5xo2bm9xv.jpg)


- CIRCUIT DIAGRAM

![seg.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592963/mzqlfvf1bmlvmdeb3yv5.png)

COMMON CATHODE PINOUT

![7segment_display_pinout1.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593062/kpiiuqaiqefynrslz6wr.gif)

- Arduino Pin 2 to Pin 9 of 7 segment
- Arduino Pin 3 to Pin 10
- Arduino Pin 4 to Pin 4.
- Arduino Pin 5 to Pin 2..
- Arduino Pin 6 to Pin 1.
- Arduino Pin 8 to Pin 7.
- Arduino Pin 9 to Pin 6.
- Arduino pin GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.

**Push Button Switch DIAGRAM**

![but.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593429/udkpglkjnc9ma0d7aeym.png)

The push buttons has 4 set of legs but we will using 2 legs, both the right leg is connected to the GND pin on the arduino the Increase button Pin in connected to pwm 10 and the Decrease button  Pin  11.

- 7-Segment counter with push button Circuit diagram

![frit.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593649/h0jrmvvmja9pbsttasjp.png)

- Connect the arduino uno board to your computer using the Type B usb cable included in the package. open the arduino Desktop IDE locate the TOOLS verify the type of board you are using PORT should be on the COM# and the board should be on the arduino/genuino uno if youre using the same board as mine.

![sel.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593776/ne8i47gkdisznpmlpsjm.png)

- Programming a code

<pre><code>const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 3;  //For displaying segment "g"
bool bPress = false;
const int IncbuttonPin = 10;
const int DecbuttonPin = 11;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int IncbuttonState = 0;         // current state of the button
int lastIncbuttonState = 0;     // previous state of the button
int DecbuttonState = 0;         // current state of the button
int lastDecbuttonState = 0;     // previous state of the button
void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode( IncbuttonPin , INPUT_PULLUP );
  pinMode( DecbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);  
  displayDigit(buttonPushCounter);  
}
void loop() {  
   IncbuttonState = digitalRead(IncbuttonPin);
   DecbuttonState = digitalRead(DecbuttonPin);
   checkIncButtonPress();
   checkDecButtonPress();  
  if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter);
  }
   /*
  for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
 */
}
void checkIncButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      if( buttonPushCounter > 9) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =9 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDecbuttonState = DecbuttonState;
}  
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=1 && digit != 4)
 digitalWrite(a,HIGH);
 //Conditions for displaying segment b
 if(digit != 5 && digit != 6)
 digitalWrite(b,HIGH);
 //Conditions for displaying segment c
 if(digit !=2)
 digitalWrite(c,HIGH);
 //Conditions for displaying segment d
 if(digit != 1 && digit !=4 && digit !=7)
 digitalWrite(d,HIGH);
 //Conditions for displaying segment e 
 if(digit == 2 || digit ==6 || digit == 8 || digit==0)
 digitalWrite(e,HIGH);
 //Conditions for displaying segment f
 if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
 digitalWrite(f,HIGH);
 if (digit!=0 && digit!=1 && digit !=7)
 digitalWrite(g,HIGH);
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}</code></pre>

loop() runs very often. Unless you put a delay() in there it runs at many thousands times a second.

![20180214_144443.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594329/ze11evpu4a5mq7wuvvfw.gif)

I hope you enjoy this actitvity if want to learn how arduino works, and how to make a sketch, then maybe this site http://educ8s.tv/ might help you, educ8 since im always following their project for this stuff, all images on this blog are supposedly mine excluding the with src. thank you for stopping by..

You can also check my previous posts:

<a href="https://utopian.io/utopian-io/@pakganern/keyes-ky-017-arduino-mercury-switch-alarm-system">Keyes KY-017 Arduino Mercury Switch alarm system</a>

<a href="https://utopian.io/utopian-io/@pakganern/soil-moisture-sensor-with-a-nokia-5110-lcd-display-arduino-project">Soil Moisture Sensor with a Nokia 5110 LCD display Arduino Project</a>

<a href="https://utopian.io/utopian-io/@pakganern/ultrasonic-sensor-hc-sr04-with-iic-lcd-display-distance-meter">Ultrasonic Sensor HC-SR04 with IIC LCD Display (Distance Meter)</a>

<a href="https://utopian.io/utopian-io/@pakganern/3qvfub-control-2-servo-with-potentiometer-xod">i2C Oled display and 8glib Library arduino</a>

<a href="https://utopian.io/utopian-io/@pakganern/control-2-servo-with-potentiometer-xod">Control 2 servo with Potentiometer/ XOD</a>

<a href="https://utopian.io/utopian-io/@pakganern/controlling-2-servo-motor-with-joystick">Controlling 2 Servo Motor with Joystick</a>

<a href="https://utopian.io/utopian-io/@pakganern/ultrasonic-sensor-hc-sr04-alarm-system">Ultrasonic Sensor HC-SR04 alarm system</a>

<a href="https://utopian.io/utopian-io/@pakganern/ds18b20-temperature-sensor-and-iic-16x2-lcd-display-arduino-tutorial">DS18B20 temperature sensor and IIC 16x2 LCD display Arduino tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/led-matrix-red-8x8-tutorial">LED Matrix red 8x8 Tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/ultrasonic-sensor-hc-sr04-distance-meter-with-a-nokia-5110-lcd-display">Ultrasonic Sensor HC SR04 distance meter with a Nokia 5110 LCD display</a>

<a href="https://utopian.io/utopian-io/@pakganern/iic-lcd-scrolling-text-with-arduino-tutorial">IIC LCD Scrolling Text with Arduino tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/light-sensor-ldr-monitor-with-a-lcd-nokia-5110-tutorial">Light sensor LDR Monitor with a LCD Nokia 5110 Tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/rotary-encoder-with-nokia-5110-display-tutorial">Rotary Encoder with Nokia 5110 display Tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/real-time-clock-ds1302-module-and-nokia-5110-diy-lcd-tutorial">Real time clock DS1302 module and Nokia 5110 DIY lcd tutorial</a>

<a href="https://utopian.io/utopian-io/@pakganern/how-to-connect-nokia-5110-lcd-to-arduino">How to connect nokia 5110 LCD to arduino</a>

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@pakganern/7-segment-counter-0-9-with-push-buttons-up-and-down">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , ,
properties (23)
authorpakganern
permlink7-segment-counter-0-9-with-push-buttons-up-and-down
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":919161,"name":"Arduino","full_name":"arduino/Arduino","html_url":"https://github.com/arduino/Arduino","fork":false,"owner":{"login":"arduino"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tutorial","howto","technology","blog"],"users":["pakganern"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594349/rtnatyh9ud91lkbpzmvg.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594360/qdfcwudsx6mtufpui0fj.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594373/xv67dj2eb9ceh1coymso.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594384/wve7ahgmfx9gsnxeddow.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594394/shafmhsatlwoxdskrfbk.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594407/mem0rysxstkwvqcgibfs.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594417/rdqp7ok5eluosmi8eqjo.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592769/vz0qymkvtpq5xo2bm9xv.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592963/mzqlfvf1bmlvmdeb3yv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593062/kpiiuqaiqefynrslz6wr.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593429/udkpglkjnc9ma0d7aeym.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593649/h0jrmvvmja9pbsttasjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593776/ne8i47gkdisznpmlpsjm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594329/ze11evpu4a5mq7wuvvfw.gif"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594349/rtnatyh9ud91lkbpzmvg.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594360/qdfcwudsx6mtufpui0fj.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594373/xv67dj2eb9ceh1coymso.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594384/wve7ahgmfx9gsnxeddow.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594394/shafmhsatlwoxdskrfbk.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594407/mem0rysxstkwvqcgibfs.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594417/rdqp7ok5eluosmi8eqjo.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592769/vz0qymkvtpq5xo2bm9xv.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518592963/mzqlfvf1bmlvmdeb3yv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593062/kpiiuqaiqefynrslz6wr.gif","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593429/udkpglkjnc9ma0d7aeym.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593649/h0jrmvvmja9pbsttasjp.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518593776/ne8i47gkdisznpmlpsjm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1518594329/ze11evpu4a5mq7wuvvfw.gif"],"moderator":{"account":"creon","time":"2018-02-15T16:17:02.339Z","reviewed":true,"pending":false,"flagged":false},"questions":null,"score":null}
created2018-02-14 07:52:06
last_update2018-02-17 12:10:57
depth0
children3
last_payout2018-02-21 07:52:06
cashout_time1969-12-31 23:59:59
total_payout_value5.945 HBD
curator_payout_value2.479 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length12,463
author_reputation39,682,824,097,581
root_title"7-Segment counter 0-9 with push buttons up and down"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id37,417,768
net_rshares1,478,366,884,754
author_curate_reward""
vote details (5)
@creon ·
$1.33
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  
properties (23)
authorcreon
permlinkre-pakganern-7-segment-counter-0-9-with-push-buttons-up-and-down-20180215t161723044z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-15 16:17:18
last_update2018-02-15 16:17:18
depth1
children1
last_payout2018-02-22 16:17:18
cashout_time1969-12-31 23:59:59
total_payout_value1.002 HBD
curator_payout_value0.332 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation2,792,252,766,467
root_title"7-Segment counter 0-9 with push buttons up and down"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id37,781,627
net_rshares197,498,796,672
author_curate_reward""
vote details (1)
@utopian.tip ·
Hey @creon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
properties (22)
authorutopian.tip
permlinkre-re-pakganern-7-segment-counter-0-9-with-push-buttons-up-and-down-20180215t161723044z-20180215t211632
categoryutopian-io
json_metadata""
created2018-02-15 21:16:33
last_update2018-02-15 21:16:33
depth2
children0
last_payout2018-02-22 21:16:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length155
author_reputation238,310,597,885
root_title"7-Segment counter 0-9 with push buttons up and down"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id37,838,024
net_rshares0
@utopian-io ·
### Hey @pakganern I am @utopian-io. I have just upvoted you!
#### Achievements
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-pakganern-7-segment-counter-0-9-with-push-buttons-up-and-down-20180217t183048449z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-17 18:30:48
last_update2018-02-17 18:30:48
depth1
children0
last_payout2018-02-24 18:30:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,429
author_reputation152,955,367,999,756
root_title"7-Segment counter 0-9 with push buttons up and down"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id38,320,603
net_rshares0