LCD showing black squares

Hello, I'm new to Arduino and I'm trying to show my heart beat on an LCD with a KY-039 for a school project and my LCD just shows black squares in the first line and I don't know what to do.
What I'm trying to do here is: if the censor doesn't send any input to the Arduino, the LCD shows "Pulse Unavailable" and if the Arduino receives some input from the censor, it shows the pulse.
Any help is appreciated. Thanks :slight_smile:

I attached an image of the circuit and the LCD with the black squares
Here's the code I put in:

#include <LiquidCrystal.h>

double pulse = 1;
bool lastAvailable;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  
  lcd.begin(16, 2);
  
  lcd.setCursor(0, 0);
  lcd.print("Pulse");
  lcd.setCursor(0, 1);
  lcd.print("Unavailable");
}

void loop() {
  // sensor
  int sensorValue = analogRead(A0);
  pulse = sensorValue * (5.0 / 1023.0);
  
  // lcd
  if (pulse == 0) {
    unavailable();
    lastAvailable = false;
  } else {
    if (lastAvailable == false)
    {
      lcd.clear();
    }
  	lcd.setCursor(0, 0);
    lcd.print("Pulse : " + String(pulse) + "   ");
    lastAvailable = true;
  }
}

void unavailable() {
  if (lastAvailable) {
	lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pulse");
    lcd.setCursor(0, 1);
    lcd.print("Unavailable");
  }
}

In the picture, it looks as if the wire to DB5 (LCD) is not connected to pin 4 (Arduino).

PS.: Can you please use black wires for GND and red wires for +5 volt? Tnx... :wink:

Erik_Baas:
In the picture, it looks as if the wire to DB5 (LCD) is not connected to pin 4 (Arduino).

PS.: Can you please use black wires for GND and red wires for +5 volt? Tnx... :wink:

I tried it and it works! Thank you very much!
Will do, thanks! :slight_smile:

Always critical to get those wire colours right! :grinning: