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

Arduino-Controlled LCD Interface with Button Selection and Potentiometer Contrast Adjustment

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled LCD Interface with Button Selection and Potentiometer Contrast Adjustment

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a 16x2 LCD display using an Arduino UNO microcontroller. The display's contrast is adjustable via a rotary potentiometer, and a pushbutton is used to switch between three different display messages. The LCD is interfaced with the Arduino through digital pins, and the potentiometer is connected to an analog input for contrast control. The pushbutton is debounced in software and triggers a change in the displayed message when pressed.

Component List

16X2 LCD

Resistor (220 Ohms)

Resistor (10k Ohms)

Pushbutton

Arduino UNO

Rotary Potentiometer (10k Ohms)

Wiring Details

16X2 LCD

Resistor (220 Ohms)

Resistor (10k Ohms)

Pushbutton

Arduino UNO

Rotary Potentiometer (10k Ohms)

Documented Code

/*
 * This Arduino sketch controls a 16x2 LCD display with a button and a potentiometer.
 * The button switches between three different display messages.
 * The potentiometer adjusts the contrast of the LCD.
 */

#include <LiquidCrystal.h>

// LCD pin connections
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Button and potentiometer pin connections
const int buttonPin = 7;
const int potPin = A0;

// Variables to store button state and display mode
int buttonState = 0;
int lastButtonState = 0;
int displayMode = 0;

void setup() {
  // Initialize the LCD
  lcd.begin(16, 2);
  lcd.print("Hello, World!");

  // Set button pin as input
  pinMode(buttonPin, INPUT);
}

void loop() {
  // Read the button state
  buttonState = digitalRead(buttonPin);

  // Check if the button is pressed
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      // Change display mode
      displayMode = (displayMode + 1) % 3;
      updateDisplay();
    }
    delay(50); // Debounce delay
  }
  lastButtonState = buttonState;

  // Read the potentiometer value
  int potValue = analogRead(potPin);
  int contrast = map(potValue, 0, 1023, 0, 255);
  analogWrite(6, contrast); // Adjust contrast (assuming pin 6 is used for contrast)
}

void updateDisplay() {
  lcd.clear();
  switch (displayMode) {
    case 0:
      lcd.print("Display Mode 1");
      break;
    case 1:
      lcd.print("Display Mode 2");
      break;
    case 2:
      lcd.print("Display Mode 3");
      break;
  }
}

Note: The code assumes that pin 6 is used for contrast adjustment, but this is not reflected in the wiring details provided. Please ensure that the correct pin is used for the contrast control or modify the code accordingly.