• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino Coding for LCD display

Thread starter #1
My project is dealing with 4 FSR sensors with arduino. I would like to display the pressure level of all 4 sensors inputs on a LCD screen all at once. I've written the codes by referring to relevant sources, but I'm uncertain if my coding is functioning as I'm completely new in this, wish to hear some comments on these, thanks.


#include<LiquidCrystal.h>
Liquid Crystal lcd(12, 11, 5, 4, 3, 2);//set pins for LCD

int fsr1 = 0;//fsr1 connected to analog pin 0
int fsr2 = 1;//fsr2 connected to analog pin 1
int fsr3 = 2;//fsr3 connected to analog pin 2
int fsr4 = 3;//fsr4 connected to analog pin 3

//variables for level of force applied to FSRs
int fsr1level = 0;
int fsr2level = 0;
int fsr3level = 0;
int fsr4level = 0;

void setup()
{
lcd.begin(16, 2);//set up LCD no.of columns & rod
}

void loop()
{
//divide by four as analog read is 4x sensitive as digital
fsr1level = analog Read(fsr1) / 4;
fsr2level = analog Read(fsr2) / 4;
fsr3level = analog Read(fsr3) / 4;
fsr4level = analog Read(fsr4) / 4;

//display pressure level on LCD
lcd.setCursor(0, 0);
lcd.print(fsr1level);
lcd.setCursor(15, 0);
lcd.print(fsr2level);
lcd.setCursor(0, 1);
lcd.print(fsr3level);
lcd.setCursor(15, 1);
lcd.print(fsr4level);
}
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#2
The correct syntax for reading the A0 analogue pin is..

int FSR1 = A0;

analogRead(FSR1);

You have a space in between analog and Read... ( Syntax error )

Also It would be preferable to use A0 rather than just 0... ( Readability )
 

MrAl

Well-Known Member
Most Helpful Member
#3
Hi,

Is something not working?

It looks like you are set up for parallel 4 bit operation?

The code setCursor(0,1) refers to the first character, first line
The code setCursor(0,2) refers to the first character, second line
The code setCursor(0,N) refers to the first character, Nth line.

So you are using 4 lines. These are usually referred to as "rows" not "columns".

Does x=analogRead(0) even work? I think it has to be x=analogRead(A0) for example.
 
Last edited:

Latest threads

EE World Online Articles

Loading

 
Top