Tronixlabs Support Forum
Register Latest Topics
 
 
 


Reply
  Author   Comment  
jmlcatarino

Junior Member
Registered:
Posts: 2
Reply with quote  #1 
Hi there, I've been using your guide lines in order to put a project to work but I've bumped into some problems.

For starters that is an excellent explanation and made me get to almost where I want.
The problem I found is at the coding level, where I'm the weakest link.
I managed to merge/compile parts of the example codes with something I got from another site but now it seems that Arduino is getting to sleep and forgets to do what It was supposed to.
The project is a low cost, open source, (of course), GSM alrm/intercom interface. I needed something to report warnings whenever the products levels get to a minimum. This should be made by SMS. But on the other way, I needed a way to communicate with the persons on site or make possible for them to call me just by pressing a button. The call is made to my cell phone only as well as the messages, and it only answers calls from me also. Well, I've managed to do that but the code is not Wright and after some time Arduino just doesn't respond to commands.

Here is the code used for you guys to see and give me some feedback and maybe help by pointing me the problem.

/*
* Arduino Home Security GSM Alarm/shop intercom based on
* An Arduino + SIM900A Project by T.K.Hareendran
*originally Tested at TechNode PROTOLABZ in 21 August 2014
* http:// http://www.electroschematics.com
*and adapted to perform as a shop alarm/warning system & intercom
*with parts taken from examples from
*http:// http://www.tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/
*/
// Depending on your modem and preferences,
//Connect the Tx pin of the GSM modem to D7
//Connect the Rx pin of the GSM modem to D8
//SMS Trigger Key/Input connected to D3 (Active LOW)
//CALL Trigger Key connected to D4 (Active LOW)
//Answer Trigger Key Connected to D5 (Active LOW)

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // RX and TX pins to communicate with GSM module

char inchar = 0; // Will hold the incoming character from the GSM Shield/module

int numring = 0; // this is the part that counts the number of rings and then answers the call
int comring = 3;
int onoff = 1;

#define msg_key 3
#define call_key 4
//#define answ_key 5

String number = "9*******3"; // Add the 9/10-Digit Mobile Number to which message / call is to be made,by replacing the 0's

void setup()
{
  Serial.begin(19200);
  SIM900.begin(19200);
  SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
  //SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); // blurt out contents of new SMS upon receipt to the GSM shields serial out
  delay(100);
  pinMode(msg_key, INPUT);
  pinMode(call_key, INPUT);
  //pinMode(answ_key, INPUT);
  digitalWrite(msg_key, HIGH);
  digitalWrite(call_key, HIGH);
  //digitalWrite(answ_key, HIGH);
}
void doSomething()
{
  if (onoff == 1)
  {
    onoff = 1;
    SIM900.println("ATA"); // here we define the auto answering after the preset rings
    delay(6000); // and a delay so that the function isn't called again on the same phone call
  }
}
void loop()
{
  //Sends an sms everytime msg_key is pressed
  if (digitalRead(msg_key) == LOW) // Check if the sms key is being pressed
  {
    SIM900.println("AT+CMGF=1"); // Set the Mode as Text Mode
    delay(150);
    SIM900.println("AT+CMGS=\"+351" + number + "\""); // Specify the Destination number in international format by             replacing the 0's
    delay(150);
    SIM900.print("Alerta! Niveis baixos!"); // Enter the message
    delay(150);
    SIM900.write((byte)0x1A); // End of message character 0x1A : Equivalent to Ctrl+z
    delay(150);
    SIM900.println();
    delay(150);
  }
  //Makes a call when call_key is pressed
  else if (digitalRead(call_key) == LOW) // Check if the call key is being pressed
  {
    SIM900.println("ATD+351" + number + ";"); //Specify the number to call(don't forget to change the international dial number"+351")
    while (digitalRead(call_key) == LOW);
    delay(50);
  }
    //This is the option to manualy answer the call(for tests only)
    //else if (digitalRead(answ_key)==LOW) // Check if the answer  key is being pressed
    //{
    //SIM900.println("ATA");
    //while (digitalRead(answ_key)==LOW);
    //delay(50);
    //Now we simply display any text that the GSM shield sends out on the serial monitor
{    
    if (SIM900.available() > 0)
    {
      inchar = SIM900.read(); //Get the character from the cellular serial port.
      Serial.print(inchar); //Print the incoming character to the terminal.
      {
        if (inchar == '9')
        {
          delay(10);
          inchar = SIM900.read();
          if (inchar == '*')
          {
            delay(10);
            inchar = SIM900.read();
            if (inchar == '*')
            {
              delay(10);
              inchar = SIM900.read();
              if (inchar == '*')
              {
                delay(10);
                inchar = SIM900.read();
                if (inchar == '*')
                {
                  delay(10);
                  inchar = SIM900.read();
                  if (inchar == '*')
                  {
                    delay(10);
                    inchar = SIM900.read();
                    if (inchar == '*')
                    {
                      delay(10);
                      inchar = SIM900.read();
                      if (inchar == '*')
                      {
                        delay(10);
                        inchar = SIM900.read();
                        if (inchar == '3')
                        {
                          delay(10);
                          numring++;
                          if (numring == comring)
                          {
                            numring = 0;
                            doSomething();
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

jmlcatarino

Junior Member
Registered:
Posts: 2
Reply with quote  #2 
Well, never mind guys, I figured it out. There's a misunderstanding with the power supply voltage, that might lead us into mistakes and malfunction of the module shield and Arduino. If you power the shield and Arduino board with the recommended 5Volt/2Amps DC, it just won't be enough because of the power loss in the voltage regulators. I didn't took that in account and it made me have lots of issues and malfunctions. They should state that that is the voltage to the SIM900 module standanlone and not to the shield. Maybe it's me but that would be great.


Previous Topic | Next Topic
Print
Reply

Quick Navigation: