Arduino Seven-Segment Counter

Arduino Seven-Segment Counter © Apache-2.0

A four-digit seven-segment counter with three options.

  • 9 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

4966285
Solder Wire, Lead Free
09507 01
Soldering iron (generic)

About this project

You can use the same programme for 01. Flood level meter 02. Visitor Counter 03.Continue Counter but you have to do only few changes to the programme.

Following components are needed.01.Push button switch02.10k Potentiometer03.Arduino Uno with Atmega 32804.Seven Segments (4 Digits)I have used here a conman Anode Seven Segment. Details as followsKYX - 5461BS SSD was used in this project

Pin connection to Arduino Uno

01.Flood Level MeterYou can connect to Analog pin 0 the following Circuit

02.Continue counter You can connect to Analog pin 0 the following Circuit

03.Visitors counter

If you want to count number of visitors then you can use the following diagram. Use LDR and light a laser and focus to the face of LDR.

Code should be edited as follows.01. Flood Level

02. Continue Counter

03. Visitors Counter

**Your comments are highly appreciated by Easy Mades **

Code

CodeArduino
You can copy and paste this code in the arduino software and upload the code.
/*

/** This code is edited by www.easymades.com **/


int Ntime = 0;
int Otime = 0;
float X = 0;
int time = 4;

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int pinDP = 1;

int DIG1 = 12;
int DIG2 = 11;
int DIG3 = 10;
int DIG4 = 9;

void choose_digit(char num) {
  switch (num) {
  default: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 1: digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 2: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 3: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 4: digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 5: digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 6: digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 7: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 8: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 9: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break;

      ;
  }
}

void pick_digit(int digit) {
  digitalWrite(DIG1, LOW);
  digitalWrite(DIG2, LOW);
  digitalWrite(DIG3, LOW);
  digitalWrite(DIG4, LOW); switch (digit) {
  case 1: digitalWrite(DIG1, HIGH); break; case 2: digitalWrite(DIG2, HIGH); break; case 3: digitalWrite(DIG3, HIGH); break; default: digitalWrite(DIG4, HIGH); break;
  }

}

void decimal_place() {
  digitalWrite(pinDP, LOW);
}

void seven_segment(int number) {
  unsigned char thousands = int (number / 1000);
  unsigned char hundreds = int ((number / 100) % 10);
  unsigned char tens = int ((number / 10) % 10);
  unsigned char ones = int (number % 10); //1234
  if (thousands > 0) {
    choose_digit(thousands);
    pick_digit(1);
  }

  if ((hundreds > 0) | (thousands > 0)) {
    delay(time); choose_digit(hundreds);
    pick_digit(2);
  }

  if ((tens > 0) || (hundreds > 0) | (thousands > 0)) {
    //decimal_place();
    delay(time); choose_digit(tens);
    pick_digit(3);
  }


  // add decimal point
  delay(time); choose_digit(ones);
  pick_digit(4);

  delay(time);

}

void setup() {
  pinMode(DIG1, OUTPUT);
  pinMode(DIG2, OUTPUT);
  pinMode(DIG3, OUTPUT);
  pinMode(DIG4, OUTPUT); 
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);
  pinMode(pinD, OUTPUT);
  pinMode(pinE, OUTPUT);
  pinMode(pinF, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(pinDP, OUTPUT);

}

void loop() {
float sensor_value = map(analogRead(A0),0,1023,0,3000); // for Flood level Sensor this Eg:3000 is the maximum level




// Continue counter and Visitors counter
/** 
  Ntime = millis();
  if (analogRead(A0) > 0) {

    if ((Ntime - Otime) > 200) {
      X = X + 1;
      Otime = Ntime; // Active this to visitors  counter
      {
        if (X == 9999) {
          X = 0;
        }
      }
    }
    //Otime = Ntime; // Active this to continue counter

  }

  float sensor_value = X; */



  
  seven_segment(sensor_value);

}

Schematics

Counter Circuit Diagram
This is directly connected to the Arduino board, but if you want, you can make the project on a vero board.
Easy mades yqivotvhpa

Comments

Similar projects you might like

Personal Home Assistant

Project tutorial by 3 developers

  • 4,420 views
  • 0 comments
  • 29 respects

Smart 3D Printer Filament Counter (FilamentBot)

Project tutorial by ArtSuzhou

  • 9,558 views
  • 3 comments
  • 25 respects

Arduino UNO Library for a Sampling Scope & Counter

Project showcase by Veldekiaan

  • 4,382 views
  • 6 comments
  • 25 respects

Android Frequency Counter

Project tutorial by Projecter

  • 2,414 views
  • 0 comments
  • 5 respects

Metal Detector Using Frequency Counter and OLED Display

Project tutorial by Andrius Purr

  • 2,245 views
  • 1 comment
  • 16 respects

ATmega Alien Themed Slot Machine

Project tutorial by Dan Murphy

  • 1,964 views
  • 6 comments
  • 22 respects
Add projectSign up / Login