---
title: "PROJECT 16: ELECTRONIC COUNTER "
description: "An electronic counter tracks events like button presses, pulses, or sensor activations, displaying the count. The microcontroller processes inputs and manages the counting, making counters useful in applications ranging from event tracking to industrial automation. ### Objective - Understand the…"
url: "https://nedu.rw/documentation/project-16-electronic-counter/"
updated: "2026-10-13"
category: InnoKit MPK A100 / Experiments you can do with MPK A100
---

# PROJECT 16: ELECTRONIC COUNTER 

An electronic counter tracks events like button presses, pulses, or sensor activations, displaying the count. The microcontroller processes inputs and manages the counting, making counters useful in applications ranging from event tracking to industrial automation.

### Objective

- Understand the relevance of counter systems in daily life.
- Build a basic electronic counter using an Arduino microcontroller.

This project provides practical experience in creating a simple yet versatile counting system, demonstrating its importance in various fields. 

### Materials to be used

| ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXer60RKq4edh_h_pEWezqRlI3fWVza_n36GZU2fsA0bUgbp73uQS0DWjxpjD0NSpMkS-65rwjiOvYoReJ8vA0fGqIiBuDZBR7z8e6KOLw3hxBUs-FtBWJ2Jb6DbA9FPHbRgCRQZyIEXDBmW5zgYF6wMS4pmgCIk93LWpvykMu8UKndW4-ukfY8?key=EIFaBMwRIuJeDoZo9taXbw) | ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXc1BsDACk437cwk11yVnzZEAMpVhG3y0o8xKi0l91njKPit8Rv8UapOdUBkJ5draBVeQih1-VyhC8Sx4XVx2NqOis8R4rs1oIPdG2TqNF4nilww0KEFpzXLieYTZURln6rxYQfXU5nPE4rh3cO2foTeDcgoaC5sJH7E5FQWYlQ0soTyhm2Zgdk?key=EIFaBMwRIuJeDoZo9taXbw) | ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXey79v-b5TwO_zk5idV_nW3wzd7LfZee-t39w0Rv3WpQoeJmSjgXWnP7fYxni4_F2H9uSFe2mtJ17lWByn40C78ktwQOlUjGb7B8zJI8Nlk_GOko42DLakvub-BLyN8Vk9Ri-0q7yyJfHmTzCriLjzQT6ZrLgkMl0XoZlxLYdYRCWroAQRF-tE?key=EIFaBMwRIuJeDoZo9taXbw) |
| --- | --- | --- |
| ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeXKalFWDYGdiRvC_uE5GuVCaZm7L25dZSE7KPVI3dGpcrR49sMjZxHwt3RAjg2kYi2Kice5cOW7vy7wMEDgPJZsEQRh3dmca28GCN5Tw_vG7LSmwO3iQpsqJnatB95vdarAN0fPwU2SUG7OBDIYLP31tuA7YKVV2Nw6MIrL4vjQgzjPMl8hw?key=EIFaBMwRIuJeDoZo9taXbw) |  |  |

### Circuit diagram

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfz37dYKs-bJN1SAuBbvfmwDlBevAR5B0rUjT2ZfvxPeM7MBOtHI6msE-pKsGeZmyA6YHAjnPVxXOfEw59sOYohtUf3ORtT0Yitmqm6EDXhIg3yoCdpDmZMXFJCXM6KTOK58E97BGzEZchCEDZ122Wm9UOg6X0ipsISARALdA?key=EIFaBMwRIuJeDoZo9taXbw)

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfp3BvYwOcDS4AOB6pQQ_RqdBS1GMHfmAMcu9IRI7cizHBmubMb9V6HWOWuBrDSMzjEf-_a03dRqaFD00pCvO6RYu69ocqnyuihY1aJv2O35AxDrDpfHxS_CewMF8ru1-iIg5qMMZ5IA5SpAB81Dw?key=EIFaBMwRIuJeDoZo9taXbw)

***Figure: Schematic diagram for LCD display connection***

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcDk7JdQMTpGTwuewvRjJOEdjSQkCHQE9nD1O-SjeLiOmSUaD_0GDzyhsgtFsM3_Ixwnoq3hECon0r7Ypot3o8lCJEu-d5fhVuByyfwEPJto0QT1pk5AuHLlamCzscGAXQDJVZFxPlmcaQ3a5HFdg?key=EIFaBMwRIuJeDoZo9taXbw)

***Figure: Components used to make connection on the board***

### Arduino Codes

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26   #include LiquidCrystal.h> // library of liquidcrystal const int  rs =12, en=11, d4=5, d5=4, d6=3, d7=2; LiquidCrystal lcd(rs,en,d4,d5,d6,d7); int x = 0; int input = A0; int state = 0; void setup(){ Lcd.setCursor(0, 0); Lcd.print(" Turn counter "); Lcd.setCursor(0, 1); Lcd.print(x); Lcd.print(" =turn "); } void loop(){ int counter = digitalRead(A0); if (state == 0) {  switch (counter) {  case 1 : state = 1; lcd.setCursor (0, 1); x = x + 1; lcd.print(x); break;  case 0 : state = 0;   break; } } if (counter == LOW) {  state = 0; } }

## Code knowledge

    4 5 6    int x = 0; int input = A0; int state = 0;

The variable **x** counts the number of turns or events. **input** refers to the analog input pin A0, used to read a sensor or input signal. **state** tracks the current state of the input.

    7 8 9 10 11 12 13    void setup(){ Lcd.setCursor(0, 0); Lcd.print(" Turn counter "); Lcd.setCursor(0, 1); Lcd.print(x); Lcd.print(" =turn "); }

This function runs once when the Arduino is powered on or reset.

- *lcd.setCursor(0, 0):* This sets the cursor to the first row (row 0) and first column (column 0) of the LCD.
- *lcd.print("Turn counter"):* This displays the text "Turn counter" on the first line of the LCD.
- *lcd.setCursor(0, 1):* Moves the cursor to the second row (row 1) and the first column (column 0).
- *lcd.print(x):* Displays the value of x (which starts at 0).
- *lcd.print(" =turn"):* Displays the text " =turn" after the x value.

    15 16    void loop(){ int counter = digitalRead(A0);

The loop() function runs continuously after the setup() function.

int counter = digitalRead(A0): This reads the digital state of pin A0 (either HIGH or LOW) and stores the result in the counter variable. Although A0 is an analog pin, you can use it for digital input. It reads HIGH (1) or LOW (0) depending on the input connected to it (e.g., a button, switch, or sensor).

    18 19 20 21 22 23 24 25    if (state == 0) {  switch (counter) {  case 1 : state = 1; lcd.setCursor (0, 1); x = x + 1; lcd.print(x); break;  case 0 : state = 0;   break; } }

if (state == 0): This checks if the state is 0 (meaning the system is waiting for input. The input in this context is when a person enters the place to be counted).

switch (counter): This is a switch statement that acts based on the value of counter:

- case 1: If counter is 1 (HIGH), it changes the state to 1, increments x by 1, and updates the LCD to display the new value of x.
- case 0: If counter is 0 (LOW), the state remains 0 (waiting for input).

    27 28 29 30    if (counter == LOW) {  state = 0; } }

if (counter == LOW): This condition ensures that when the counter reads LOW, the state is reset to 0, meaning it's waiting for the next input or turn.

### Results

The logic increments a counter (x) whenever the input signal changes.

**The LCD displays:**

- Top Row (Row 0): " Turn counter "
- Bottom Row (Row 1): "0 =turn " This shows the initial counter value, x = 0.

On each increment, the LCD updates the bottom row to reflect the new value of x.

For example:

- After the first HIGH signal: "1 =turn "
- After the second HIGH signal: "2 =turn ", and so on.

**Visible Output: **

- ***Initial State****:* 

Turn counter  

**0** =turn

- ***After Incrementing (e.g., 3 turns)****:       *

Turn counter 

**3** =turn  The display updates correctly with the new counter value every time the signal on **A0** transitions from LOW to HIGH.
