How to make a DIY object counting machine using Arduino

How to make a DIY object counting machine using Arduino

Hello and welcome back. In this project, we will learn how to make an object counting machine using Arduino. For this project, I mainly used an IR sensor to detect objects. When an object comes close to the sensor, it gives a digital signal to the Arduino, and the count increases by one. I also used a seven-segment display to show the counting values. In addition, I added a push button to reset the count and a buzzer to give a sound indication whenever an object is detected. Additionally, I designed a PCB for this project using JLCPCB. Therefore, we don’t need additional components.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s order PCBs for this project.

  • Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
  • Gerber file – Download
  • For this project, I ordered five Red PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.

Step 3

Thirdly, unbox the PCB package and check all the boards.

Step 4

After that, solder the female headers and the two-pin terminal to the PCB.

Step 5

Next, connect the Arduino Nano board, seven-segment display, and sensor to the PCB. Afterward, connect the Arduino board to the computer.

Step 6

Now, open the Arduino IDE and copy the following program into it.

// 7-segment pins
int a = 3;
int b = 2;
int c = 8;
int d = 7;
int e = 6;
int f = 4;
int g = 5;
int dp = 9;

// Other pins
int irPin = 11;
int buttonPin = 12;
int buzzer = 13;

int count = 0;
bool lastIRState = HIGH;

// Segment patterns for 0–9 (Common Anode → LOW = ON)
byte digits[10][7] = {
  {0,0,0,0,0,0,1}, // 0
  {1,0,0,1,1,1,1}, // 1
  {0,0,1,0,0,1,0}, // 2
  {0,0,0,0,1,1,0}, // 3
  {1,0,0,1,1,0,0}, // 4
  {0,1,0,0,1,0,0}, // 5
  {0,1,0,0,0,0,0}, // 6
  {0,0,0,1,1,1,1}, // 7
  {0,0,0,0,0,0,0}, // 8
  {0,0,0,0,1,0,0}  // 9
};

void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(dp, OUTPUT);

  pinMode(irPin, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);

  displayDigit(count);
}

void loop() {
  bool irState = digitalRead(irPin);

  // Detect object (HIGH → LOW)
  if (lastIRState == HIGH && irState == LOW) {
    count++;
    if (count > 9) count = 0;

    displayDigit(count);
    beep();
    delay(200);
  }
  lastIRState = irState;

  // Reset button
  if (digitalRead(buttonPin) == LOW) {
    count = 0;
    displayDigit(count);
    delay(300);
  }
}

void displayDigit(int num) {
  digitalWrite(a, digits[num][0]);
  digitalWrite(b, digits[num][1]);
  digitalWrite(c, digits[num][2]);
  digitalWrite(d, digits[num][3]);
  digitalWrite(e, digits[num][4]);
  digitalWrite(f, digits[num][5]);
  digitalWrite(g, digits[num][6]);
}

void beep() {
  digitalWrite(buzzer, HIGH);
  delay(100);
  digitalWrite(buzzer, LOW);
}
  • Next, select the board and port. After, click the upload button.

Step 7

Finally, remove the USB cable and connect an external power supply to the project. I also designed a structure to mount this system.

Now, enjoy this project. The full video guide is provided below. We hope to see you in the next project. Have a great day!

How to make a DIY object counting machine using Arduino

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *