GSM + arduino uno

i am using a GSM module with my uno. The aim of my project is simply that i send an SMS to the module, which sends a high to the assigned pin to power an electromagnet to trigger a reed switch. this is my code;

/*
 *  SMS with GSM Playground - GSM Shield for Arduino
 *  Released under the Creative Commons Attribution-Share Alike 3.0 License
 *  http://www.creativecommons.org/licenses/by-sa/3.0/
 *  www.hwkitchen.com
 */


/*
  Important:
  ==========
  This sketch step by step reads and erases all SMSs from your SIM
  card so if there are some important SMSs stored in your
  SIM card please backup them up before inserting SIM card
  to the GSM Playground
*/
int ledPin = 12;
int ledPin2 = 0;
int ledPin3 = 11;
#include "GSM.h"  

// max length for SMS buffer(including also string terminator 0x00)
// here SMS can have max. 99 characters (1 character is reserved for
// string termination 0x00)
#define SMS_MAX_LEN 100

// definition of instance of GSM class
GSM gsm;




int pos = 0;

// variables used for timing
unsigned long	previous_timer;
byte timer100msec;

int val;
char string[30];
char position;          
char phone_number[20];      // array for the phone number string
char sms_text[SMS_MAX_LEN]; // array for the SMS text
char *ch;                   // pointer to the character
 

void setup()
{
  pinMode (ledPin, OUTPUT);
  pinMode (ledPin2, OUTPUT);
  pinMode (ledPin3, OUTPUT);
  // initialization of serial line
  gsm.InitSerLine(115200);		
  // turn on GSM module
  gsm.TurnOn();
  // set direction for GPIO pins
  gsm.SetGPIODir(GPIO10, GPIO_DIR_OUT);
  gsm.SetGPIODir(GPIO11, GPIO_DIR_OUT);
  
  // periodic timer initialization
  timer100msec = 0;
  previous_timer = millis();
  // we are not registered so far => disable button
  gsm.DisableUserButton();

}

void loop()
{
  // -------------------
  // timing of main loop
  // -------------------
  if ((unsigned long)(millis() - previous_timer) >= 100) { 
    previous_timer = millis();  

    //*******************************
    //****** EVERY 100msec. *********
    //*******************************
    if (gsm.IsUserButtonEnable() && gsm.IsUserButtonPushed()) {
      // operation with the user button is enabled and user button
      // is pushed => send SMS
      // and disable user button until SMS is not sent 
      gsm.DisableUserButton();
      gsm.TurnOffLED();

      // read temperature
      val = gsm.GetTemp();
      if (val > -1000) {
        // temperature is OK -> send SMS to the specified 
        // phone number
        // ----------------------------------------------
        
        // prepare a string which will be send by the SMS:
        // "Temperature: 25 C"  
        sprintf(string, "Temperature: %i C", val/10);

        // in case you want to send SMS to the specific number
        // change 123456789 to your phone number
        // gsm.SendSMS("123456789", string); 

        // in case you want to send SMS to the specific SIM phonebook position
        // here we send to the first SIM phonebook position
        gsm.SendSMS(1, string);
      }
    }
    
    //*******************************
    //****** EVERY 200msec. *********
    // %2 means every 200 msec.
    // +1 means - 100msec. "before" a previous 100msec. action
    // so the processor power is better spreaded
    //  
    // in case +1 is not used but only: if (timer100msec % 2 == 0)  
    // then this action will also executed every 200msec.
    // but previous EVERY 100msec. and this EVERY 200msec.
    // is executed in the same 100msec. point so the processor
    // time is not used so effectively
    //*******************************
    if ((timer100msec+1) % 2 == 0) {
      // here it is possible to place your code which will be executed
      // each 200 msec.
      // ---------------------------------------------------------
    }
    
    //*******************************
    //****** EVERY 500msec. *********
    // %5 means every 500 msec.
    // +2 means - 200msec. "before" a first 100msec. action
    // so the processor power is better spreaded
    //*******************************
    if ((timer100msec+2) % 5 == 0) {
      // here it is possible to place your code which will be executed
      // each 500 msec.
      // ---------------------------------------------------------
    }
    

    //*******************************
    //****** EVERY 1 sec. ***********
    // %10 means every 1000 msec. = 1sec.
    //*******************************
    if ((timer100msec+3) % 10 == 0) {

      // is the GSM module registered?
      // -----------------------------
      gsm.CheckRegistration();
      if (gsm.IsRegistered()) {

        // GSM modul is still registered
        // -----------------------------
        gsm.EnableUserButton();
        gsm.TurnOnLED();
      }
      else {
        // not registered - so disable button
        // ----------------------------------
        gsm.DisableUserButton();
        gsm.TurnOffLED();
      }
    }


    //*******************************
    //****** EVERY 3 sec. ***********
    // %30 means every 3000 msec. = 3sec.
    //*******************************
    if ((timer100msec+4) % 30 == 0) {

      // is there a new UNREAD SMS ?
      // if YES - SIM position > 0 is returned
      // -------------------------------------
      if (gsm.IsRegistered()) {
        // GSM module is registered

        // Note: if there is new SMS before IsSMSPresent() is executed
        // this SMS has a status UNREAD
        // after calling IsSMSPresent() method status of SMS
        // is automatically changed to READ
   
        position = gsm.IsSMSPresent(SMS_ALL);
        if (position > 0) {
          // we have new SMS 
          // now we will make authorization with SIM phonebook pos. 1,2,3
          // ------------------------------------------------------------
          if (GETSMS_AUTH_SMS == gsm.GetAuthorizedSMS(position, phone_number, sms_text, SMS_MAX_LEN,
                                                      0, 0)) {

            // SMS comes from authorized phone number 
            // so lets check SMS text
            // --------------------------------------

            // 1) e.g. text "Temp?"
            // --------------------
            ch = strstr(sms_text, "Happy Birthday");
            if (ch != NULL) {
              digitalWrite(ledPin2, HIGH);
              delay(10000);
              digitalWrite(ledPin2, LOW);
             
             gsm.DeleteSMS(position);             
              }               
              }              
            }
            
                     // 1) e.g. text "Temp?"
            // --------------------
            ch = strstr(sms_text, "Merry Christmas");
            if (ch != NULL) {
              digitalWrite(ledPin, HIGH);
              delay(10000);
              digitalWrite(ledPin, LOW);
             
             gsm.DeleteSMS(position);             
           loop ();  
            }               
              }              
            }

            

            // 3) e.g. text "GPIO10 OFF"
            // -------------------------
            ch = strstr(sms_text, "Happy New Year");
            if (ch != NULL) {
              digitalWrite(ledPin3, HIGH);
              delay(10000);
              digitalWrite(ledPin3, LOW);
             
              gsm.DeleteSMS(position);

              int target = 179; // Where you want the servo to go
loop();

              }


          // and delete received SMS 
          // to leave place for next new SMS's
          // ---------------------------------
          gsm.DeleteSMS(position);
        }


    
    
    
    //********************************************
    //********WRAP AROUND COUNTER 10 sec. ********
    //********************************************
    timer100msec = (timer100msec + 1) % 100;
  }

and it was working perfectly to Pin 0 (i fortunately have a video to prove it), but Pins 11 and 12 did not output enough voltage to power the electromagnet, and when tested with an LED to these pins, they stay on and do not return to Low after 10 secs..

but now when i turn on the module, PINs 0 and 1 are constantly High, and have no effect on the electromagnet. I've been using a small dc motor to test the pins as i can then see the output.

although Pins 11 and 12 power an LED, they have no effect on the electromagnet or motor, that is why i started using Pin 0.

if anyone can shed any light on why Pin 0 and 1 are always high now, or how best to output to power an electromagnet i would be very grateful.

thanks

rosanna

You should not be using an electromagnet or motor to test I/O pins by connecting to them directly. The I/O pins on the Arduino are only designed to output low currents (<20mA) and electromagnets and motors nearly always draw much more than that. The result is that you can damage your microcontroller permanently.

If you want to turn on electromagnets and motors you will need a higher-current interface of some sort. Begin by looking through the "Interfacing with Hardware" section of the playground:

http://arduino.cc/playground/Main/InterfacingWithHardware

Also note that pins 0 and 1 are in use by the USB interface of the Arduino. They are used for uploading programs and for serial communication to a PC. You should not treat them as general-purpose I/O pins.

--
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected