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

ESP32-Based I2C LCD Button State Display

View and Edit Project In Cirkit DesignerImage of ESP32-Based I2C LCD Button State Display

Circuit Documentation

Summary

This circuit consists of an ESP32 Wemos microcontroller, a pushbutton, and an I2C LCD 16x2 screen. The ESP32 Wemos reads the state of the pushbutton and displays the button state on the LCD screen. The components are interconnected to facilitate communication and power distribution.

Component List

ESP32 Wemos

Pushbutton

I2C LCD 16x2 Screen

Comment

Wiring Details

ESP32 Wemos

Pushbutton

I2C LCD 16x2 Screen

Code Documentation

/*
 * This Arduino Sketch initializes an I2C LCD screen and reads the state of a
 * pushbutton. The button state is displayed on the LCD screen.
 */

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

// Define the I2C address for the LCD
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2

// Initialize the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_ROWS);

// Define pin for the pushbutton
const int buttonPin = 17;

void setup() {
  // Initialize the LCD
  lcd.begin(LCD_COLUMNS, LCD_ROWS);
  lcd.backlight();
  lcd.print("Button State:");

  // Initialize the pushbutton pin as an input
  pinMode(buttonPin, INPUT);
}

void loop() {
  // Read the state of the pushbutton
  int buttonState = digitalRead(buttonPin);

  // Display the button state on the LCD
  lcd.setCursor(0, 1);
  if (buttonState == HIGH) {
    lcd.print("Pressed ");
  } else {
    lcd.print("Released");
  }

  // Small delay to debounce the button
  delay(50);
}

This code initializes the I2C LCD screen and sets up the pushbutton pin as an input. In the main loop, it reads the state of the pushbutton and displays the state ("Pressed" or "Released") on the LCD screen. A small delay is added to debounce the button.