SOLVED: LCD Trouble

Hey everyone

I’m working on a project that reads data from three switches and a selector and outputs based on the inputs to three relays controlling some valves and an LCD. The program worked correctly until all of the outputs to the relays (pins 6, 7, & 8 ) are set to “HIGH” at the same time using digitalWrite. During this case, the outputs to the relays alternate quickly opening and closing the valves at a fast pace until the switches are changed so that two out of the three outputs are “HIGH.”

My question: is using 10 output pins causing those three pins to alternate incorrectly? The LCD isn’t affected when pins 6, 7, & 8 are high. I am using a Uno from Radioshack. Should I upgrade to a board with more output pins? Or could it be the code? The code loaded to the Arduino is below (feel free to leave feedback if you see anything that can be cleaned up).

Thanks for the help in advance

Beal

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int analogPressurize = A0;
int analogDepressurize = A1;
int analogCycle = A2;
int analogClose = A3;
int analogTestDepressurize = A4;

int pressurizeVal = 0;
int depressurizeVal = 0;
int cycleVal = 0;
int closeVal = 0;
int testDepressurizeVal = 0;

byte pressurize = B0;
byte depressurize = B0;
byte cycle = B0;
byte closeValve = B0;
byte testDepressurize = B0;

int actuatorPin = 8;
int downstreamPin = 7;
int upstreamPin = 6;
int backLight = 13;

int totalCount = 0;
int count = 0;

void setup(){
  lcd.begin(20,4);               
  showCount();
  
  pinMode(actuatorPin,OUTPUT); 
  pinMode(downstreamPin,OUTPUT);  
  pinMode(upstreamPin,OUTPUT); 
  pinMode(backLight,OUTPUT);
  
  digitalWrite(backLight, HIGH);
}

void loop(){
  
  pressurizeVal = analogRead(analogPressurize);
  depressurizeVal = analogRead(analogDepressurize); 
  cycleVal = analogRead(analogCycle); 
  closeVal = analogRead(analogClose); 
  testDepressurizeVal = analogRead(analogTestDepressurize);

  if(pressurizeVal > 900) pressurize = B1;
  else pressurize = B0;
  if(depressurizeVal > 900) depressurize = B1;  
  else depressurize = B0;
  if(cycleVal > 900) cycle = B1;
  else cycle = B0;
  if(closeVal > 900) closeValve = B1;
  else closeValve = B0;
  if(testDepressurizeVal > 900) testDepressurize = B1;
  else testDepressurize = B0;

  if(cycle == 1){
    digitalWrite(actuatorPin, HIGH);
    count = count + 1;
    totalCount = totalCount + 1;
    showCount(); 
    delay(1500);    
    digitalWrite(actuatorPin,LOW);
    delay(2500);
    }
  else count = 0;
     
  if(closeValve == 1) digitalWrite(actuatorPin,HIGH);
  else digitalWrite(actuatorPin,LOW);  
 
  if(pressurize == 1){
    digitalWrite(upstreamPin, HIGH);
    if(testDepressurize == 1){ 
      digitalWrite(downstreamPin, LOW);}
    else{
      digitalWrite(downstreamPin, HIGH);}
    }
  else{
     digitalWrite(upstreamPin, LOW); 
     digitalWrite(downstreamPin, LOW);}
}

void showCount(){
  lcd.clear();
  lcd.setCursor(0,0);           
  lcd.print("Count:");  
  lcd.setCursor(0,1);           
  lcd.print(count);
  lcd.setCursor(0,2);
  lcd.print("Total Count:");
  lcd.setCursor(0,3);
  lcd.print(totalCount);}

I'm guessing it is a power related problem.

How are you relays wired? What kind of transistor are you using to drive them? How are they powered?

What is the power supply you are using?

I'm guessing it is a power related problem. *How are you relays wired? * The relay is the first link, and the wiring is the second. The relay in the second link is not the same one used, but the wiring remains the same. I am using Crydom CS240D5 solid state relays. The output from the Arduino goes directly to the relay control pin (pin 3). Pin 4 is grounded. Pin 1 is connected to the negative terminal of an AC distribution block and pin 2 is connect to the negative pin of the valve.

http://datasheet.seekic.com/datasheet/Crydom_CX240D5.html http://www.futurlec.com/Pictures/SSR5A_Circuit.gif

What kind of transistor are you using to drive them? How are they powered? I am not using any transistors to the relays.

What is the power supply you are using? Power for the Arduino is from a 12V 1A AC adapter. The board is powered by 5V 1A AC adapter

Are you thinking the relays aren't getting enough current and using transistors to amplify the current?

You hardware setup sounds fine. I suspect your software logic may have a flaw, but I'm having trouble following your discription of how you want it to operate.

Yes, I haven’t been commenting while I’ve been coding. :cold_sweat:

But, I digress. In summary, the switches are assigned a 1 or 0 based on the analogRead value every iteration of the loop, and based on the value assigned, a digital output pin will be set to high or low sending that value to the relay control pin. If the cycle switch is flipped, the actuator pin alternates high and low. If the close switch is flipped, the actuator pin is high. There is a selector for pressurize or depressurize. When pressurize is selected, the upstream and downstream pins are high unless the testDepressurize switch is flipped while pressurize is selected. In this case, the upstream pin will be high and downstream will be low. If depressurize is selected, both upstream and downstream pins are low.

Hope this brief summary makes since, but I don’t know if it is the code. When I test the LCD and relays separately, they work with this code. The trouble only comes about when the LCD and relays are connected to the Arduino, and the upstream, downstream, and actuator pins are set to high at the same time (i.e. the close valve and pressurize are selected).

Hope this brief summary makes since, but I don't know if it is the code.

It probably does, I'm just not up to the task of figuring it out today. I'm a hardware guy and it sounds to me that your hardware is functioning OK. That leaves the software. Good luck. ;)

Lefty

I have a schematic in .pdf format on my computer, but I don't know how to post it onto the forum. Can someone please outline the steps to post an image.

Thanks

Under the reply box on the left there is an arrow next to Additional Options. Click that to post your file.

Thanks Mike

Here is the current schematic

construction_milestone_1.pdf (206 KB)

You seem to have a bit of a fetish thing with 100 ohm resistors going on. Try and think what current you want to work with.

Good point, Mike. The relays need at least 15mA, but I don't know how much the LED is taking from the 40 mA the Arduino is supplying. The ME's in my group bought the LEDs, and they don't have a datasheet that I can find. I'll have to measure some currents and voltage in the shop tomorrow and see if I can increase that resistance.

wbeal1: but I don't know how much the LED is taking from the 40 mA the Arduino is supplying.

LEDs take all the current they can, once their forward voltage is dropped across them. So measuring the voltage drop of the LED will help you to calculate the appropriate resistor.

If the LED drops 3V, then your resistor's current is 2V / 100ohm = 20mA.

The arduino is not supplying 40mA, it is supplying as much current as the load is drawing. If this figure is equal to or exceeds 40mA then damage is done to the arduino.

Hey y’all

I’m at the closing stages of this project and almost have everything working to the groups satisfaction. Everyone’s input from the forum definitely helped out a lot in the completion of this work. Pictures (and maybe video) to come.

Nevertheless, I am having trouble implementing the LCD into the system now. I have a hunch that it is the Arduino (FYI: UNO). I load a simple test program onto like the “hello world” one given in the IDE and the LCD will display “hello world” and count like it is supposed to, but after a while the words are erased and random characters show up on the screen. I loaded other example programs only to get the same result. The time that it takes for the LCD to clear and scramble seems to change every time. I am using a 20x4 LCD and am connecting the Arduino to the LCD in the manner shown on this website. http://www.instructables.com/id/Connecting-an-LCD-to-the-Arduino/?ALLSTEPS

The Arduino works correctly for the code to control the switches, but the LCD does not work. I don’t think it is the code because of this, and I upload simple programs to the Arduino and the same problem happens.

The code and schematic attached are almost update with the following exceptions:

  • I will add a counter to display on the LCD how many cycles have gone through
  • Pin 5 on the LCD is grounded (as reflected in the link above)

Has anyone encountered a similar issue, and if so, what steps did yall take to mitigate the problem.

Thanks

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int analogPressurize = A0;
int analogDepressurize = A1;
int analogCycle = A2;
int analogClose = A3;
int analogTestDepressurize = A4;

int pressurizeVal = 0;
int depressurizeVal = 0;
int cycleVal = 0;
int closeVal = 0;
int testDepressurizeVal = 0;

byte pressurize = B0;
byte depressurize = B0;
byte cycle = B0;
byte closeValve = B0;
byte testDepressurize = B0;

int buzzerPin = 13;
int actuatorPin = 8;
int downstreamPin = 7;
int upstreamPin = 6;

void setup(){

  lcd.begin(20,4);   
  lcd.print("Flip 'Cycle' switch");  
  lcd.setCursor(0,1);           
  lcd.print("down when alarm"); 
  lcd.setCursor(0,2);
  lcd.print("sounds");
  
  pinMode(buzzerPin,OUTPUT);
  pinMode(actuatorPin,OUTPUT); 
  pinMode(downstreamPin,OUTPUT);  
  pinMode(upstreamPin,OUTPUT); 

}

void loop(){
  
  pressurizeVal = analogRead(analogPressurize);
  depressurizeVal = analogRead(analogDepressurize); 
  cycleVal = analogRead(analogCycle); 
  closeVal = analogRead(analogClose); 
  testDepressurizeVal = analogRead(analogTestDepressurize);

  if(pressurizeVal > 900) pressurize = B1;
  else pressurize = B0;
  if(depressurizeVal > 900) depressurize = B1;  
  else depressurize = B0;
  if(cycleVal > 900) cycle = B1;
  else cycle = B0;
  if(closeVal > 900) closeValve = B1;
  else closeValve = B0;
  if(testDepressurizeVal > 900) testDepressurize = B1;
  else testDepressurize = B0;

  if(cycle == 1){
    for(int i = 0; i < 100; i++){                        // adjust the number in the i < ??? arguement to change the number of cycles when the switch is flipped
      digitalWrite(actuatorPin, HIGH);
      delay(5000);                                      // adjust the number in the parentheses to change the close time of the valve (in milliseconds)
      digitalWrite(actuatorPin,LOW);
      delay(10000);}                                     // adjust the number in the parentheses to change the open time of the valve (in milliseconds)
    alarm();  
    }
     
  if(closeValve == 1) digitalWrite(actuatorPin,HIGH);
  else digitalWrite(actuatorPin,LOW);  
 
  if(pressurize == 1){
    digitalWrite(upstreamPin, HIGH);
    if(testDepressurize == 1){ 
      digitalWrite(downstreamPin, LOW);}
    else{
      digitalWrite(downstreamPin, HIGH);}
    }
  else{
     digitalWrite(upstreamPin, LOW); 
     digitalWrite(downstreamPin, LOW);}
}

void alarm(){
  for(int j = 0; j < 30; j++){
    digitalWrite(buzzerPin,HIGH);
    delay(250);
    digitalWrite(buzzerPin,LOW);
    delay(250);}}

Have you tried some decoupling capacitors around the circuit and espically on the LCDs power input pins?

Mike

Thanks for the response. Do you think .1uF would be sufficient? Also, do you have any suggestions for where else I might add one?

Apply a 0.1uF ceramic capacitor across the power and ground of each chip you have in the circuit.

Don't want to butt in too much, but wbeal1:

Probably a better powe supply as mentioned, and the caps.

But just a small thing about your schematic.

I understand what you are doing - or I think I do - but how you have drawn the "relays" and motor are confusing.

The motor is 120 vac. Well the circuit is 5 vdc and you haven't shown from where the 120vac is coming and how the motor is really connected.

There is no + and - with AC, so the + and - signs on the motor are confusing.

On "relays" you have 4 wires - which you show - but 2 go to the "coil" and 2 are the contacts, switching the high voltage.

So, what I see your circuit doing is: There are two valves, Upstream and Downstream. There is a control for the motor to pressurise the pipe. There are two ways to depressureise the pipe. A toggle from the pressurise switch and a "test" one. There is also an emergency stop button - good idea.

Problems seen: The pressurise swtich can be active but at the same time the "depressurise for testing" switch can be active. Is this supposed to happen? And the motor, relay part mentioned above.

Suggestion - and it is only that. As neat as you have been with keeping the pins in sequential order on both the Arduino and LCD, it would make it a whole lot neater/easier if you bunched the "wires" together rather than honoured the pins.

So: D10,11,12 would go from the Arduino straight out, turn left and go straight to the LCD, BEFORE pins 1,2,3 on the display's chip. Well that's optional. D5,4,3,2 from the Arduino would also be tidied up and go from the Arduino to the LCD. On the horizontal part where they continue on to the relay, drop the line to the inverters/LED's. When you get to the relays, space them out a bit more and then put the valves beside the respective relay, and not "up there in another part of the circuit". Then there is the problem with the AC voltage. I am sure there is a problem with how you have drawn that part.

I am only suggesting this because it will help with clarity of people's understanding of the circuit should they need to look at it.

All

I added the 0.1 uF capacitors to the as per Mike's suggestion to the LCD and OR and NOT gates and now the system runs perfectly.

Thanks for the input from everyone!