LCD Module in Arduino alarm clock

I am using the following components to build an Arduino alarm clock. The breadboard is numbered from 1-30 and from A-J.

  1. Arduino Uno R3

  2. I2C 1602 LCD Display Module

  3. Real Time Clock (RTC) module (DS3231)

  4. 3 x Twidec PBS-110-X6C Momentary Push Buttons

  5. Gikfun Passive Electronic Buzzer (EK2146)

  6. 3 x 10kΩ resistors

  7. Breadboard

  8. Jumper wires . The three Twidec PBS-110-X6C Momentary Push Buttons are connected to Arduino pin A8, A9 and A10 through the breadboard holes 5A, 10A and 15A. The Buzzer is connected to Arduino pin A11 through breadboard hole 20A. The LCD module is not working. Kindly advise.

Make a hand drawn diagram and photograph it then post.
Post all source code in code tags.

Is this a group of parts you ordered, or a complete kit?
What instructions accompanied the parts/kit?

I ordered the parts individually from Amazon.

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

// Define LCD address and pins
const int lcdAddress = 0x27;
const int lcdColumns = 16;
const int lcdRows = 2;

// Define button pins
const int buttonSet = 8;
const int buttonUp = 9;
const int buttonDown = 10;

// Define buzzer pin
const int buzzer = 11;

// Initialize LCD
LiquidCrystal_I2C lcd(lcdAddress, lcdColumns, lcdRows);

// Alarm variables
int alarmHour = 0;
int alarmMinute = 0;
bool alarmSet = false;

// Time-keeping variables
unsigned long previousMillis = 0;
int currentHour = 0;
int currentMinute = 0;
int currentSecond = 0;

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

  // Initialize buttons as inputs
  pinMode(buttonSet, INPUT);
  pinMode(buttonUp, INPUT);
  pinMode(buttonDown, INPUT);

  // Initialize buzzer as output
  pinMode(buzzer, OUTPUT);

  // Display initial message
  lcd.setCursor(0, 0);
  lcd.print("Alarm Clock");
  lcd.setCursor(0, 1);
  lcd.print("Time: ");
}

void loop() {
  // Read buttons
  int buttonStateSet = digitalRead(buttonSet);
  int buttonStateUp = digitalRead(buttonUp);
  int buttonStateDown = digitalRead(buttonDown);

  // Update time
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= 1000) {
    previousMillis = currentMillis;
    currentSecond++;
    if (currentSecond >= 60) {
      currentSecond = 0;
      currentMinute++;
      if (currentMinute >= 60) {
        currentMinute = 0;
        currentHour++;
        if (currentHour >= 24) {
          currentHour = 0;
        }
      }
    }
  }

  // Set alarm
  if (buttonStateSet == HIGH) {
    alarmSet = true;
    lcd.setCursor(0, 1);
    lcd.print("Alarm Set");
    delay(1000);
  }

  // Increase alarm time
  if (buttonStateUp == HIGH) {
    if (alarmHour < 23) {
      alarmHour++;
    } else {
      alarmHour = 0;
    }
    lcd.setCursor(0, 1);
    lcd.print("Alarm: ");
    lcd.print(alarmHour);
    lcd.print(":");
    lcd.print(alarmMinute);
    delay(200); // Debounce
  }

  // Decrease alarm time
  if (buttonStateDown == HIGH) {
    if (alarmHour > 0) {
      alarmHour--;
    } else {
      alarmHour = 23;
    }
    lcd.setCursor(0, 1);
    lcd.print("Alarm: ");
    lcd.print(alarmHour);
    lcd.print(":");
    lcd.print(alarmMinute);
    delay(200); // Debounce
  }

  // Check if it's alarm time
  if (alarmSet && currentHour == alarmHour && currentMinute == alarmMinute) {
    // Activate buzzer
    digitalWrite(buzzer, HIGH);
    delay(1000);
    digitalWrite(buzzer, LOW);
  }

  // Display current time
  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(currentHour);
  lcd.print(":");
  lcd.print(currentMinute);
  lcd.print(":");
  lcd.print(currentSecond);

  delay(100);
}

Can you verify your LCD is an I2C LCD? Would you post a picture of the back side of the LCD?

That is good. It is an I2C LCD. Please upload a picture of the wiring so we can see each end of every wire.

1. Set Time Button (Arduino Pin 8)

  • Place the button across the center divider on rows 5 and 6.
  • Button Leg 1 (left side): Insert into E5.
  • Button Leg 2 (right side): Insert into F5.
  • Arduino Pin Connection:
    • Connect F5 to Arduino Pin 8 with a jumper wire.
  • Pull-Down Resistor:
    • Place one end of a 10kΩ resistor in F5 (same as the Arduino pin connection).
    • Connect the other end to GND by placing it in F30 (or any other GND-connected rail).

2. Set Alarm Button (Arduino Pin 9)

  • Place the button across the center divider on rows 10 and 11.
  • Button Leg 1 (left side): Insert into E10.
  • Button Leg 2 (right side): Insert into F10.
  • Arduino Pin Connection:
    • Connect F10 to Arduino Pin 9 with a jumper wire.
  • Pull-Down Resistor:
    • Place one end of a 10kΩ resistor in F10 (same as the Arduino pin connection).
    • Connect the other end to GND by placing it in F30 (or any other GND-connected rail).

3. Adjust Button (Arduino Pin 10)

  • Place the button across the center divider on rows 15 and 16.
  • Button Leg 1 (left side): Insert into E15.
  • Button Leg 2 (right side): Insert into F15.
  • Arduino Pin Connection:
    • Connect F15 to Arduino Pin 10 with a jumper wire.
  • Pull-Down Resistor:
    • Place one end of a 10kΩ resistor in F15 (same as the Arduino pin connection).
    • Connect the other end to GND by placing it in F30 (or any other GND-connected rail).

Power Connections:

  • 5V: Run a jumper wire from the Arduino’s 5V pin to the breadboard’s top positive (+) power rail.
  • GND: Run a jumper wire from the Arduino’s GND pin to the breadboard’s bottom negative (-) power rail

F20** (Positive leg of the buzzer) → Arduino Pin A11.
F21** (Negative leg of the buzzer) → GND rail on the breadboard.

Unreadable picture. Draw the circuit.

The code does things (but needs work), so the problem is in the wiring.

Hello kebasita30

Welcome to the best Arduino forum ever :slight_smile:

Take a view to gain the knowledge.

hth

Three 10K ohms resistors, 5V buzzer , I2C 1602 LCD Display Module and Real Time Clock (RTC) module (DS3231) were used for this alarm clock. The LCD does not work.

Does your sketch upload?
Do you see any LEDs on the Arduino light?

For the LCD only, look at the pin labels of the LCD... where do the four pins go?

Hi, @kebasita30

Have you tried one of the example codes that comes with the Library you are using.

Don't try and write a lump of code to try and get everything to work at once.

Write code JUST for each if your peripherals and get it working, before putting them together one at a time.

So start with your display and a library example to prove you have communication with it and control.

Tom.. :smiley: :+1: :coffee: :australia:

Have you run an I2C scanner sketch to verify the I2C address of the display?

Yes, I uploaded the sketch. Jumper wires from the VCC and GND pins of the LCD are connected to the breadboard power rail at line 25 (+ and - respectively). There are also GND connections from 5G, 10G and 15G to the (-) rails respectively. The lights on the Arduino and the D3231 are on but the light on the LCD also flickers.