LCD displaying black boxes

Trying to make a distance sensor and the distance is supposed to display on the LCD, however every time I run it it only displays black boxes.

Here is my code:

/*

Arduino Project 

*/
#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);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);
}

Here are pictures:

image
image
image

I was informed via PM, and I quote:
"Unfortunately, your reply is anything but helpful.
:roll_eyes:
Sorry, but it is only making it more difficult for the OP."

So I deleted it

1 Like

You should avoid using pin 0 or 1 for your LCD as they are used to upload the code to the Arduino.

Don

1 Like

Try what Don said... by using pins 11 and 12 and changing your LiquidCrystal line to this:

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

Just tried this and updated the code to match- still seeing those black boxes though. Earlier when I tried this it seemed to fix the issue and now it has returned to the showing the black boxes


The black boxes mean that the LCD is correctly powered, but is not receiving commands from the Arduino.

Sticking bare wires into the Arduino female header connector is unlikely to work or be reliable. You need jumpers similar to these: Pololu - Premium Jumper Wires

You have 5v (red wire) going to V0 of the LCD. V0 is is contrast. Contrast is usually sent through a variable resistor to vary the contrast. Pull the wire out of V0 (of the LCD)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.