Digital Object Counter Using Arduino || DIY || TexoBot

Hi All, welcome to yet another Arduino project from TexoBot. This time, we will learn how to create this cool looking digital Object counter using Arduino Nano.

Block Diagram

Let’s learn the Designing and Working of this project using given block diagram.

  • The first block is Arduino Nano, Arduino is the brain of this project. It will take input from the IR sensor and increase the count value by one whenever the IR sensor output change from 5v to 0.

Arduino will control and coordinate all other blocks that are used in this project.

  • The second block is 16x4 LCD display. This section is an output unit, main functions like prompting the user to set the count limit, count limit reach notification. Also, other functions like displaying the current count, showing the last count value etc.

  • The Third block is 8-Bit 7 Segment Display Module. This section is used to [i]display the Object Count. This display is driven by MAX7219 IC and can support up to 8-digit numbers.

  • The fourth block is Push Button Switches. This section contains three push button switches. The Set / Reset push button will be used for setting the count limit, the UP and DOWN buttons are used for Increasing and decreasing the count value respectively.

  • The fifth block is the Buzzer + LED. This section is used to make the project more user-friendly. Buzzer will produce a beep sound and LED will blink when any of the push buttons are pressed and also while the IR sensor detects and object. The buzzer will beep for 30 seconds when the count reaches the count limit value.

  • The Fifth block is the IR Sensor. IR sensor is an electronic device, that emits the light in order to sense some object of the surroundings. This sensor has two sections.

The emitter is an IR LED and the detector is an IR photodiode. The IR photodiode is sensitive to the IR light emitted by an IR LED. The photo-diode’s resistance and output voltage change in proportion to the IR light received. This is the underlying working principle of the IR sensor. We will be using this sensor to count the object. When ever an object presents in the range of this sensor, the output voltage will change from 5V to 0v. Arduino will detect this change in voltage state and increase the count by one.

The sensor used in our project has a range of 3-80cm

Required Components

Now let’s move to the components required to build this project. You can buy all these components from third party vendors like E-bay, Amazon etc.

Arduino Nano….....Amazon.in / Amazon.com

16x4 lcd display.......electroncomponents.com / aliexpress.com

8 Digit Seven Segment Display Module with MAX7219......Amazon.in / Amazon.com

IR Sensor E18-D80NK...... Amazon.in / Amazon.com

5V Passive Buzzer......... Amazon.in / Amazon.com

Push Button Switch-3Pcs.......... Amazon.in / Amazon.com

LED diode ............ Amazon.in / Amazon.com

Female header pins............. Amazon.in / Amazon.com

Male header pins............... Amazon.in / Amazon.com

BC547 Transistor............. Amazon.in / Amazon.com

0.1 uf capacitor - 3pcs.......... Amazon.in / Amazon.com

10k Ohm Trimpot Trimmer Potentiometer......... Amazon.in / Amazon.com

Resistor 10KΩ – 4pcs........ Amazon.in / Amazon.com

Resistor 1KΩ – 1 pcs......... Amazon.in / Amazon.com

Resistor 220Ω – 1 Pcs............ Amazon.in / Amazon.com

Resistor 560Ω – 1 pcs............ Amazon.in / Amazon.com

Carousel imageCarousel image

Designing the PCB and Generating the Gerber File

Below is the circuit diagram for our design, if anyone want to implement the project without using a PCB then you can refer this one.

Now let’s have look into the PCB designing process. So first, you need to design your PCB. You can choose online or offline platform for designing your PCBs.

Here we used Eagle software to design the PCB.

Once we finish the design, we will generate the Gerber file needed for manufacturing the PCB.

Please contact us if you would like to have the Gerber file that we have used in this project.

Then we ordered the PCB from JLCPCB which are also the sponsor of this video.

JLCPCB is a manufacture of high quality PBCs which are used in many industries for prototyping as well as in DIY projects. Once you have your PCB design ready, simply upload the Geber file, review your PCB in the Gerber viewer,

Select the property that you want and order your PCB at a reasonable price.

If it is your first order from JLCPCB you can get up to 5 PCBs for only $2.

Soldering Process

Now let's try to solder the components. Try to solder the small components first and then proceed with the big one while soldering the components to the PCB. This will make the soldering process easier.

Follow the same procedure to complete the soldering process for rest of the components. For more information please visit link in the description

So now we have completed the soldering process.

Please contact us if you would like to have the Gerber file that we have used in this project.


Upload the Sketch to Arduino

Now we can upload the sketch to our Arduino. Connect Arduino to your computer using the USB cable and upload the code shown below.

I have added comments in the program for better understanding of each codes.

int Count_limit = 0; // declare count limit variable to zero

int IR_Sensor_INPUT = A0; //E18*D80NK IR Infrared Sensor input pin to Arduino pin A0

long int counter = 0; // Set counter variable to 0

int hitObject = false;

int Buzzer = 9; // Positive pin of Buzzer to Arduino pin 9

int Set_Reset_Button = A1; // Button to reset the count value to Arduino pin A1

int UP_button = A2; // Button to count up to Arduino pin A2

int Down_button = A3; // Button to count Down to Arduino pin A3

int Set_Reset_Button_State= 1;

int Up_Button_State = 1;

int Down_Button_State = 0;

int LED = 8; // Amnode pin of the LED to Arduino pin 8

#include "LedControl.h" // include the Led display library:

LedControl lc=LedControl(11,13,10,1);// initialize the library with the numbers of the interface pins

#include <LiquidCrystal.h> // include the Liquid Cristal library:

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

#include <EEPROM.h> // include the EEPROM library to store last count even after power loose

int addr = 0; //Set EEPROM Address to zero

void setup() {

pinMode(Set_Reset_Button, INPUT); // SET PUSH Button as input

pinMode(UP_button, INPUT); // UP PUSH Button as input

pinMode(Down_button, INPUT); //DOWN PUSH Button as input

pinMode(Buzzer, OUTPUT); // Buzzer as output

pinMode(LED, OUTPUT); // LED as output

lc.shutdown(0,false);

lc.setIntensity(0,8);

lc.clearDisplay(0);

Serial.begin(9600);

pinMode(IR_Sensor_INPUT,INPUT_PULLUP); // IR sensor as INPUT(Used inbuilt pullup resister using program)

lcd.begin(16, 4); // set up the LCD's number of 16 columns and 4 rows:

// ###Print follwing details to the LCD at the start###//

lcd.print("****************");

lcd.setCursor(0,1);

lcd.print("*Object Counter*");

lcd.setCursor(0,2);

lcd.print("* *");

lcd.setCursor(0,3);

lcd.print("****************");

//Trun on Buzzer and off after 200ms delay//

digitalWrite(Buzzer, HIGH);

delay(200);

digitalWrite(Buzzer, LOW);

delay(1000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("last count was:");

lcd.setCursor(0,1);

lcd.print(EEPROM.read(addr));// show the previous count

delay(2000);

set_count_limit(); //cal set_count function

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Object Count:");

lcd.setCursor(0,1);

lcd.print(counter); // show counter value

led_display();

}

void loop() {

counter_(); // call counter

counter = 0;

led_display();

digitalWrite(Buzzer, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("last count was:");

lcd.setCursor(0,1);

lcd.print(EEPROM.read(addr));

delay(2000);

Set_Reset_Button_State = HIGH;

set_count_limit();

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Object Count:");

lcd.setCursor(0,1);

lcd.print(counter);

led_display();

// lcd.clear();

// lcd.setCursor(0,0);

// lcd.print("Object Count:");

// lcd.setCursor(0,1);

// lcd.print(counter);

}

void counter_(){

while(1){

lcd.setCursor(0,3);

lcd.print("SET RST");

Set_Reset_Button_State= digitalRead(Set_Reset_Button); // read the reset button sate(LOW or HIGH)

Down_Button_State = digitalRead(Down_button); // read the DOWN button sate(LOW or HIGH)

Up_Button_State = digitalRead(UP_button); // read the UP button sate(LOW or HIGH)

if(Set_Reset_Button_State== HIGH){ // This if loop will be executed if the SET button is HIGH

lcd.setCursor(0,1);

int val = digitalRead(IR_Sensor_INPUT); // read the IR_Sensor

if( (val == 0) && (hitObject == false) ){ // this code will execute when object in range

counter++;

hitObject = true;

EEPROM.write(addr, counter); // store the count value in EEPROM

Serial.print("Counter = ");

lcd.print(counter);

led_display();

if(counter == Count_limit){ // this loop will be executed once the count reach the count limit

digitalWrite(Buzzer, HIGH); // buzzer ON 30 sec

lcd.setCursor(0,2);

lcd.print("Cnt Lmt Reached!");

lcd.setCursor(0,3);

lcd.print(" RST");

for (int i =0; i<150; i++){ // LED will blink for 30 sec

Set_Reset_Button_State= digitalRead(Set_Reset_Button); // read the reset button sate(LOW or HIGH)

if (Set_Reset_Button_State== LOW){ //this loop will be executed if the SET button is LOW else stay count limit reached

Set_Reset_Button_State = HIGH;

return;

}else{

digitalWrite(LED,HIGH);

delay(100);

digitalWrite(LED,LOW);

delay(100);

}

}

delay(30000);

digitalWrite(Buzzer, LOW);

lcd.setCursor(0,2);

lcd.print(" ");

lcd.setCursor(0,3);

lcd.print(" RST");

}

else{

digitalWrite(Buzzer, HIGH);

delay(20);

digitalWrite(Buzzer, LOW);

lcd.setCursor(0,2);

}

}

else if( (val ==1) && (hitObject == true) ){ // this code will execute when object is not in range

hitObject = false;

}

}

else if (Set_Reset_Button_State== LOW){ // this code will execute when reset button pressed

counter = 0;

digitalWrite(Buzzer, HIGH);

delay(200);

digitalWrite(Buzzer, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Object Count:");

lcd.setCursor(0,1);

lcd.print(counter);

led_display();

}

if(Down_Button_State == LOW){ // Count set loop will be executed once down button is pressed.

digitalWrite(Buzzer, HIGH);

delay(70);

digitalWrite(Buzzer, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("last count was:");

lcd.setCursor(0,1);

lcd.print(EEPROM.read(addr));

delay(800);

set_count_limit(); // call set count limit

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Object Count:");

lcd.setCursor(0,1);

counter = 0;

lcd.print(counter);

led_display();

}

}

}

int set_count_limit() //defined the count limit set function here.

{

counter=0;

led_display();

while (Set_Reset_Button_State == HIGH)

{

Set_Reset_Button_State= digitalRead(Set_Reset_Button);

Up_Button_State = digitalRead(UP_button);

Down_Button_State = digitalRead(Down_button);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("SET THE COUNT!");

lcd.setCursor(0,1);

lcd.print("Count Limit:");

lcd.setCursor(0,2);

lcd.print(Count_limit);

lcd.setCursor(0,3);

lcd.print("DOWN UP SET");

delay(50);

if (Up_Button_State == LOW) //Increase the count Limit

{

Count_limit++;

lcd.setCursor(0,2);

lcd.print(Count_limit);

digitalWrite(Buzzer, HIGH);

delay(70);

digitalWrite(Buzzer, LOW);

}

else if(Down_Button_State == LOW) //Decrese the count Limit

{ if (Count_limit > 0)

{

Count_limit--;

lcd.setCursor(0,2);

lcd.print(Count_limit);

digitalWrite(Buzzer, HIGH);

delay(70);

digitalWrite(Buzzer, LOW);

}

}

}

digitalWrite(Buzzer, HIGH);

delay(70);

digitalWrite(Buzzer, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Count Limit Set:");

if(Count_limit==0){ // if the count limit is zero then the counter set infinite limit

lcd.print("infinity");

}else{

lcd.setCursor(0,1);

lcd.print(Count_limit);

}

delay(3000);

}

void led_display(){ // led display function

int digit[8]={0,0,0,0,0,0,0,0};

// lc.clearDisplay(0);

long int temp=counter;

Serial.println( counter);

int j=0,i=0;

for(i=0;temp>0 && i<8;i++ ,temp=temp/10)digit[i]=temp%10;

for(;i<8;i++)digit[i]=0;

delay(1);

}

We have also added links to watch Arduino IDE installation for Windows and Ubuntu in the description. This will help you to understand more about Arduino if you are using it for the First time.


Assembling.

Lets start the assembling now, start installing the Arduino on to the circuit board.

Then move on to the 16 X 4 LCD display.

Take out the seven segment display and connect it to the circuit board using the jumper wire that we had soldered earlier. Similarly connect the IR sensor as well.

Conveyor Belt

We have also created a small conveyor belt prototype using below components.

  1. Stepper Motor

  2. Arduino Uno

  3. L298N Motor Driver

Please refer the below figure to make one by your own.

Arduino Code for Conveyor Belt

#include <Stepper.h>

const int stepsPerRevolution = 1000; // change this to fit the number of steps per revolution

// for your motor

// initialize the stepper library on pins 2 through 5:

Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);


void setup()

{

// set the speed at 10 rpm:

myStepper.setSpeed(10);

}


void loop()

{

Serial.println("clockwise");

myStepper.step(stepsPerRevolution);

}

Fully assembled circuit project look something like this.

Let's test the project

We will go through all the possible scenarios while testing our project. Let’s see the working first, then we will test all the possible scenarios one by one. Watch video.

So, our project is working as per our design. We hope that you enjoyed the Project.

And we would like to thank you once again for reading this article.

Donate Now

Consider supporting TexoBot by contributing to its development. All the content we bring to you is a result of hours of work and dedication towards our viewers.