serial monitor serial.print problem

hello, i m trying to write a code such that if a user press the switch the system stays on and if the user presses the switch it goes off at the movement i m getting printed system on for infinite times. i only wants it once to print in my serial monitor.

the condition is if user press it the system should be on if user press again it should go off and if the user decide to press again it should go on again. at the movement if system is on:

the output on monitor screen shows this
system on!!!
system is operating
(infinite loop)

here is my code:

// These constants won't change:
const int sensorPin = 2; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2; // pin that the button is attached to
boolean calabrated = false; // have we calabrated the sensor

void setup() {
// set the LED pins as outputs and the switch pin as input:
pinMode(indicatorLedPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
Serial.begin(9600);
}

void loop() {
if(!calabrated){
// while the button is pressed, take calibration readings:
while (digitalRead(buttonPin) == HIGH) {
calabrated= true;
Serial.println("System ON!!!!");
tempreading();
}
calabrated= true;
// signal the end of the calibration period
digitalWrite(indicatorLedPin, LOW);
Serial.println("System OFFFFF!!!!");
}
if(digitalRead(buttonPin) == HIGH) calabrated = false;
// do other suff here
}

void tempreading() {

// turn on the indicator LED to indicate that Heating process is happening:
digitalWrite(indicatorLedPin, HIGH);
Serial.println("System is on this part is operating!!!!");
int reading =analogRead(sensorPin);
if(reading < 920)
{

}
else
{
Serial.print("Temperature is more then 40*C");
}

}

Add two more booleans - onMsgSent and offMsgSent - initially set to false.

Before sending a message, see if onMsgSent is true. Don't send if it is. If it isn't, send the message and set the flag to true.

At some point, it might be necessary to reset these flags.

changed to this but arnt working...

// These constants won't change:
const int sensorPin = 2; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2; // pin that the button is attached to
boolean calabrated = false; // have we calabrated the sensor
boolean calibration = false; //

void setup() {
// set the LED pins as outputs and the switch pin as input:
pinMode(indicatorLedPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
Serial.begin(9600);
}

void loop() {
if(!calabrated){
// while the button is pressed, take calibration readings:
while (digitalRead(buttonPin) == HIGH) {
if(!calibration){
//calibration= true;
Serial.println("System ON!!!!");}
if(digitalRead(buttonPin) == HIGH) calibration = false;
tempreading();
}
calabrated= true;
// signal the end of the calibration period
digitalWrite(indicatorLedPin, LOW);
Serial.println("System OFFFFF!!!!");
}
if(digitalRead(buttonPin) == HIGH) calabrated = false;
// do other suff here
}

void tempreading() {

// turn on the indicator LED to indicate that Heating process is happening:
digitalWrite(indicatorLedPin, HIGH);
Serial.println("System is on this part is operating!!!!");
int reading =analogRead(sensorPin);
if(reading < 920)
{

}
else
{
Serial.print("Temperature is more then 40*C");
}

}

You want to send the messages only when in calibration mode. So, you need one flag the defines whether you are in calibration mode, or not.

If you are, you want to send two different messages, exactly once. You need one flag for each message, and you need to change the value of that flag at appropriate times.

bool onMsgSent = false;
bool offMsgSent = false;

Put each { on a new line, and use Tools + Auto Format, so you can see the structure of your program.

I was going to copy and paste your loop() here, and fix it for you, but I can't make sense of it.

The names of variables need to be relevant for the intended purpose. calibration is NO relationship to whether a message was sent, or not, and certainly can't be used for two different purposes (sending/not sending two different messages).

When i change the code to this as still showing me the system on for infinite as well as system operating mess on monitor window!

/*

// These constants won't change:
const int sensorPin = 2; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2; // pin that the button is attached to
boolean calabrated = false; // have we calabrated the sensor
//boolean calibration = false; //
boolean onMsgSent = false;
boolean offMsgSent = false;

void setup() {
// set the LED pins as outputs and the switch pin as input:
pinMode(indicatorLedPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
Serial.begin(9600);
}

void loop() {
if(!calabrated){
// while the button is pressed, take calibration readings:
while (digitalRead(buttonPin) == HIGH) {
if(!onMsgSent){
onMsgSent= true;
Serial.println("System ON!!!!");}
if(digitalRead(buttonPin)==HIGH) onMsgSent =false;
//if(digitalRead(buttonPin) == HIGH) calibration = false;
tempreading();
}
calabrated= true;
// signal the end of the calibration period
digitalWrite(indicatorLedPin, LOW);
Serial.println("System OFFFFF!!!!");
}
if(digitalRead(buttonPin) == HIGH) calabrated = false;
// do other suff here
}

void tempreading() {

// turn on the indicator LED to indicate that Heating process is happening:
digitalWrite(indicatorLedPin, HIGH);
if(!onMsgSent){
onMsgSent= true;
Serial.println("System is on.. This part is operating!!!!");}
if(digitalRead(buttonPin)==HIGH) onMsgSent =false;
//Serial.println("System is on this part is operating!!!!");
int reading =analogRead(sensorPin);
if(reading < 920)
{

}
else
{
Serial.print("Temperature is more then 40*C");
}

}

You want help? Follow directions:

Put each { on a new line, and use Tools + Auto Format, so you can see the structure of your program.