Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO LED Blinking and LCD Display Control with Pushbuttons

View and Edit Project In Cirkit DesignerImage of Arduino UNO LED Blinking and LCD Display Control with Pushbuttons

Circuit Documentation

Summary

This circuit is designed to control an array of LEDs and an LCD screen using an Arduino UNO. The user can select different modes using pushbuttons. Modes include random LED blinking at different speeds and all LEDs blinking simultaneously. The selected mode is displayed on the LCD screen.

Component List

  1. Resistor (1000 Ohms)

    • Pins: pin1, pin2
    • Description: Standard resistor used to limit current to LEDs.
  2. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Red LED used for visual indication.
  3. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller used to control the LEDs and LCD screen.
  4. LCD screen 16x2 I2C

    • Pins: SCL, SDA, VCC, GND
    • Description: 16x2 character LCD screen with I2C interface.
  5. Pushbutton

    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
    • Description: Pushbutton used to select different modes.

Wiring Details

Resistor (1000 Ohms)

LED: Two Pin (red)

Arduino UNO

LCD screen 16x2 I2C

Pushbutton

Code Documentation

Arduino UNO Code

// This Arduino sketch controls an array of LEDs and an LCD screen. The user can
// select different modes using pushbuttons. Modes include random LED blinking
// at different speeds and all LEDs blinking simultaneously. The selected mode
// is displayed on the LCD screen.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the I2C LCD (address: 0x27, columns: 16, rows: 2)
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define LED and switch pins
const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
const int numLeds = 9;
const int switchPins[] = {A0, A1, A2, A3};

// Variables for timing
int delayTime = 500; // Default delay for blinking
unsigned long mode4StartTime = 0;
bool mode4Active = false;

// Setup function
void setup() {
  // Initialize LCD
  lcd.init();
  lcd.backlight();

  // Set LED pins as output
  for (int i = 0; i < numLeds; i++) {
    pinMode(ledPins[i], OUTPUT);
    digitalWrite(ledPins[i], LOW);
  }

  // Set switch pins as input
  for (int i = 0; i < 4; i++) {
    pinMode(switchPins[i], INPUT_PULLUP);
  }

  // Display initial message
  lcd.setCursor(0, 0);
  lcd.print("Select a Mode");
}

// Random LED blinking function
void randomBlink(int delayTime) {
  int randomLed = random(0, numLeds);
  digitalWrite(ledPins[randomLed], HIGH);
  delay(delayTime);
  digitalWrite(ledPins[randomLed], LOW);
  delay(delayTime);
}

// All LEDs on/off function
void allLedsOnOff(int duration) {
  for (int i = 0; i < numLeds; i++) {
    digitalWrite(ledPins[i], HIGH);
  }
  delay(duration);
  for (int i = 0; i < numLeds; i++) {
    digitalWrite(ledPins[i], LOW);
  }
  delay(duration);
}

// Loop function
void loop() {
  // Check for mode switches
  if (digitalRead(switchPins[0]) == LOW) {
    // Mode 1: Random LED blink
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mode 1: Random");
    delayTime = 500; // Default speed
    mode4Active = false; // Exit mode 4
  } else if (digitalRead(switchPins[1]) == LOW) {
    // Mode 2: Slow random blink
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mode 2: Slow");
    delayTime = 1000;
    mode4Active = false;
  } else if (digitalRead(switchPins[2]) == LOW) {
    // Mode 3: Fast random blink
    lcd.clear();