hcsr04+lcddisplay+sdcard datalogging problem

Hello, i think i wrote everything correctly, but the lcd display popped up some weird screen and my serial monitor doesnt work, what should i do ty,
if you need the files, please send me your gmail account and i will send it over as this forum cant support my files thanks

HC-SR04_with_LCD_sd.ino (2.29 KB)

newbieGABRIEL:
Hello, i think i wrote everything correctly, but the lcd display popped up some weird screen and my serial monitor doesnt work, what should i do ty,
if you need the files, please send me your gmail account and i will send it over as this forum cant support my files thanks

No one’s going to give you their email address.

What files are you talking about anyway? And in future, please post your code instead of attaching it. (Between [code]code tags[/code].)

Anyway, here’s the code:-

/*
    HC-SR04 Ultrasonic Sensor with LCD dispaly

    HC-SR04 Ultrasonic Sensor
    VCC to Arduino 5V
    GND to Arduino GND
    Echo to Arduino pin 12
    Trig to Arduino pin 13

    LCD Display (I used JHD162A)
    VSS to Arduino GND
    VCC to Arduino 5V
    VEE to Arduino GND
    RS to Arduino pin 11
    R/W to Arduino pin 10
    E to Arduino pin 9
    DB4 to Arduino pin 2
    DB5 to Arduino pin 3
    DB6 to Arduino pin 4
    DB7 to Arduino pin 5
    LED+ to Arduino 5V
    LED- to Arduino GND

    Modified by Ahmed Djebali (June 1, 2015).
*/
#include <LiquidCrystal.h> //Load Liquid Crystal Library
LiquidCrystal LCD (1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
#define trigPin 9 //Sensor Echo pin connected to Arduino pin 13
#define echoPin 8//Sensor Trip pin connected to Arduino pin 12
#include <SD.h>
#include <SPI.h>
//Simple program just for testing the HC-SR04 Ultrasonic Sensor with LCD dispaly
//URL:
File myFile;

int pinCS = 10;
void setup()
{
    Serial.begin(9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);

    if (SD.begin())
    {
        Serial.println("SD card is ready to use.");
    }
    else
    {
        Serial.println("SD card initialization failed");
        return;
    }
    LCD.begin(16, 2); //Tell Arduino to start your 16 column 2 row LCD
    LCD.setCursor(0, 0); //Set LCD cursor to upper left corner, column 0, row 0
    LCD.print("Target Distance:");  //Print Message on First Row
    if (SD.begin())
    {
        Serial.println("SD card is ready to use.");
    }
    else
    {
        Serial.println("SD card initialization failed");
        return;
    }
}

void loop()
{
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration / 2) / 29.1;

    LCD.setCursor(0, 1); //Set cursor to first column of second row
    LCD.print("                "); //Print blanks to clear the row
    LCD.setCursor(0, 1);  //Set Cursor again to first column of second row
    LCD.print(distance); //Print measured distance
    LCD.print(" cm");  //Print your units.
    delay(3000); //pause to let things settle

    myFile = SD.open("Distance2.txt", FILE_WRITE);
    if (myFile)
    {
        myFile.println("distance");
        myFile.close();
    }
    else
    {
        Serial.println("error opening distance.txt");
    }
    delay(3000);
}

my serial monitor doesnt work,

Do you have the baud rate set to match your code? ie 9600 baud
At the very least, you should see one or the other of these messages printed to the serial monitor:-
"SD card is ready to use."
"SD card initialization failed"

lcd display popped up some weird screen

Have you tried a stand-alone test program for your LCD? If so, did it work? If you haven't tried getting it working on it's own, then do so and let us know the result.
Edit: After looking further at your code, it couldn't possibly work with your LCD constructor call.

Ideally, you should write test programs for all of the elements you'll use in your main program, then when they're working satisfactorily, write the main code. That's better than putting everything together, then discovering that nothing is working.

Edit: Shouldn't your LCD constructor call be using these pin numbers?:-

RS to Arduino pin 11
R/W to Arduino pin 10
E to Arduino pin 9
DB4 to Arduino pin 2
DB5 to Arduino pin 3
DB6 to Arduino pin 4
DB7 to Arduino pin 5

Otherwise how does the library know which pins you've connected the LCD to?
As I said, get everything working individually, then put it all together.

delay(3000); //pause to let things settleYou don't need this, especially since you already have a blocking 3 second delay at the end of 'loop()'.

LCD (1, 2, 4, 5, 6, 7); = WTF?

Pin1 belongs to Serial, and if you use pin1 for different hardware, this will, of course, make Serial unusable.

Check the pin numbers in the LCD declaration along with your description of pin number usage!