Gsm900a avec mega

Memr avec ce code tjr le meme probleme des que j utilise une alimentation externe

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(10,11);
String textMessage;
// Create a variable to store Lamp state
String lampState = "HIGH";

// Relay connected to pin 7
const int relay = 7;
void setup()
{
  // Set relay as OUTPUT
  pinMode(relay, OUTPUT);
  // By default the relay is off
  digitalWrite(relay, HIGH);
  SIM900A.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println ("SIM900A Ready");
  delay(100);
  Serial.println ("Type s to send message or r to receive message");
}
void loop()
{
  if(SIM900A.available()>0){
    textMessage = SIM900A.readString();
    Serial.print(textMessage);    
    delay(10);
  } 
  if(textMessage.indexOf("ON")>=0){
    // Turn on relay and save current state
    digitalWrite(relay, LOW);
    lampState = "on";
    Serial.println("Relay set to ON");  
    textMessage = "";   
  }
  if(textMessage.indexOf("OFF")>=0){
    // Turn off relay and save current state
    digitalWrite(relay, HIGH);
    lampState = "off"; 
    Serial.println("Relay set to OFF");
    textMessage = ""; 
  }
  if(textMessage.indexOf("STATE")>=0){
    String message = "Lamp is " + lampState;
    sendSMS(message);
    Serial.println("Lamp state resquest");
    textMessage = "";
  }
}
 // Function that sends SMS
void sendSMS(String message){
  // AT command to set SIM900 to SMS mode
  SIM900A.print("AT+CMGF=1\r"); 
  delay(100);

  // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
  // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
    SIM900A.println("AT+CMGS=\"+212662096718\""); 
  delay(100);
  // Send the SMS
  SIM900A.println(message); 
  delay(100);

  // End AT command with a ^Z, ASCII code 26
  SIM900A.println((char)26); 
  delay(100);
  SIM900A.println();
  // Give module time to send SMS
  delay(5000);  
}
 void RecieveMessage()
{
  Serial.println ("SIM900A Membaca SMS");
  delay (1000);
  SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
 }