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
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");
}
}