Displaying the pressure range on a 16x4 LCD for four pressure sensors input (Arduino-based)

Discussion in 'Embedded Systems and Microcontrollers' started by Amy Yu, Oct 20, 2015.

  1. Amy Yu

    Thread Starter New Member

    Oct 14, 2015
    5
    0
    Hi, my project is about displaying the pressure range on a 16x4 LCD for four pressure sensors input. I'm new to this, but I have try writing out codes by referring to other online sources, doesn't know whether the coding works, hope somebody can help up.


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

    int FSR1 = A0;//fsr1 connected to analog pin 0
    int FSR2 = A1;//fsr2 connected to analog pin 1
    int FSR3 = A2;//fsr3 connected to analog pin 2
    int FSR4 = A3;//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, 4);//set up LCD no.of columns & rod
    lcd.setCursor(0, 0);
    lcd.print("1st:");// set up 1st column for FSR1level
    lcd.setCursor(0, 1);
    lcd.print("2nd:");// set up 2nd column for FSR2level
    lcd.setCursor(0, 2);
    lcd.print("3rd:");//set up 3rd column for FSR3level
    lcd.setCursor(0, 3);
    lcd.print("4th:")//set up 4th column for FSR4level
    }

    void loop()
    {
    //divide by four as analog read is 4x sensitive as digital
    FSR1level = analogRead(FSR1) / 4;
    FSR2level = analogRead(FSR2) / 4;
    FSR3level = analogRead(FSR3) / 4;
    FSR4level = analogRead(FSR4) / 4;

    // Threshold preset for FSR1level
    if (FSR1level < 200)
    {
    lcd.setCursor(5, 0);
    lcd.print("Very Weak");
    }
    else if (FSR1level < 500)
    {
    lcd.setCursor(5, 0);
    lcd.print("Weak");
    }
    else if (FSR1level < 800)
    {
    lcd.setCursor(5, 0);
    lcd.print("Moderate");
    }
    else {
    lcd.setCursor(5, 0);
    lcd.print("Strong");
    }
    delay(5000);

    // Threshold set for FSR2level
    if (FSR2level < 200)
    {
    lcd.setCursor(5, 1);
    lcd.print("Very Weak");
    }
    else if (FSR2level < 500)
    {
    lcd.setCursor(5, 1);
    lcd.print("Weak");
    }
    else if (FSR2level < 800)
    {
    lcd.setCursor(5, 1);
    lcd.print("Moderate");
    }
    else {
    lcd.setCursor(5, 1);
    lcd.print("Strong");
    }
    delay(5000);

    // Threshold set for FSR3level
    if (FSR3level < 200)
    {
    lcd.setCursor(5, 3);
    lcd.print("Very Weak");
    }
    else if (FSR3level < 500)
    {
    lcd.setCursor(5, 3);
    lcd.print("Weak");
    }
    else if (FSR3level < 800)
    {
    lcd.setCursor(5, 3);
    lcd.print("Moderate");
    }
    else {
    lcd.setCursor(5, 3);
    lcd.print("Strong");
    }
    delay(5000);

    // Threshold set for FSR4level
    if (FSR4level < 200)
    {
    lcd.setCursor(5, 4);
    lcd.print("Very Weak");
    }
    else if (FSR4level < 500)
    {
    lcd.setCursor(5, 4);
    lcd.print("Weak");
    }
    else if (FSR4level < 800)
    {
    lcd.setCursor(5, 4);
    lcd.print("Moderate");
    }
    else {
    lcd.setCursor(5, 4);
    lcd.print("Strong");
    }
     
  2. DickCappels

    Moderator

    Aug 21, 2008
    2,662
    633
    What is your question or request?
     
Loading...