LCD with arduino shows a weird words!

Hey guys,

I’m using 16*2 LCD with arduino in my school project. It’s just a dc motor driving a 2nd motor which the last represents the generator and produce about 2v which goes to analogRead and There is 4 LEDs too.

An LCD shows the status of the what happens exactly.

Actually, The first printing to the lcd is works perfectly but after that’s not.

/*
 * Programmer: Mahdi Samah
 * Purpose: Automatic Generator Starter AGS
 * Year: 2015
*/

#include <LiquidCrystal.h>

int x=0;
int flag=1;
int motor=2;
int redLed=3;
int blueLed=4;
int greenLed=5;
int yellowLed=6;
int pwrInput=7;
int gnrRead=A5;
LiquidCrystal lcd(8,9,10,11,12,13);

void setup() {
pinMode(motor,OUTPUT);
pinMode(redLed,OUTPUT);
pinMode(blueLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(yellowLed,OUTPUT);
pinMode(pwrInput,INPUT);
pinMode(gnrRead,INPUT);
lcd.begin(16,2);
lcd.print("AGS System is ON");
}

void loop() {
  digitalWrite(redLed,HIGH);                                              //Led indicates the power to the circuit
while(flag){
  if(digitalRead(pwrInput)==HIGH){                                        //There is a main power
    digitalWrite(greenLed,LOW);                                           //Disconnect the load
    lcd.clear();
    lcd.print("Main Power");
    delay(10000);
    if(digitalRead(pwrInput)==LOW && digitalRead(blueLed)==HIGH){         //There is no main power & the generator is turned off (CASE: IF THE MAIN POWER GET BACK DURING 10 SEC)
      digitalWrite(greenLed,HIGH);                                        //Connect the load
      continue;}                                                          //Bypass
      digitalWrite(blueLed,LOW);                                          //Don't turn off the generator
      x=0;                                                                //Renew the loop
      continue;                                                           //Bypass
      }
      x++;                                                                //Increase x value
      if(digitalRead(pwrInput)==LOW){                                     //If the main power is turned off
        if(analogRead(gnrRead)<450 && digitalRead(greenLed)==LOW){        //If the generator is still off & No load yet
      delay(3000);                                                       
      lcd.clear();
      lcd.print("Starting...");
      digitalWrite(motor,HIGH);                                           //Starting the motor to drive the generator
      delay(3000);
      if(analogRead(gnrRead)>=450 && analogRead(gnrRead)<=640){           //If the generator reading is good (2V)
        digitalWrite(motor,LOW);                                          //Stop the motor
        digitalWrite(blueLed,HIGH);                                       //The generator is running
        lcd.clear();
        lcd.print("Running");
        delay(3000);
        digitalWrite(greenLed,HIGH);                                      //Connect the load
        if(digitalRead(blueLed)==HIGH){x=0;continue;}                     //If the generator is running > renew the loop
        }
        else if(x>=4){                                                    //(In case which the generator is not running and exhausted 4 times to start and failed)
          if(digitalRead(pwrInput)==LOW && digitalRead(redLed)==HIGH){    //If there is no main power and the led of power circuit is ON
          flag=0;                                                         //Stop the loop
          digitalWrite(motor,LOW);                                        //Turn off the motor
          lcd.clear();
          lcd.print("Starting failure");
          digitalWrite(yellowLed,HIGH);                                   //The led indicates to "Starting failure"
          break;}
        }
        else if(digitalRead(blueLed)==LOW){digitalWrite(motor,LOW);}      //If the generator is not running > turn off the motor in order to prevent the motor from still turning
          }
          }
          }
}

So, The string “AGS System is ON” is appears with no weirdness. Also “Starting…” appears well but others is not.

I know the problem is in the code not in hardware because I tried with simple example it works well . But I couldn’t find where the is wrong exactly (I’ve repeated the structure of the code in more than form but still…)

Regards,

I know the problem is in the code not in hardware because I tried with simple example it works well .

Actually the problem is most likely in the hardware, specifically the presence of the motor. Does it work properly when the motor is replaced with an LED?

Don

floresta:
Actually the problem is most likely in the hardware, specifically the presence of the motor. Does it work properly when the motor is replaced with an LED?

Don

I will try this. Becuase I tried without the motor.

Acutally, The problem is because the presence of the motor. Can you explain what is the affect of the motor on lcd?

So What I can do? becuase my project is based on the motor(s), Also lcd is required.

Mahdi

You could search through this forum to see how the problem has been dealt with in the past.

In general you have to reduce the effect of the motor on your power supply which in turn ultimately affects the LCD controller.

Snubber diodes across the motor windings, bypass capacitors across the LCD power terminals, separate power supplies for the motor and the LCD all come to mind.

Don

floresta:
You could search through this forum to see how the problem has been dealt with in the past.

In general you have to reduce the effect of the motor on your power supply which in turn ultimately affects the LCD controller.

Snubber diodes across the motor windings, bypass capacitors across the LCD power terminals, separate power supplies for the motor and the LCD all come to mind.

Don

Already, The motor have a separated power supply. Also required for LCD power?

What is the value of cap? it is 1000uF?

I get tired of saying this, but "lead dress" is critical - keeping all the wires between one part and the next, together. Ribbon cable is excellent for this.

And solder a 47 (or 100) µF capacitor (in correct polarity) directly between pins 1 and 2 of the LCD.

Paul__B:
I get tired of saying this, but "lead dress" is critical - keeping all the wires between one part and the next, together. Ribbon cable is excellent for this.

And solder a 47 (or 100) µF capacitor (in correct polarity) directly between pins 1 and 2 of the LCD.

I read about flyback voltage and freewheel diode.

I will replace a cap across power supply of lcd and a diode across the motor windings to prevent any side affects.

I will replace a cap across power supply of lcd ...

That's not what I said.

   ________                                           _____
  |        |                   wires                 |     |
  | POWER  |=========================================| LCD |
  | SUPPLY |                                         |_____|
  |________|

Don

floresta:
That's not what I said.

   ________                                           _____

|        |                  wires                |    |
  | POWER  |=========================================| LCD |
  | SUPPLY |                                        ||
  |
___|




Don

All those , Separated power supply for both the motor and lcd, snubber diode across the motor windings and a cap across Vcc&Gnd of the lcd.

Will get back soon with results.

Paul__B:
I get tired of saying this, but “lead dress” is critical - keeping all the wires between one part and the next, together. Ribbon cable is excellent for this.

And solder a 47 (or 100) µF capacitor (in correct polarity) directly between pins 1 and 2 of the LCD.

Done! Solved by a cap 100uF across lcd’s power supply.

Thanks all, Regards