programming problem

hello

i made energy meter using arduino. But some problem in programming . The problem is GSM And arduino programming addition. means when i mix or add the program of gsm in energy meter program than it not display original value of energy.

our aim is
the energy use is more than the contracted load ( cross the limit) than gsm is send the message to the control room.

we use arduino mega 2560 , icomsat 1.1 gsm sim900 .

i attached the program

power_measurement_with_gsm.ino (4.4 KB)

void displayPower() {
  lcd.clear();
  lcd.print(realPower, 0);
  lcd.print("w ");
  lcd.print(apparentPower, 0);
  lcd.print("va ");
  lcd.print(powerFactor * 100, 0);
  lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print(voltageRMS, 0);
  lcd.print("v ");
  lcd.print(currentRMS, 1);
  lcd.print("a ");
  lcd.print(kilowattHour, 4);

  if (realPower < 69)
  {
    digitalWrite(led, LOW);

  }
  else if ( realPower >= 70)
  {

    digitalWrite(led, HIGH);
    sendSMS();
   // do {} while (1);
  }
  else
  {
    digitalWrite (led, LOW);
  }
}

whether the values displaying on LCD screen??
i changed lCD part little bit ; just try it out realPower what value is displaying

Start by making TWO programs...

One to do almost everything connected with reading the energy usage. Have a subroutine called "SendData" in that, which, for the moment, just sends to the serial monitor...

http://sheepdogguides.com/arduino/aht1serimoni.htm

... whatever you eventually want to send as GSM.

The other to wait until a button connected to an input is pressed, and then send a message by GSM.

When you have those two programs fully working, THEN putting them together into a program that Does It All will be simple.

And the time to make the two programs separately, and merge them, will be lot less than the time to do everything at once.

While you are making the two programs, keep track of which pins, features, each is using, and be careful not to build things that BOTH use one (or more!) pins, features, but for different things.