LCD text keeps on repeating

Hi, beginner here!

I was wondering if you could help me out. The components I have are RTC module (DS3231), SD card reader module, and an 8-channel relay.

When the code WITH ONLY THE LCD **AND RTC as components is uploaded, the display works just as fine.

However, when the other components are added to the code, the display is messed up and even shows other characters.

I'm only a beginner at Arduino so I'm not really familiar with how things work.

So the display works properly... The date and time are shown correctly without any other characters.

#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

#include <DS3231.h>
DS3231  rtc(SDA, SCL);
Time t;

void setup() {
  rtc.begin();
  lcd.begin(16, 4);


}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("HELLO WORLD");
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDateStr());
  lcd.print("  ");
  lcd.print(rtc.getTimeStr());
  delay(5000);
  lcd.clear();
  
}

This one however... The text keeps on repeating and other characters are showing up too.

//rtc
#include <DS3231.h>
DS3231  rtc(SDA, SCL);
Time t;

//relay_LIGHTS1
int relay_LIGHTS1 = 28;
int relay_LIGHTS2 = 29;

//data_logger
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 53;

//LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
  //lcd
  lcd.begin(16, 4);

  //rtc
  rtc.begin();

  //relay_LIGHTS1
  pinMode(relay_LIGHTS1, OUTPUT);
  pinMode(relay_LIGHTS2, OUTPUT);
  Serial.begin(115200);



  //data_logger
  pinMode(pinCS, OUTPUT);
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
}
void loop()
{
  // relay_LIGHTS
  int HOUR = t.hour;
  if (HOUR >= 6 && HOUR <= 18)
  {
    digitalWrite(relay_LIGHTS1, HIGH);
    digitalWrite(relay_LIGHTS2, HIGH);

  }
  else
  {
    digitalWrite(relay_LIGHTS1, LOW);
    digitalWrite(relay_LIGHTS2, LOW);
  }
  //


  myFile = SD.open("test.txt", FILE_WRITE);
  {
    if (myFile)
    {
      myFile.print(rtc.getDOWStr());
      myFile.print(",");
      myFile.print(rtc.getDateStr());
      myFile.print(",");
      myFile.print(rtc.getTimeStr());
      myFile.close(); // close the file
    }
    else
    {
      Serial.println("error opening test.txt");
      delay(1000);
    }
  }
    
      //rtc
      Serial.print(rtc.getDOWStr());
      Serial.print(" ");
      // Send date
      Serial.print(rtc.getDateStr());
      Serial.print(" -- ");
      // Send time
      Serial.println(rtc.getTimeStr());
      delay(1000);
  
    //lcd
  lcd.setCursor(0, 0);
  lcd.print("HELLO Z");
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDateStr());
  lcd.print("  ");
  lcd.print(rtc.getTimeStr());
  delay(5000);
  lcd.clear();
  delay(5000);
   lcd.setCursor(0, 0);
  lcd.print("HELLO J");
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDateStr());
  lcd.print("  ");
  lcd.print(rtc.getTimeStr());
  delay(5000);
  lcd.clear();
  delay(5000);
}

Thank you very much and hoping from some answers!

ksan0626:
Hi, beginner here!

I was wondering if you could help me out. The components I have are RTC module (DS3231), SD card reader module, and an 8-channel relay.

When the code WITH ONLY THE LCD as component is uploaded, the display works just as fine.

However, when the other components are added to the code, the display is messed up and even shows other characters.

I'm only a beginner at Arduino so I'm not really familiar with how things work.

Attached are the codes and the connections.

Thank you very much and hoping from some answers!

Which 'other component' is the culprit? My money is on the 8-channel relay.

Don

52458981_2343055435927069_4352032043970854912_n.jpg

52856707_324553354846365_624110176047202304_n.jpg
So,

Paul__B:
So,

Sorry, my bad! I've already edited my original post. Thanks for the heads up.

ksan0626:
So the display works properly... The date and time are shown correctly without any other characters.

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

#include <DS3231.h>
DS3231  rtc(SDA, SCL);
Time t;

void setup() {
 rtc.begin();
 lcd.begin(16, 4);

}

void loop() {
 lcd.setCursor(0, 0);
 lcd.print("HELLO WORLD");
 lcd.setCursor(0, 1);
 lcd.print(rtc.getDateStr());
 lcd.print("  ");
 lcd.print(rtc.getTimeStr());
 delay(5000);
 lcd.clear();
 
}




This one however... The text keeps on repeating and other characters are showing up too.


//rtc
#include <DS3231.h>
DS3231  rtc(SDA, SCL);
Time t;

//relay_LIGHTS1
int relay_LIGHTS1 = 28;
int relay_LIGHTS2 = 29;

//data_logger
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 53;

//LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup()
{
 //lcd
 lcd.begin(16, 4);

//rtc
 rtc.begin();

//relay_LIGHTS1
 pinMode(relay_LIGHTS1, OUTPUT);
 pinMode(relay_LIGHTS2, OUTPUT);
 Serial.begin(115200);

//data_logger
 pinMode(pinCS, OUTPUT);
 if (SD.begin())
 {
   Serial.println("SD card is ready to use.");
 } else
 {
   Serial.println("SD card initialization failed");
   return;
 }
}
void loop()
{
 // relay_LIGHTS
 int HOUR = t.hour;
 if (HOUR >= 6 && HOUR <= 18)
 {
   digitalWrite(relay_LIGHTS1, HIGH);
   digitalWrite(relay_LIGHTS2, HIGH);

}
 else
 {
   digitalWrite(relay_LIGHTS1, LOW);
   digitalWrite(relay_LIGHTS2, LOW);
 }
 //

myFile = SD.open("test.txt", FILE_WRITE);
 {
   if (myFile)
   {
     myFile.print(rtc.getDOWStr());
     myFile.print(",");
     myFile.print(rtc.getDateStr());
     myFile.print(",");
     myFile.print(rtc.getTimeStr());
     myFile.close(); // close the file
   }
   else
   {
     Serial.println("error opening test.txt");
     delay(1000);
   }
 }
   
     //rtc
     Serial.print(rtc.getDOWStr());
     Serial.print(" ");
     // Send date
     Serial.print(rtc.getDateStr());
     Serial.print(" -- ");
     // Send time
     Serial.println(rtc.getTimeStr());
     delay(1000);
 
   //lcd
 lcd.setCursor(0, 0);
 lcd.print("HELLO Z");
 lcd.setCursor(0, 1);
 lcd.print(rtc.getDateStr());
 lcd.print("  ");
 lcd.print(rtc.getTimeStr());
 delay(5000);
 lcd.clear();
 delay(5000);
  lcd.setCursor(0, 0);
 lcd.print("HELLO J");
 lcd.setCursor(0, 1);
 lcd.print(rtc.getDateStr());
 lcd.print("  ");
 lcd.print(rtc.getTimeStr());
 delay(5000);
 lcd.clear();
 delay(5000);
}

floresta:
Which 'other component' is the culprit? My money is on the 8-channel relay.

Don

Can you explain to me how it affected the display? And what could I do to fix it?

P.S.
I've also edited my original post and added code tags.

Do you reuse pins? You probably don't need to do that. (since you're using Arduino Mega).

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

Pin 1 is the hardware serial (USB) TX pin.