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

ESP32-Based Smart Timer with Keypad and LCD Display for Water Pump Control

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Timer with Keypad and LCD Display for Water Pump Control

Circuit Documentation

Summary

This circuit is designed to control a water pump using an ESP32 microcontroller. The system includes a 4x4 keypad for user input, a 16x2 I2C LCD for display, an L298N motor driver to control the water pump, a buzzer for audio alerts, and an LED for visual indicators. The user can set a timer using the keypad, and the water pump will run for the specified duration. The LCD displays the remaining time, and the buzzer sounds when the timer ends.

Component List

  1. ESP32 Wroom Dev Kit

    • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: 3V3, EN, VP, VN, GPIO 34, GPIO 35, GPIO 32, GPIO 33, GPIO 25, GPIO 26, GPIO 27, GPIO 14, GND, GPIO 13, SD2, SD3, CMD, V5, GPIO 23, GPIO 22, TXD, RXD, GPIO 21, GPIO 19, GPIO 18, GPIO 5, GPIO 17, GPIO 16, GPIO 4, GPIO 0, GPIO 2, GPIO 15, SD1, SD0, CLK
  2. Water Pump 12V

    • Description: A 12V DC water pump.
    • Pins: +, -
  3. 4x4 Keypad (Simulator)

    • Description: A 4x4 matrix keypad for user input.
    • Pins: R1, C4, R2, C2, R3, R4, C1, C3
  4. L298N DC Motor Driver

    • Description: A dual H-Bridge motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  5. 16x2 I2C LCD

    • Description: A 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  6. Buzzer

    • Description: A simple buzzer for audio alerts.
    • Pins: PIN, GND
  7. LED: Two Pin (Red)

    • Description: A red LED for visual indicators.
    • Pins: Cathode, Anode

Wiring Details

ESP32 Wroom Dev Kit

Water Pump 12V

4x4 Keypad (Simulator)

L298N DC Motor Driver

16x2 I2C LCD

Buzzer

LED: Two Pin (Red)

Code Documentation

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

const byte ROW_NUM = 4;
const byte COLUMN_NUM = 4;

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte pin_rows[ROW_NUM] = {14, 27, 26, 25};
byte pin_column[COLUMN_NUM] = {33, 32, 35, 34};

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);

int timerSeconds = 0;
int initialTime = 0;

Ticker timerTicker;
Ticker ledTicker;

bool timerActive = false;
bool ledState = false;

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int ledPin = 13;
const int buzzerPin = 12;

// Motor control pins for L298N motor driver
const int motorPin1 = 18; // IN1
const int motorPin2 = 19; // IN2

void setup() {
  Serial.begin(115200);
  
  lcd.begin();
  lcd.setBacklight(true);

  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);

  digitalWrite(buzzerPin, LOW);
  stopMotor();

  timerTicker.attach(1, timerTick);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Enter time in sec:");
  lcd.setCursor(0, 1);
  lcd.print("Use keys 0-9");
}

void loop() {
  char key = keypad.getKey();
  if (key) handleKeyInput(key);

  if (timerActive) updateDisplay();
}

void handleKeyInput(char key) {
  Serial.print("Key pressed: ");
  Serial.println(key);
  
  if (key >= '0' && key <= '9') {
    timerSeconds = timerSeconds * 10 + (key - '0');
    displayTimeSetting();
  }
  
  if (key == 'A' && timerSeconds > 0) startTimer();
  if (key == 'B') resetTimer();
}

void displayTimeSetting() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time set:");
  lcd.setCursor(0, 1);
  displayTime(timerSeconds);
}

void startTimer() {
  initialTime = timerSeconds;
  timerActive = true;
  lcd.clear();
  lcd