Lois
Published © CERN-OHL2

Arduino-Based Counter with LED on Multiples of Three

This is a triple LED counter circuit based on Arduino.

BeginnerProtip53

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Online Simulation
PCBX Online Simulation

Hand tools and fabrication machines

Materia 101
Arduino Materia 101

Story

Read more

Schematics

Arduino-Based Counter with LED on Multiples of Three

Initializes LCD, sets LED as output. Clears LCD, displays "Counting to 100...". Counts 1-100, displays count, blinks LED for multiples of three, counts blinks. After count, shows "LED Blinks: X" and halts.After count, shows "LED Blinks: X" and halts: Once the count reaches 100, the program stops incrementing and displays the total number of LED blinks on the LCD. The program then halts, and the final message remains on the display.

Code

Arduino-Based Counter with LED on Multiples of Three

Arduino
Initializes LCD, sets LED as output. Clears LCD, displays "Counting to 100...". Counts 1-100, displays count, blinks LED for multiples of three, counts blinks. After count, shows "LED Blinks: X" and halts.After count, shows "LED Blinks: X" and halts: Once the count reaches 100, the program stops incrementing and displays the total number of LED blinks on the LCD. The program then halts, and the final message remains on the display.
#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

Lois
13 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.