Serial.println(); Help!

Hi guys! :smiley:

How can i stop overwriting my Serial.println(); (Alert Levels) on showing in serial monitor

const int buttonPin = 2;
const int buttonPin1 = 4;
const int buttonPin2 = 6;
const int ledPin = 12;// the number of the pushbutton pin
const int ledPin1 = 13;
const int ledPin2 = 11;
const int buzzerPin = 8;
// the number of the LED pin

// variables will change:
int buttonState = 0;
int buttonState2 = 0;// variable for reading the pushbutton status
int buttonState3 = 0;

void setup() {
Serial.begin(19200);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println("Alert Level 1!");
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
buttonState2 = digitalRead(buttonPin1);
if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
Serial.println("Alert Level 2!");
}
else {
// turn LED off:

digitalWrite(ledPin1, LOW);
}
buttonState3 = digitalRead(buttonPin2);
if (buttonState3 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
digitalWrite(buzzerPin, HIGH);
Serial.println("Alert Level 3!");
}
else {
// turn LED off:

digitalWrite(ledPin2, LOW);
digitalWrite(buzzerPin, LOW);
}
}

Hope you help me THANKS :smiley:

Check the baud rate of the Serial monitor, match it with your specified one. I think this may be your issue.

Suddenly the baudrate is match sir.

Your serial monitor is showing nothing unexpected.
I don’t get your issue. Explain it more.
Use code tag to paste your code

How are the pushbuttons connected? Is there external pullup or pulldown resistors?

If they're wired the most common way: Input Pin ●—T—● GND

and you're not using external resistors, then define your pushbutton inputs with INPUT_PULLUP.

Thanks for the replies.
This is just a simple water level indicator project using pushbutton code.

How can I make it likes this:
If the buttonState2 is high the buttonState will set to low automatically and buttonState shouldn't display "alert level 1" on serial monitor if the buttonState2 is high only showing "alert level 2" same with buttonState3.

// initialize the pushbutton pin as an input:
Β  pinMode(buttonPin, INPUT); 
Β  pinMode(buttonPin1, INPUT);
Β  pinMode(buttonPin2, INPUT);

β‘  Input Pin ●—T—● GND Use: pinMode(buttonPinx, INPUT_PULLUP);

β‘‘ 5V ●—T—● Input Pin Do not use this connection.

β‘’ 5V ●—T—●Input Pin——╱╲╱╲╱╲——● GND Your pinMode code is OK.

β‘£ 5V ●——╱╲╱╲╱╲——●Input Pinβ€”T—● GND Your pinMode code is OK.