arduino, data from serial monitor to lcd

sooo, i want to make my arduino show me data (distance) from serial monitor. that`s all.

#define trigPin 13
#define echoPin 12
#define led 11
#define led2 9
#define led3 10
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 1, 2, 3, 4);

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  lcd.begin(16, 2);
  lcd.print(
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 10) {  // This is where the LED On/Off happens
    digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);
}
  else {
    digitalWrite(led,LOW);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,LOW);
   
  }
  if (distance >= 100 || distance <= 0){
    digitalWrite(led3,HIGH);
    digitalWrite(led2,LOW);
    digitalWrite(led,LOW);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}

as you can see i missiong only the part with lcd.print

iamponczu:
as you can see i missiong only the part with lcd.print

But surely you want that inside loop() not setup()?

And I reckon it just needs to say lcd.print(distance);

ut surely you want that inside loop() not setup()?

im open for criticism

I expect that you know the program you posted does not compile but you do seem to know about the lcd.print() method. What's wrong with using it to print the distance on the LCD ? The one place that you don't need to put it is in setup() though. Why not put it immediately after

 Serial.print(distance);
    Serial.println(" cm");

iamponczu:

ut surely you want that inside loop() not setup()?

im open for criticism

Well in setup() you haven't measured the distance, have you, and even if you had it would only go once. It gets read over and over in loop(), so I'd guess that's when you want to display it. Might add a short delay just after that so the lcd doesn't go too haywire.... try without.

i change to code. i put the lcd.print (distance) in loop (as you said). now i`m thinking hot to make data show in one line and have the cm ending (47 cm, not 47) :slight_smile:

You know how to doSerial.println(" cm");Have wild guess how to lcd.print() the same text....

iamponczu:
i change to code. i put the lcd.print (distance) in loop (as you said). now i`m thinking hot to make data show in one line and have the cm ending (47 cm, not 47) :slight_smile:

  else {
    Serial.print(distance);
    Serial.println(" cm");
    lcd.setCursor(0,1);// <<<positions the cursor on the first line, at the first position
    lcd.print(distance);
    lcd.print(" cm");
  }