I have one of the standard LCD shields. It is mounted on a UNO clone.
The following code outputs the correct value to the Terminal but I get a random and fixed number coming on the LCD. It is puzzling. Has anybody any idea why?
#include <LiquidCrystal.h>
/*******************************************************
This program outputs to lcd and to serial the A1 value
********************************************************/
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
lcd.begin(16, 2); // start the library
//lcd.setCursor(0,0);
//lcd.print("this is the first"); // print a simple message
//lcd.setCursor(0,1);
//lcd.print("this is the second"); // print a simple message
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin A1:
int sensorValue = analogRead(1);
Serial.println(sensorValue);
lcd.setCursor(0,0);
lcd.print(sensorValue);
delay(250); // delay in between reads for stability
}