Hi everyone! Welcome to another knowledgeable blog of My Tech Studio. Today we're going to discuss “how to setup the LCD display using arduino”. Also we're going to learn how to wire up and use an alphanumeric LCD display. In the lesson 22 LCD display we're going to take a look at the 1602a led module now this LCD screen can display two rows of 16 characters. It does have a led backlight and is intended to display text and what we're going to do today is run the arduino example program from the LCD library just so we get an idea of how to wire it up and how to get it going. Let’s get started the items. I’ll be using an LCD 1602 module 1602a. Also I’ll be using a 10k ohm potentiometer.
LCD display using Arduino –
The first thing we should do here is get familiar with our LCD module as you can see the headers are already soldered in which is very nice and each pin on the header has its own function for instance. You can see the VSS corresponds to the pin right here on the end and that is your ground pin the next pin over is the VDD pin and that is your 5 volt power supply. The VO pin is used to adjust the contrast to your LCD monitor and you'll do that with your potentiometer. It is a variable resistor and you can turn it all the way down to zero and all the way up to 10k ohms. The RS pen is a register select pin that controls where in the LCD's memory. You’re writing data to you can select either the data register which holds what goes on the screen or an instruction register which is where the LCD’s controller looks for the instructions on what to do next that's the RS pin the RW pin is the read write pin and that selects reading mode or writing mode.
And then there's an E pin right. Here the E pin is an enabling pin and when you apply low level energy to it causes the LCD module to execute its instructions to carry out its function. Now next you see the D0 through the D7 pin. Those are your data pins. Now the last two pins are the A and K pins and these pins control the led backlight. The A is the anode and the K is the cathode so a is anode you're positive and K is the cathode you're negative now that you're a little more familiar with your LCD 1602 module.
How do I connect 16X2 LCD to Arduino?
Let’s hook it up I want to go ahead and make my connections. But before I do, I just wanted to say that this is the correct orientation for the LCD monitor and to be able to read it you need the 1602a to be on the bottom. But what I’m going to do is turn it upside down I’m going to put it right here on the breadboard so pressing that into your breadboard maybe a little bit hard. But they're all a little bit different. So once you've got your module plugged into your breadboard. I’m going to go ahead and work my way backwards. Here I’m going to start with the uh K pin. The A pin and work my way all the way up to the power supply pin and the ground pin. So I’m first going to start with the K pen which is the cathode pin for the back light and that will go in ground. Then I’ve got A pin, which is the anode pin. We’ll go right here into the positive rail the next pins are my data pins so d7 we'll go into the number 12 pin.
The pulse width modulation section here the d6 pin will go into the PWM pin 11. The D5 pin we'll go into the PWM pin 10. And now I’m on the d4 pin and that will go into the PWM. Now I’m going to skip down to the E pin. My enabling pin and I will connect that to PWM 8. Next is the RW pin and I will connect that to ground. Next is the RS pin and I will connect that to PWM seven. The next thing I’ll do is plug in my potentiometer I’m going to do that over here on the side so it's out of the way and I’m going to have it straddle this little groove right here.
How does a 16x2 LCD work?
So the top pin will go in the above the two bottom pins will go below that groove and just press it in and then your VO pin will connect to the middle pin of your potentiometer. And now the left pin on your potentiometer is going to connect to the positive rail and then the right pin of your potentiometer will connect to the ground rail or negative rail. And once you do that you don't want to forget your uh, your connector to the LCD that can be frustrating. If you don't realize why your potentiometer isn’t working my next connection will be the VDD. And that will connect to the positive rail and then my last pin is the VSS pin and that will connect to the negative rail. And then I’m going to come over. Here and I’m going to connect the 5 volt to the positive rail to give it power now it's time to plug it in and the cable they give you at least in my experience is too short. So I’m using an old Epson printer cable and it works just fine and when I turn the potentiometer. Your screen should look something like that at this point. So after you plug it in and your screen doesn't light up maybe you have connection issues.
LCD Display using Arduino Circuit Diagram -
How to check 16x2 LCD display with Arduino –
Now while you have your board plugged in and connected to your computer let's go over to our Elegoo folder and if you're brand new and you haven't installed and set up your Arduino IDE. You’re going to select your language. For me it’ll be English and you'll go up here to code and go to lesson 22 that's the LCD display. And you'll go to the hello world. You’ll click on this little arduino ide symbol here and it will open up the software for you and forever has a new version. I will do that later I will install the update later and at this point this is what you're going to install on your board all you have to do right now is upload and let's see if it worked. Hello world and it's upside down like I said. You may find it useful I hope you do and right here we can play with the contrast by twisting this I kind of disappear. And then you get blocks in the way there so that right there looks good it actually looks better than it does on screen but uh there it is there you have it. So you should see this hello world and then a timer down here and it just counts up from zero. If you ever want to reset it just press the reset button on your board and it'll reset back to one so at this point let's go back and take a look at the code switch over here.
So down here you'll see uh include liquid crystal H this tells the arduino that we want to use the liquid crystal library. Next we have a line that we had to modify here and this basically defines which pins of the arduino are connected to you know which pins of the display. So in the setup function we have two commands the first command tells us how big our screen is this tells the liquid crystal library. How many columns and rows the display has we have 16 columns and two rows and the second function here tells us what is going to be written on that screen. And that can be changed to anything you want as long as it falls within these parameters so if we come down to the loop function here it has two commands. The set cursor command tells us where the cursor position will be since counting starts at zero the values zero would indicate first column first row the values 0 1 would indicate first column second row and then we come down here and this function right here this command tells us how long it's been in milliseconds since our arduino since our mega 2560 board has been reset. And you can play around with these in fact I’m going to change this to uh be monster laboratory why not all right and then go up here I’ll upload it and there it is b monster laboratory actually laboratory didn't fit. So remember we had 16 columns right so it didn't fit. But anyway that gives you an idea of how to use it get familiar with your module.