LCD -> "unreadable messages" / Absolute Beginner

Hello,

its my first time im using an arduino and my first time programming and using microcontrollers.

Today is my second Day working with it and since yesterday i`m fighting with one Problem:

My LCD only Shows "unreadable Messages" when i try to Display Data i`ve read with an HC-SR04 (Ultrasonic Sensor).

Ive read a lot of Messages, Postuings, watched a lot of YouTube-Videos but couldnt find my Problem.

I switched the "ports" from 12,11,5,4,3,2 to 12,11,4,3,2,1 - with "Hello World" Beginners Tutorial it`s perfectly working on both lines.

Can someone help me? Did i something wrong with Type "long" or my integer "cm" ?

This is my Code:

(PS: I know it can be shorter ...)

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 4, 3, 2, 1);


long messergebnis;
long cm;
int led1 = 7;                             // Umbenennung Anschluss 7 zu led1
int led2 = 6;                             // Umbenennung Anschluss 6 zu led2
int led3 = 5;                             // Umbenennung Anschluss 5 zu led3

void setup() {
lcd.begin(16, 2);
    lcd.print("MESSAGE 1");
  Serial.begin(9600);                     // Geschwindigkeit der Datenübertragung festlegen
}

void loop() {
  pinMode(8, OUTPUT);                       // Festlegung des Triggersignals als Ausgangssignal
  pinMode(9, INPUT);                        // Festlegung des Echoempfangs als Eingangssignal
  pinMode(led1, OUTPUT);                    // Festlegung der LED1 als Ausgangssignal
  pinMode(led2, OUTPUT);                    // Festlegung der LED1 als Ausgangssignal
  pinMode(led3, OUTPUT);                    // Festlegung der LED1 als Ausgangssignal

  digitalWrite(led1, LOW);                  // Ausschalten der LED1
  digitalWrite(led2, LOW);                  // Ausschalten der LED2
  digitalWrite(led3, LOW);                  // Ausschalten der LED3

  digitalWrite(8, LOW);                     // Ausschalten des Triggers
  delayMicroseconds(2);                     // Wartezeit
  digitalWrite(8, HIGH);                    // Einschalten des Triggers
  delayMicroseconds(5);                     // Wartezeit
  digitalWrite(8, LOW);                     // Ausschalten des Triggers

messergebnis = pulseIn(9, HIGH);          // Umbenennung des Pulseingangssignals auf 9 in "messergebnis"

cm = (messergebnis * 34) / 2000;          // Umrechnung des messergebnisses in cm

  Serial.print(cm);                         // Ausgabe des Werts in cm auf dem seriellen Monitor
  Serial.println(" cm");                    // Anhängen von "cm" an den Wert
lcd.setCursor(0,1);
lcd.print(cm);

  if (cm < 100)                             // Wenn cm unter 100, dann led1 einschalten
  {
    digitalWrite(led1, HIGH);
  }

  if (cm < 66)                              // Wenn cm unter 66, dann led1 und led2 einschalten
  {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
  }

  if (cm < 33)                              // Wenn cm unter 33, dann led1, led2 und led3 einschalten
  {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
  }
  
  delay(1000);                              // Wartezeit bis zum Neustart
}

IMG_20151008_132136 [19797].jpg

firstly change the lcd back to the original pins as serial print is using pins 0 and 1.

also you have a led on pin 5. make sure all pins assigned to the lcd are not being used else where

:o it works! :o

switched 1 to 13 ... will correct everything this evening!

many, many, many thanks!

What i do not understand:

When i used "Hello World" - the lcd and the Serial Monitor were used both at same time and it worked - why not in this case?

thefreak:
:o it works! :o

switched 1 to 13 ... will correct everything this evening!

many, many, many thanks!

What i do not understand:

When i used "Hello World" - the lcd and the Serial Monitor were used both at same time and it worked - why not in this case?

a pin can be shared it just can not be used at the same time. So your hello world probably didn't try to print in both places at the same time. Its just a bad practice to share pins (you can use analog pins as digital when you need more)