Two shields use the same output pins on UNO?

I am using an Arduino UNO with two shields stacked;
Ceeed Relay shield V3.0 and
2x16 LCD keyboard display

Display shield works great and relay shield works great individually mounted on the UNO. The two together have conflicts because both shields use pins 4, 5, 6, 7 from the UNO.

How do I separate the two in my code to prevent this?

My code:

int MotorControl = 5;    // Digital Arduino Pin used to control the motor
#include <LiquidCrystal.h>
 // 60 second count down timer that closes the relay at start and opens at end
 
int hours = 0; // start hours
int minutes = 10; //start min
int seconds = 10; //start seconds
 
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

 
void setup() {

 // declare pin 5 to be an output:
  pinMode(MotorControl, OUTPUT);
    digitalWrite(MotorControl,HIGH); // NO3 and COM3 Connected (the machine is running)
}
 
void loop() {
 lcd.begin(16, 2);
 lcd.print("Washing Machine ");
 
 delay(2000); // wait before we start the cycle
 
 while (hours > 0 || minutes > 0 || seconds >= 0) {

 lcd.setCursor(4, 2);
 
 (hours < 10) ? lcd.print("0") : NULL;
 lcd.print(hours);
 lcd.print(":");
 (minutes < 10) ? lcd.print("0") : NULL;
 lcd.print(minutes);
 lcd.print(":");
 (seconds < 10) ? lcd.print("0") : NULL;
 lcd.print(seconds);
 lcd.display();
 stepDown();
 delay(1000);
     }
}

void stepDown() {
 if (seconds > 0) {
 seconds -= 1;
 } else {
 if (minutes > 0) {
 seconds = 59;
 minutes -= 1;
 } else {
 if (hours > 0) {
 seconds = 59;
 minutes = 59;
 hours -= 1;
 } else {

 trigger();
 }
 }
 }
}
 
void trigger() {
 lcd.clear(); // clears the screen and buffer
 lcd.setCursor(0, 1); // set timer position on lcd for end.
 
   digitalWrite(MotorControl,LOW); // NO3 and COM3 Disconnected (the machine is not running)
    
 lcd.println("PROGRAM FINISHED");
 }

fatman1961:
How do I separate the two in my code to prevent this?

You can’t, sorry…

It’s a problem in hardware, you can’t magically fix it in software. You have to hack on of the two boards and route the double used pins to new pins (and disconnect them from the double used pins).

Ok, thanks for confirming, sort of expected this.

Next question then, I suppose I'm stuck with pins 4 5 6 and 7 on the relay shield, so I need to use other pins from the UNO? Can I use pins 2, 3, 10 and 11 as the LCD shield seems to be using 8, 9, 4, 5, 6, 7. Apologies if that's a stupid question, but I have just started with Arduino.

You can.. Use jumper-cables for the second shield.
A0.. A5 works as digital pins as well

Oh perfect! The analog pins wont be used by the LCD shield, will they? Do I need to do anything to use them as digital pins?

fatman1961:
Oh perfect! The analog pins wont be used by the LCD shield, will they? Do I need to do anything to use them as digital pins?

A0 is used for the button input on the LCD shield that I have.

Has yours got buttons on it ?

To use them as digital pins just use pinMode() as usual

Hi UKHeliBob. Thanks for the advice. Yep, mines got buttons. What will be the difference in how I address pin1 analog as opposed to addressing pin1 digital?

Just use A0, A1, etc. as pin numbers.

Perfect, thank's