1. 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.
    Dismiss Notice

Arduino Coding for LCD display

Discussion in 'Arduino' started by Amy KL, Oct 20, 2015.

  1. Amy KL

    Amy KL New Member

    Joined:
    Oct 13, 2015
    Messages:
    2
    Likes:
    0
    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);
    }
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    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 )
     
  3. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    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: Oct 21, 2015

Share This Page