Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
PCBX
Published

Arduino-Based Counter with LED on Multiples of Three

A simple triple LED counter circuit based on Arduino that teaches programming and electronics, perfect for projects and education.

BeginnerProtip96

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
HD44780 LCD Display
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Online Simulation
PCBX Online Simulation

Story

Read more

Schematics

Arduino-Based Counter with LED

Code

Arduino-Based Counter with LED on Multiples of Three

Arduino
#include <LiquidCrystal.h>

// Initialize the LCD, setting the pins connected to the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2, 10, 9, 8, 7);
// Define the LED pin
const int ledPin = 13;
// Define the LED blink counter
int ledBlinks = 0;

void setup() {
  // Initialize the LCD display
  lcd.begin(16, 2);
  // Initialize the LED pin as output mode
  pinMode(ledPin, OUTPUT);
  // Clear the LCD display
  lcd.clear();
  // Display initial message
  lcd.print("Counting to 100...");
}

void loop() {
  for (int count = 1; count <= 100; count++) {
    // Each time the counter is incremented, display it on the LCD
    lcd.clear(); // Clear the LCD display
    lcd.print("Count: ");
    lcd.print(count);
    
    // Check if the count is a multiple of 3
    if (count % 3 == 0) {
      // Turn on the LED
      digitalWrite(ledPin, HIGH);
      // Wait for one second so you can see the LED light up
      delay(1000);
      // Turn off the LED
      digitalWrite(ledPin, LOW);
      // Increment the LED blink counter
      ledBlinks++;
    }
    
    // Wait a bit before continuing to count so you can read the numbers on the LCD
    delay(1000);
  }
  
  // After counting, display the final message
  lcd.clear();
  lcd.print("Done! Counted to 100");
  lcd.setCursor(0, 1); // Move the cursor to the second line
  lcd.print("LED Blinks: ");
  lcd.print(ledBlinks);
  
  // Stop the program
  while (true);
}

Credits

PCBX
33 projects • 9 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.