LCD display showing random characters [wrong wiring]

I am working on a school project right now where I have to design a PPG to monitor someone's heart rate. The LCD I am using is a 16 by 02 standard LCD display without a shield and directly wired to the Arduino board. When I start the program it initializes correctly and displays the welcome message, but once it goes into the void loop part of the code it starts to display random characters, but they follow a pattern and when observing the output through the serial monitor, the Arduino does read the input signal and processes it. The LCD display only shows random characters but updates itself at the set delay rate, so any help trouble shooting the code is greatly appreciated. I am trying to troubleshoot it one step at a time so please bear with me.

The code I need to troubleshoot for now is as follows

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// initialize the library with the numbers of the interface pins
// If using software SPI (the default case):
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin = 13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
int nFrames = 36;
int backlight
= 13;
int peakValue = 0;
int threshold = 160;
int beatcounter = 0;
unsigned long endTime = 0;
unsigned long previousTime = 0;
unsigned long startTime = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("WELCOME");
lcd.display();
delay (2000);
lcd.clear();
lcd.display();
Genotronex.begin(9600);
Genotronex.print("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin, OUTPUT);
}
void loop() {
delay(200);
// read the sensor:
int sensorState = analogRead(A0);
lcd.print(sensorState);
}

You have duplicated some pins i.e. digital#11 is used as EN and TX.

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
SoftwareSerial Genotronex(10, 11); // RX, TX

Choose different pins and it will probably solve it.

David.

Thanks, David. I'll go change the code and see if it changes anything.

I've made some headway into the project. The display showed the next part of the code, so I moved on with it and tried troubleshooting the rest of it. The code is as follows:

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// initialize the library with the numbers of the interface pins
// If using software SPI (the default case):
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
SoftwareSerial Genotronex(8, 9); // RX, TX
int ledpin = 13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
int nFrames = 36;
int backlight
= 13;
int peakValue = 0;
int threshold = 160;
int beatcounter = 0;
unsigned long endTime = 0;
unsigned long previousTime = 0;
unsigned long startTime = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("WELCOME");
lcd.display();
delay (2000);
lcd.clear();
lcd.display();
Genotronex.begin(9600);
Genotronex.print("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin, OUTPUT);
}
void loop() {
delay(200);
// read the sensor:
int sensorState = analogRead(A0);
if (endTime == 0) {
if (sensorState >= 1.5 * threshold) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Please");
lcd.setCursor(0, 1);
lcd.print("wait");
lcd.display();
startTime = (millis() / 1000);
endTime = (millis() / 1000) + 70;
delay(100);// prepare for next data ...
}
}
else {
if ((millis() / 1000) < endTime) {
if ((millis() / 1000) > (endTime - 60) && sensorState > peakValue && sensorState > threshold)
{
peakValue = sensorState;
}
else {
peakValue = 1.5 * threshold;
}
if ((millis() / 1000) > (endTime

60)) {
if (sensorState >= 0.85 * peakValue && (millis() / 1000) < endTime && millis()

previousTime

  1. {
    beatcounter = beatcounter + 1;
    previousTime = millis();
    }
    if ((millis() / 1000)

startTime > 10) {
if (endTime

(millis() / 1000) >= 10) {
lcd.clear();
lcd.display();

lcd.setCursor(50, 16);
lcd.print(endTime

(millis() / 1000));
lcd.display();
}
else {
lcd.clear();
lcd.display();
lcd.setCursor(16, 2);
lcd.print(endTime

(millis() / 1000));
lcd.display();
}
}
}
}
else {
lcd.clear();
lcd.display();
for (int z = 0; z < 1000; z++) {
lcd.setCursor(0, 0);
lcd.print("BPM:");
lcd.setCursor(0, 5);
lcd.print(beatcounter);
lcd.display();
if (beatcounter >= 60 && beatcounter <= 110) {
lcd.setCursor(0, 1);
lcd.print("Normal");
lcd.display();
}
else if (beatcounter < 60) {
lcd.setCursor(0, 1);
lcd.print("Abnormally Slow");
lcd.display();
}
else if (beatcounter > 110) {
lcd.setCursor(0, 1);
lcd.print("Keep up the pace");
lcd.display();
}
else if (beatcounter > 190) {
lcd.setCursor(0, 1);
lcd.print("Call an ambulance");
lcd.display();
}
}
lcd.clear();
lcd.display();
endTime = 0;
beatcounter = 0;
peakValue = 0;
previousTime = 0;
startTime = 0;
}
}
if (Genotronex.available()) {
BluetoothData = Genotronex.read();
if (BluetoothData == '1') { // if number 1 pressed ....
digitalWrite(ledpin, 1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData == '0') { // if number 0 pressed ....
digitalWrite(ledpin, 0);
Genotronex.println("LED On D13 Off ! ");
}
}
}

The LCD display works until it displays 'Please wait' but when I input a signal, the screen goes blank. When I remove the signal, the display goes back to 'Please wait' like it's supposed to. I believe that there may be a problem with the calculation code but I'm not sure where to debug from there. Any assistance will be greatly appreciated.