Issue with LCD connectted to UNO along with other sensors

I have a UNO connected with a SainSmart LCD 1602 Keypaid Shield and have issues controlling my sensors and relays.

I soldered headers to the LCD board as it had available to do so, but since the LCD is using
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

I cant control some of my sensors. I was debating on going to pick up a Mega to get more pins, but even right now with just simple sensors I cant control them, not sure what has happened that I cant trigger my relays and I need them to trigger in order to read the other data from the other sensors.

Here is a stripped down version of just 1 relay and 1 reflective sensor for RPM calculations.

I’m sure I’m overlooking something, but not sure…

Any help would be greatly appreciated.

#include <LiquidCrystal.h>
#include <DFR_Key.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

DFR_Key keypad;

int localKey = 0;
String keyString = "";

int RELAY1 = A1;

// RPM SENSOR
#include <TimerOne.h>
unsigned int counter=0;
String stat = "";
String tmp = "";

int b1a = 3;  // L9110 B-1A 
int b1b = 2;  // L9110 B-1B

void docount()  // counts from the speed sensor
{
 counter++;  // increase +1 the counter value
} 

void timerIsr()
{
 int rotation = (counter / 1)* 60;  // divide by number of holes in Disc
 Timer1.detachInterrupt();  //stop the timer
 lcd.clear();
 lcd.setCursor(8, 1);
 lcd.print("RPM: "); 
 lcd.setCursor(12, 1);
 lcd.print(rotation,DEC);
 counter=0;  //  reset counter to zero
 Timer1.attachInterrupt( timerIsr );  //enable the timer

 lcd.setCursor(0,0);
 lcd.print("Status:");
 lcd.setCursor(7,0);
 lcd.print(stat);

 lcd.setCursor(0,1);
 lcd.print("Temp:");
 lcd.setCursor(5,1);
 lcd.print(tmp);
}
// END

void setup() {
 // put your setup code here, to run once: 
 //Serial.begin(9600);

 lcd.begin(16, 2);
 lcd.clear();
 //Sets the sample rate at once every x milliseconds.
 //Default: 10ms
 keypad.setRate(10);

   // RPM
 pinMode(b1a, OUTPUT); 
 pinMode(b1b, OUTPUT); 

 Timer1.initialize(1000000); // set timer for 1sec
 attachInterrupt(0, docount, RISING);  // increase counter when speed sensor pin goes High
 Timer1.attachInterrupt( timerIsr ); // enable the timer
   // END 

 // CURRENT
 pinMode(RELAY1, OUTPUT);
 digitalWrite(RELAY1,LOW);
 // END    
}

void loop() 
{  
 digitalWrite(RELAY1,HIGH);         // Turns ON Relays 1
 delay(10000);
 digitalWrite(RELAY1,LOW);          // Turns Relay Off
 delay(20000);
 
 int potvalue = analogRead(1);  // Potentiometer connected to Pin A1
 int motorspeed = map(potvalue, 0, 680, 255, 0);
 analogWrite(b1a, motorspeed);  // set speed of motor (0-255)
 digitalWrite(b1b, 1);  // set rotation of motor to Clockwise
}

So if I remove the LCD shield from the UNO and just let the code run, it seems to work as expected. So I know that the LCD has to be at fault for some, but I need the display so that they aren't having to connect to USB to view data.

OK, corrected the code - that's better.

Mind you, you said "issues controlling my sensors and relays". That alerts me for a start. Relays are a worry. :grinning:

I have read the instructions, only thing I did wrong was posting the code incorrectly, I have researched via google and also read the sticky in this section "Warning to users of some vendors LCD keypad shields. " and that lead me here to post my question.

I have found plenty of videos on youtube on using a lcd with multiple sensors, but they aren't the LCD I have.

The logic works if I physically remove the LCD from the UNO. Relays and sensors..

What else did I miss?

Running the above code with the LCD connected doesn't work and nothing triggers, running without the LCD connected the code triggers and works as expected.

I . . . have issues controlling my sensors and relays.

. . . with just simple sensors I cant control them . . .

I cant trigger my relays

So if I . . . it seems to work as expected.

Do you think you could explain some of these phenomena?

Something along the lines of what should be happening vs what actually is happening

Don

Do you have the +5 and gnd connections correct on the LCD? Things like that do very strange things to other signals if they are missing the power connection (then trying to get power from the data pins).

floresta:
Do you think you could explain some of these phenomena?

Something along the lines of what should be happening vs what actually is happening

Don

The relays would not trigger(go high or low) when I had my LCD connected, if I merely removed the LCD from the uno, the logic works fine, so I know my logic/code is correct as shown above, but having the LCD mounted to the uno causes no relays to be triggered, the logic that turns the relays on and off never gets executed, I had print statements within each area of logic so I can watch it on the serial monitor and with the LCD nothing ever got shown.

There seems to be some kind of conflict in pin usage between your LCD and your sensors and/or relays.

The LiquidCrystal library is set up so that, in the absence of an LCD shield, you can assign any Arduino pins to any LCD pin. Normally you would determine which Arduino pins are being used by other devices and assign the LCD to ones that are free.

In your case you are using a shield that is hardwired so that Arduino pins 4, 5, 6, 7, 8 ,and 9 are being used by the LCD and analog pin A0 is being used by the Keypad. I'm not sure why pin 13 shows up in your LiquidCrystal lcd(...) statement.

It looks like your sensors and/or relays are using one or more of these pins so you can to look into the possibility of reassigning those connections.

If you can't change the sensor or relay connections then you will have to change the LCD connections. You can't easily do that with the Sainsmart shield but you could look into using a different way to connect a display such as a using standalone LCD connected directly or via an I2C interface.

Don

I see a couple of pin conflicts but I'm not sure how they relate to the lcd.

int RELAY1 = A1;
int potvalue = analogRead(1);
int b1b = 2;
 digitalWrite(b1b, 1);
attachInterrupt(0, docount, RISING);

How are all the motors, sensors, and relays powered. With the lcd shield attached, you may not have enough power to operate the relay.

I'm picking this project back up and wanted to ask, if i move my code over to a Mega board, would that help?

By that i mean i would clearly have a lot more pins to work with given the sensors and LCD i want to use.. my biggest issue when i was working on this was not being able to have the LCD in place and run the logic correctly.

Id like to finish this project and get it out of my office.. (takes up alot of space)

Just want to see if having more available pins would help segregate all the sensors so that there is no conflict with anything.

I have a similar problem with using just a 16X2 lcd and an mpu 9250 using the i2c buss. With the lcd connected the program stops. As soon as I remove scl and sda from the LCD it continues. I feel it either has to be the load and I need to put pull up resistors somewhere or the 0x3f address of the lcd is conflicting with the 9250. My advice would be to see if the address of your LCD conflicts with the sensor(s) you are using.
Good Luck.

How would i check if the address conflicts?

How would i check if the address conflicts?

You are not using an i2c lcd, so there can not be an address conflict.

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

In reply #7 Don said

In your case you are using a shield that is hardwired so that Arduino pins 4, 5, 6, 7, 8 ,and 9 are being used by the LCD and analog pin A0 is being used by the Keypad. I'm not sure why pin 13 shows up in your LiquidCrystal lcd(...) statement.

The constructor for the common lcd keypad shield should be

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);//pin assignment for lcd button shield

ok, thats good, yea the pins listed in my original post are as provided in an example.. i should have time to work on this tonight or this weekend and will be moving all sensors and such over to a mega i picked up this past weekend and will attempt to run the LCD again with the sensors all connected

I appreciate the call out on the pins and addressing..