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

ESP32-Based Guest Counter with 4x4 Keypad and 16x2 I2C LCD

View and Edit Project In Cirkit DesignerImage of ESP32-Based Guest Counter with 4x4 Keypad and 16x2 I2C LCD

Circuit Documentation

Summary

This circuit is designed to function as a guest counter system. It utilizes an ESP32 microcontroller to interface with a 4x4 membrane matrix keypad and a 16x2 I2C LCD display. The keypad is used to input guest information, and the LCD displays the total number of guests, as well as the count of male and female guests.

Component List

ESP32

4x4 Membrane Matrix Keypad

16x2 I2C LCD

Wiring Details

ESP32 to 4x4 Membrane Matrix Keypad

ESP32 to 16x2 I2C LCD

Code Documentation

Code Overview

The code initializes the LCD and keypad, and then enters a loop where it waits for key presses. Depending on the key pressed, it updates the guest count and displays the information on the LCD.

Code Listing

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

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

// Keypad configuration
const byte ROWS = 4; // 4 rows
const byte COLS = 4; // 4 columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {32, 33, 19, 23}; // Row pins connected to ESP32
byte colPins[COLS] = {25, 26, 27, 14}; // Column pins connected to ESP32

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Guest count variables
int totalGuests = 0;
int maleGuests = 0;
int femaleGuests = 0;

void setup() {
  lcd.begin();
  lcd.backlight();
  
  // Initial display
  lcd.setCursor(0, 0);
  lcd.print("Guest Counter");
  delay(2000);
  lcd.clear();
  updateDisplay();
}

void loop() {
  char key = keypad.getKey(); // Get keypress from the keypad

  if (key) {
    // Handle male guest count
    if (key == 'A') {
      maleGuests++;
      totalGuests++;
      lcd.clear();
      lcd.print("Male Added");
      delay(1000);
    }
    // Handle female guest count
    else if (key == 'B') {
      femaleGuests++;
      totalGuests++;
      lcd.clear();
      lcd.print("Female Added");
      delay(1000);
    }
    // Reset counts
    else if (key == 'C') {
      totalGuests = 0;
      maleGuests = 0;
      femaleGuests = 0;
      lcd.clear();
      lcd.print("Reset Done");
      delay(1000);
    }
    updateDisplay(); // Update LCD with counts
  }
}

// Function to update LCD display with counts
void updateDisplay() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Total: ");
  lcd.print(totalGuests);
  lcd.setCursor(0, 1);
  lcd.print("M:");
  lcd.print(maleGuests);
  lcd.print(" F:");
  lcd.print(femaleGuests);
}

Code Explanation

This documentation provides a comprehensive overview of the circuit, components, wiring, and code used in the guest counter system.