Go Down

Topic: lcd not clearing after each display and more (Read 174 times) previous topic - next topic

StannatS

Apr 24, 2019, 03:50 pm Last Edit: Apr 24, 2019, 03:51 pm by StannatS
Hello there,

Can't find an answer for this anywhere. Whenever I want to clear the lcd screen it won't. It would just display 4 vertical stripes or a weird symbol. But now it won't display anything, only on the monitor get's displayed.

this is my code:

Code: [Select]


#define Vref 4.0
#include <LiquidCrystal.h>
unsigned long int avgValue;ck
int i=0;
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
void setup()
{
    Serial.begin(9600);
    pinMode(A0, INPUT);
    lcd.begin(16,2);
void loop()
{
  
    float sensorValue;
    int m;
    long sensorSum;
    int buf[10];
  for(int i=0;i<10;i++)
  {
    buf[i]=analogRead(A0);
    delay(10);
  }
  for(int i=0;i<9;i++)
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        int temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
      avgValue=0;
      for(int i=2;i<8;i++)
      avgValue+=buf[i];
      sensorValue = avgValue/6;
      
    float pH = 7-1000*(sensorValue-365)*Vref/59.16/1023;
    
    lcd.print("De pH = ");
    lcd.print( pH );
    Serial.print("De pH = ");
    Serial.println( pH );
    delay(1000);
    lcd.clear();
}




It's an arduino Uno with a NDS1602A lcd. The pH-meter is a CROWTAIL PH Sensor v2,0.



david_prentice

Never use pins 0, 1 for the LCD (or anything else).    These pins are used by Serial.

StannatS

thank you so much man, it's a project for school but i've never used arduino before.

one more question, could someone tell me what this means in the code:
Code: [Select]

for(int i=0;i<9;i++)
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        int temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }

marco_c

#3
Apr 24, 2019, 10:25 pm Last Edit: Apr 25, 2019, 02:54 am by marco_c
That code is sorting the array in increasing order. It is a bubblesort algorithm.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Go Up