You are on page 1of 6

MIcrocontroller Projects (/)

AllAboutMicrocontro

SearchSiteForMoreAtmel,Arduino,8051andPicSeriesMicrocontrollerProject
CustomSearch

sIncaseanyhelpisrequired,regardinganyProject.

Home(/)
Microcontroller
projects
(/microcontroller
projects.html)
Knowledgebased
(/knowledge
based.html)
Arduino
(/arduino.html)
LcdInterfacing
(/lcd
interfacing.html)
AboutMe(/about
me.html)
ContactMe
(/contactme.html)
Microco...
2.4klikes

MakingTwodigitcalculatorwithArduino,16x2lcdand4x4keypad

Here is a simple one digit calculator made using Arduino uno,4x4 keypad and 16x2 lcd. Calculator can perform four function
multiplication and division. Code is easy to understand but its lengthy. If you are already familiar with the arduino coding
understandthecodebelow.Ifyouarenotthantakesometutorialstobecomefamiliarwitharduinolanguagesyntax.
ProjectRequirements
Arduinouno(Microcontroller)
4x4Keypad(TakinginputfromUsers)
16x2Lcd(DisplaysResult)
Potentiometer(SettingLcdContrast)

Arduinounoisusedasmicrocontrollerittakestheinputandafteranalyzingtheinstructionsproducesoutput.Whichisthandisp

keypadisusedasnumerickeypadtogiveinputs(digits)tocalculator.Calculatortakestwodigitsandanoperatorasinput,analyz

computesresultsaccordingtotheoperatorfuntion.16x2lcdisinterfacedin4bitmodewitharduinouno.Keypadrowsareconn

ofarduinouno.Coulombsofkeypadareconnectedtopins0,1,2&3ofarduino.Lcdisinterfacedin4bitmodewitharduino.Pin
usedtointerfacelcdwitharduino.

Itsnotpossibletoexplaineachandeverylogichere.ThereforIrecommendyoutakethetutorialslistedbelow.Thesetutorials
16x2lcdand4x4keypadwitharduino.
HOWTOINTERFACE16x2LCDIN4BITMODEWITHARDUINO(/howtouselcdin4bitmodewitharduino.html)
HOWTOINTERFACE4X4KEYPADWITHARDUINO.(/4x44x3numerickeypadprogrammingwitharduino.html)

LikePage

Bethefirstofyour
friendstolikethis

Microcontroller
Projectsshared
TechInsider's
video.
46min

11,101,883Views
TechInsider

LikePage
October23at
1:00pm

Thetutorialsaboveareveryimportant.Ifyoutakethemitsbecomeeasierforyoutounderstandthecalculatorcodebelow.Ifyo

interfacecharacterlcd(16x2)and4x4keypadwitharduino,youcanskiptheabovetutorials.CircuitDiagramoftheprojectisgive

(/uploads/2/2/1/5/22159166/5519102_orig.jpg)

CalculatorwithArduinouno,16x2lcdand4x4keypadCircuitDiagram

Firstoffall,LiquidCrystallibraryisimportedforlcdusage.Iamusing16x2lcdin4bitmode.Thansomefunctionsaredefined.E
thefunctionstheyperformarelistedbelow.
intgetKey()istakinginputs,digitsfromkeypad.
chargetOper()istakinginput,Operatorfromkeypad.
voidresult(floatresult)Displayingresultonlcd.

Nexttwostatementsdefinerowsandcoulombsofkeypad.key1isanintegerwhichcontainsfirstdigitthatisinputtedbyuser,us

an integer that contains second digit inputted by the user. oper is character variable that contains the operator inputted by u

setup()function,lcd.begin(16,2)statementinitializesthelcd.ThanrowsofkeypadareinitializedasoutputandCoulombsareinitia

Thefirststringthatappearsonthescreenwhenyoudownloadthecodeinarduinoboardandrunitis"CALCULATOR!!!!"itrema

secondsdelay(4000)statementmeansstopexecutionofinstructionsfor4seconds.After4secondsatextwillappearonlcdas

Youenterthefirstdigitusingkeypad.Thansecondstringisdisplayedonlcdaskingforseconddigit"Enter2no=".Youentert

thirdstringappearsonlcdaskingtoinputoperator"Operator=".Youentertheoperator.Afteryouentertheoperatorresultwillb

outanyfurtherdelay.Resultofaparticularinputsremainonlcdfor5seconds.After5secondslcdclearsallthetextdisplaye
beginning.Takingdigits,operatoretcandproducingresults.

Project Code
DownloadtheprojectcodefromthelinksgivenatthebottomofthePost.

#include<LiquidCrystal.h>
intgetKey();
chargetOper();
voidresult(floatresult);
LiquidCrystallcd(13,12,11,10,9,8);
introw[4]={7,6,5,4};
intcol[4]={3,2,1,0};
intkey1;
charoper;
intkey2;
voidsetup()
{
lcd.begin(16,2);
for(inti=0;i<=3;i++)
{
pinMode(row[i],OUTPUT);
pinMode(col[i],INPUT);
}
for(intj=0;j<=3;j++)
digitalWrite(col[j],HIGH);
for(intk=0;k<=3;k++)
digitalWrite(row[k],HIGH);
lcd.print("CALCULATOR!!!!");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
}
voidloop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ENTER1NO=");
key1=getKey();
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ENTER2NO=");
key2=getKey();
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("OPERATOR=");
oper=getOper();
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("RESULT=");
switch(oper)
{
case'+':
result((float)key1+key2);
break;
case'':
result((float)key1key2);
break;
case'/':
result((float)key1/key2);
break;
case'*':
result((float)key1*key2);
break;
case'^':
result((float)pow(key1,key2)+1);
break;
case'%':
result(key1%key2);
break;
}
}
intgetKey()
{
intkey=13;
intReadrow,Readcol;
while(key!=1&&key!=2&&key!=3&&key!=4&&key!=5&&key!=6&&key!=7&&key!=8&&key!=9
&&key!=0)
{
digitalWrite(row[0],LOW);
Readrow=digitalRead(row[0]);
Readcol=digitalRead(col[0]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("1");
digitalWrite(row[0],HIGH);
returnkey=1;
}
digitalWrite(row[0],HIGH);
digitalWrite(row[0],LOW);
Readrow=digitalRead(row[0]);
Readcol=digitalRead(col[1]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("2");
digitalWrite(row[0],HIGH);
returnkey=2;
}
digitalWrite(row[0],HIGH);
digitalWrite(row[0],LOW);
Readrow=digitalRead(row[0]);
Readcol=digitalRead(col[2]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("3");

digitalWrite(row[0],HIGH);
returnkey=3;
}
digitalWrite(row[0],HIGH);
digitalWrite(row[0],LOW);
Readrow=digitalRead(row[0]);
Readcol=digitalRead(col[3]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("4");
digitalWrite(row[0],HIGH);
returnkey=4;
}
digitalWrite(row[0],HIGH);
for(inti=0;i<=3;i++)
{
digitalWrite(row[1],LOW);
Readrow=digitalRead(row[1]);
Readcol=digitalRead(col[i]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print(4+(i+1));
digitalWrite(row[1],HIGH);
returnkey=(4+(i+1));
break;
}
}
digitalWrite(row[1],HIGH);
digitalWrite(row[2],LOW);
Readrow=digitalRead(row[2]);
Readcol=digitalRead(col[0]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("9");
digitalWrite(row[2],HIGH);
returnkey=9;
}
digitalWrite(row[2],HIGH);
digitalWrite(row[2],LOW);
Readrow=digitalRead(row[2]);
Readcol=digitalRead(col[1]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("0");
digitalWrite(row[2],HIGH);
returnkey=0;
}
digitalWrite(row[2],HIGH);
key=13;
}//Whileloopends
return0;
}//GetKeyfunctionends
chargetOper()
{
intReadrow,Readcol;
charkey='l';
while(key!='+'&&key!=''&&key!='/'&&key!='*'&&key!='^'&&key!='%')
{
digitalWrite(row[2],LOW);
Readrow=digitalRead(row[2]);
Readcol=digitalRead(col[2]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("+");
digitalWrite(row[2],HIGH);
returnkey='+';
}
digitalWrite(row[2],HIGH);
digitalWrite(row[2],LOW);
Readrow=digitalRead(row[2]);
Readcol=digitalRead(col[3]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("");
digitalWrite(row[2],HIGH);
returnkey='';
}
digitalWrite(row[2],HIGH);
digitalWrite(row[3],LOW);
Readrow=digitalRead(row[3]);
Readcol=digitalRead(col[0]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("/");
digitalWrite(row[3],HIGH);
returnkey='/';
}
digitalWrite(row[3],HIGH);
digitalWrite(row[3],LOW);
Readrow=digitalRead(row[3]);
Readcol=digitalRead(col[1]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("*");
digitalWrite(row[3],HIGH);
returnkey='*';
}
digitalWrite(row[3],HIGH);
digitalWrite(row[3],LOW);
Readrow=digitalRead(row[3]);
Readcol=digitalRead(col[2]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("^");

digitalWrite(row[3],HIGH);
returnkey='^';
}
digitalWrite(row[3],HIGH);
digitalWrite(row[3],LOW);
Readrow=digitalRead(row[3]);
Readcol=digitalRead(col[3]);
if((Readrow==LOW)&&(Readcol==LOW))
{
lcd.print("%");
digitalWrite(row[3],HIGH);
returnkey='%';
}
digitalWrite(row[3],HIGH);
key='c';
}//whileloopends
return'\0';
}//getOperfunctionends
voidresult(floatresult)
{
intunitvalue,tenvalue,decimal;
floatvalue=result;
if(result<0.0)
{
lcd.print("");
value=result*(1);
}
if(value>10.0)
{
tenvalue=(int)value/10;
lcd.print(tenvalue);
}
unitvalue=(int)value%10;
lcd.print(unitvalue);
lcd.print(".");
decimal=(int)((int)(value*10)%10);
lcd.print(decimal);
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
}

Download the Project Files that contain code and .ino file of th
you have any questions regarding code or circuit diagram, P
theminthecommentssectionbelow.Giveusyourfeedbackon

CalculatorusingArduinoUno(/uploads/2/2/1/5/22159166/

WatchtheProjectVideoHere.....

0:00 / 4:39

MicrocontrollerProjectswithMohsinAli
and6othersatBahriaUniversity,
Islamabad.

LikePage

PersonalWebsite2,405LikesOctober27,2014
Islamabad

CalculatorusingArduinouno,16x2lcdand4x4keypad..Post
includescircuitdiagramandcodeoftheproject.
SeeTranslation
6Likes
Like

Comment

Share

8Comments
Recommend

Microcontroller

Share

Jointhediscussion
Avatarpradip amonthago
nice

Reply Share

AvatarMAliRajput 10monthsago
nice

Reply Share

UsmanAliButt>MAliRajput 10monthsago
Avatar
Thanks...

Reply Share

MAliRajput>UsmanAliButt 10monthsago
Avatar
yayacalculatorkiprogrammingaudrinomainsaveniiihoooriiii
help????me

Reply Share

UsmanAliButt>MAliRajput 10monthsago
Avatar
Sketchuploadnihoraha?????
Compilesihorahaha....?????

Reply Share

MAliRajput>UsmanAliButt 10monthsago
Avatar
ARDUINounokiprogramingsendkrdn
jasy4x4calculator

Reply Share

MAliRajput>UsmanAliButt 10monthsago
Avatar
basicallyamarduinodealerinpakistanilikearduinoprojectimadedistancemeasuredevicelightandmotorc
somethingsisnoworking

Reply Share

UsmanAliButt>MAliRajput 10monthsago
Avatar
Codepostpyha.....Downloadlinkbha..Downloadkrlainyahansy...
1

Reply Share

ALSOONMICROCONTROLLER

DCmotorspeedcontrolwithpic16f877

Countingonsevensegmentdisplaywith8051

5commentsayearago

4comments2yearsago

PicKit2madeathome

GraphicalLcdwithPicMicrocontroller

3commentsayearago

2comments10monthsago

Subscribe

AddDisqustoyoursite

Privacy

89c51MicrocontrollerProjects(projects.html)89c52Microcontro

Arduino(Uno,Mega)Projects(projects.html)KnowledgeBased

AboutMe(aboutme.html)ContactMe(contactme.htm

Copyright2012AllRightsReservedwww.microcontrollerproject.com