Tag Archives | calculator

Liquid Crystal Display Setup, Control & Calculator

A common Arduino system typically includes a display of some type. This project was to set up a 16×2 LCD display to an Arduino unit and run it with simple messages that render it available for inputs or computational processing. It produces an informational output of its own, or to correspond to another event controlled by a wider system.

While the LCD display takes up several digital GPIO pins, there are several more remaining to build additional system functions. As either inputs or outputs, the display can read sensor data and trigger a relay, an alarm, or other device as specified. The potentiometer in the project as illustrated in the schematic below controls the LCD character block brightness.
Aside from any additional inputs, controls, or outputs, the LCD can display processes that run within the Arduino unit. Even as depicted here such as a counter or a calculator.

The physical connections between the Arduino and LCD display are through direct jumper connections between GPIO pins to data, control, power, and ground. The potentiometer is simply for character illumination intensity.

The digital GPIO pins that interface to the LCD connect to its data pins. R/W is strapped low to ground.

Arduino 16×2 LCD System Schematic

1602A LCD Display Pinout

PinSymbolFunction
1VSSGround
2VDD+5VDC
3V0Contrast
4RSRegister
5R/WRead/Write
6EEnable
7D0Data
8D1Data
9D2Data
10D3Data
11D4Data
12D5Data
13D6Data
14D7Data
15AAnode (+5VDC)
16KCathode (Ground)

Program & Functional Operation:



Code Setup:

#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
lcd.begin(16,2);
}

void loop() {
lcd.setCursor(0,0);
lcd.print(“Counter:”);
lcd.setCursor(0,1);
lcd.print(“Hello James”);
for (int j=1;j<=10;j=j+1){
lcd.setCursor(9,0);
lcd.print(j);
delay(500);
}
lcd.clear();
}

Arduino Setup:

Calculator Setup:

#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;

float firstNum;
float secNum;
float answer;

String op;

LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
lcd.begin(16,2);
Serial.begin(9600);
}

void loop() {

lcd.setCursor(0,0);
lcd.print(“Input 1st Number”);
while (Serial.available()==0){
}
firstNum=Serial.parseFloat();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Input 2nd Number”);
while (Serial.available()==0){
}
secNum=Serial.parseFloat();

lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Operator(+,-,*,/)”);
while (Serial.available()==0){
}
op=Serial.readString();

if (op==”+”){
answer=firstNum+secNum;
}
if (op==”-“){
answer=firstNum-secNum;
}
if (op==””){
answer=firstNumsecNum;
}
if (op==”/”){
answer=firstNum/secNum;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(firstNum);
lcd.print(op);
lcd.print(secNum);
lcd.print(” = “);
lcd.print(answer);
lcd.setCursor(0,1);
lcd.print(“Thank You”);
delay(10000);
lcd.clear();
}