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

Arduino UNO-Based Keypad-Controlled I2C LCD Display System

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Keypad-Controlled I2C LCD Display System

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a 16x2 I2C LCD display, and a 4x4 Keypad. The Arduino UNO serves as the central controller, interfacing with the LCD to display messages and with the keypad to receive user input. The LCD is connected via I2C protocol, while the keypad is connected through digital I/O pins.

Component List

16x2 I2C LCD

Arduino UNO

4x4 Keypad (Simulator)

Wiring Details

16x2 I2C LCD

Arduino UNO

4x4 Keypad (Simulator)

Code Documentation

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

// Configuração do display I2C
LiquidCrystal_I2C lcd(0x27, 16, 2); // Endereço I2C pode variar (0x27 ou 0x3F)

// Configuração do Keypad
const byte ROWS = 4; // Número de linhas
const byte COLS = 3; // Número de colunas utilizadas

// Mapeamento das teclas do keypad
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

// Pinos conectados às linhas e colunas do keypad
byte rowPins[ROWS] = {8, 7, 6, 5};    // Linhas (R1, R2, R3, R4)
byte colPins[COLS] = {4, 3, 2};       // Colunas (C1, C2, C3)

// Inicialização do Keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Variáveis para armazenar o código digitado
String code = "";

void setup() {
  // Inicialização do display
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Digite o codigo:");
}

void loop() {
  char key = keypad.getKey(); // Lê a tecla pressionada

  if (key) { // Se uma tecla foi pressionada
    if (key == '#') {
      // Confirmação do código
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Codigo: " + code);
      delay(2000);
      
      // Limpa o display e reinicia o código
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Digite o codigo:");
      code = "";
    } else if (key >= '0' && key <= '9') {
      // Adiciona o número ao código e exibe no display
      code += key;
      lcd.setCursor(0, 1);
      lcd.print(code);
    }
  }
}

This code initializes the I2C LCD and the keypad, then continuously reads input from the keypad. When a key is pressed, it updates the display accordingly. If the '#' key is pressed, it confirms the entered code, displays it, and then resets the display for a new input.