LCD doesn't refresh and keeps on scrolling

My lcd doesn’t really work. Here’s the code:

#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;

void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration0.034/2;
distanceInch = duration
0.0133/2;
lcd.setCursor(0,0);
lcd.print(distanceCm);
lcd.print(" cm");
Serial.print(distanceCm);
Serial.print(“cm”);
Serial.print("\n");
delay(10);
lcd.setCursor(0,1);
lcd.print(distanceInch);
lcd.print(" in");
Serial.print(distanceInch);
Serial.print(“in”);
Serial.print("\n");
delay(10);
}

It’s supposed to refresh every few seconds, but it keeps entering data and scrolling to the right. How to counter this?

Thanks!

What Arduino board are you using? Which display?

Pin 1 s the serial TX pin on many boards.

Read the forum guidelines to see how to properly post code and some advice on how to get the most from the forum.

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

pins 1 & 2 are serial pins not good to use that combo

The website I used said that it would be OK for using pins 1&2. Tx didn't really mess with my thing that much.
What else could be the problem?

The website I used said that it would be OK for using pins 1 & 2.

Pin 2 is OK, but pin 1 is not while you are using the serial port. I would not follow any more advice from that site. If you are low on pins, the analog inputs (A0-A5) are also digital pins on Uno and Mega type boards.

What Arduino board are you using? Which display?

It is easier to help those who answer our questions.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What model Arduino controller are you using?

Tom… :slight_smile: