Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Oveview of the Project:
This this Embedded program project. In this project we should interface Arduino with 16*2 LCD in I2C protocol.
Equipment in this project :
- Arduino UNO board.
- Bread board.
- LCD 16x2 I2c.
- Slide switches.
Coding:
In this project used C programming codes. We used 3 switches for 3 different letters to print in the LCD. in this code we used if else statement and Switch case statement.
Program:
#include
#define switch1 8 //here we declared 8th pin as a switch 1 input port
#define switch2 9 //here we declared 9th pin as a switch 2 input port
#define switch3 10 //here we declared 9th pin as a switch 3 input port
int switchStatus1=0;//For switch status
int switchStatus2=0;
int switchStatus3=0;
int buttonNo=0;
Adafruit_LiquidCrystal lcd_1(0);
void setup()
{
pinMode(switch1,INPUT);//Declaring inputs
pinMode(switch2,INPUT);
pinMode(switch3,INPUT);
lcd_1.begin(16, 2);
}
void loop()
{
lcd_1.clear();
buttonNo=0;//Initial Status
switchStatus1=digitalRead(switch1);//Switches digital read
switchStatus2=digitalRead(switch2);
switchStatus3=digitalRead(switch3);
lcd_1.setCursor(0,0);//Cursor setting
if(switchStatus1==HIGH)//here we using if statement to give input to switch case
{
buttonNo=1;
}
else if(switchStatus2==HIGH)
{
buttonNo=2;
}
else if(switchStatus3==HIGH)
{
buttonNo=3;
}
switch(buttonNo)/*here we used switch case to print letters
in LCD as per input*/
{
case 1:
lcd_1.print("VOLTAGE");
break;
case 2:
lcd_1.print("CURRENT");
break;
case 3:
lcd_1.print("RESISTANCE");
break;
default:
lcd_1.print("NO INPUT");
}