i want to use both serial monitor and lcd

can i both use both use lcd and serial monitor? if yes, pls help me, i trying to use both serial monitor and lcd in my mega arduino, 4x4 keyad, servo motor,coin acceptor. In my lcd output, it display an words something i didn't know what it is. I also research about serial pins, but i don't quite understand it. :frowning:

here my code:

// Coin to Bill System

#include <Servo.h>

Servo myservo;

// constants
const int coinpin = 20,ledpin = 13,button1 = 24; //here's my pins
int servoPin = 22,buttonState =0; 

// Variables
volatile int pulse = 0,a=0;
Servo Servo1; 
boolean bInserted = false;
boolean  b=0,c=0;


//...
// Inventory Systems



#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)




#define redLED 10 //define the LED pins
#define greenLED 11

char* password ="1234"; //create a password
int pozisyon = 0; //keypad position




const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins [rows] = {2, 3, 4, 5}; //pins of the keypad
byte colPins [cols] = {6, 7, 8, 9};

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)

void setup(){
  
//Coin to Bill System

 Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  pinMode(ledpin, OUTPUT);
  Servo1.attach(servoPin);
  pinMode(button1,INPUT);
  
  // Inventory Systems
  lcd.begin(16, 2);
  pinMode(redLED, OUTPUT);  //set the LED as an output
  pinMode(greenLED, OUTPUT);
  setLocked (true); //state of the password


}

void loop(){
  
//Coin to Bill System
 myservoloop();
 checkButton1();
 checkcoin();


// Inventory Systems
  char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("    Welcome");
  lcd.setCursor(0, 1);
  lcd.print(" Enter Password");

  if(whichKey == '*' || whichKey == 'A' ||       //define invalid keys
  whichKey == 'B' || whichKey == 'C' || whichKey == 'D'|| whichKey == '#'){

    pozisyon=0;
    setLocked (true);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("TRY AGAIN!");
    delay(1000);
    lcd.clear();
  }
  if(whichKey == password [pozisyon]){

    pozisyon ++;
  }
  if(pozisyon == 4){ 
    
    setLocked (false);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*** Verified ***");
    delay(3000);
    lcd.clear();
systemfunction();

  }
  delay(100);
}


void systemfunction(){
  
  
   lcd.setCursor(0,0);
 lcd.print("Pls Enter your");
  lcd.setCursor(0,1);
  lcd.print("options:");
  delay(1000);
  lcd.setCursor(0,0);
  lcd.print ("Bill to coins[1]");
  lcd.setCursor(0,1);
  lcd.print ("Coins to Bill[2]");
  delay(1000);
  lcd.clear();
  
char whichKey = myKeypad.waitForKey();

 if(whichKey == '1'){// coin to bill system
  lcd.setCursor(0,0);
  lcd.print("Pls Enter Number");
  lcd.setCursor(0,1);
  lcd.print("of Coins:");
  

char coins;
String convert1,convert_integer1;



while(coins !='#'){

coins = myKeypad.waitForKey();

if(coins =='#'){
  
   return systemfunction();//return to system function
  
}

if(coins =='*'){
  return 0;
}

lcd.print(coins);

if(coins =='1'||coins =='2'||coins =='3'||coins =='4'||coins =='5'||coins =='6'||
 coins =='7'||coins =='8'||coins =='9'){

  convert1=String(convert1 + coins);

convert_integer1 = convert1.toInt();
  
 }

}
 }

 
 
 else if(whichKey == '2'){ //bill to coins system

   char bills;
  String convert2,convert_integer2;

  lcd.setCursor(0,0);
  lcd.print("Pls Enter Number");
  lcd.setCursor(0,1);
  lcd.print("of Bills:");
  
   while(bills !='#'){
    bills = myKeypad.waitForKey();
    
    
if(bills =='#'){
  
   return systemfunction();//return to system function
  
}
    lcd.print(bills);

   if(bills =='1'||bills =='2'||bills =='3'||bills =='4'||bills =='5'||bills =='6'||
 bills =='7'||bills =='8'||bills=='9'){

  convert2=String(convert2 + bills);

convert_integer2 = convert2.toInt();
 }

    
   }
   
 }
  else{
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Invalid Key!");
    delay(1000);
    lcd.clear();
     return systemfunction();
  }


    
  
}



void setLocked(int locked){
  if(locked){
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
    }
    else{
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);
    }
  }
//...
// Coin to Bill System

void checkcoin(){

   if( bInserted  ){ // for show LED ON when Inserted
     bInserted = false;
     digitalWrite(ledpin, HIGH);    
     delay(1000);
  
  }else{
   
  // Turn off LED
  digitalWrite(ledpin, LOW);
  }
  
}
void checkButton1() {

  buttonState = digitalRead(button1);

}

// Interrupt
void coinInterrupt(){
 
  // Each time a pulse is sent from the coin acceptor,
  // interrupt main loop to add 1  and flip on the LED
  pulse++ ;
  a++;
  bInserted = true;

 // digitalWrite(ledpin, HIGH);
 // Serial.println( pulse );

   
}

void myservoloop(){

if(a==4 && buttonState == HIGH ){
  
  Servo1.write(0);
  delay(1000);

 Servo1.write(90);
 delay(1000);

  a=(a-4);
}


   if( bInserted  ){ // for show LED ON when Inserted
     bInserted = false;
     digitalWrite(ledpin, HIGH);    
     delay(1000);
     
     
  }else{
   
  // Turn off LED
  digitalWrite(ledpin, LOW);

}

}
//...
// merging system codes

can i both use both use lcd and serial monitor?

Yes

Does the LCD example "HelloWorld" program work OK ?

Hi,
Have you developed your code in stages?

If so, then you must have written some code JUST to write to the LCD, to make sure your coding and connections are correct.

As @UKHeliBob has suggested, try one of the LCD library examples.

Tom.. :slight_smile: