Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Problem to read SMS on: January 12, 2014, 03:51:38 pm
I use the code from http://www.instructables.com/id/Control-the-relays-via-GPRS-SMS/?ALLSTEPS to control two LEDs with SMS commands.

It has worked!

Suddenly, I can only control the Arduino circuit with SMS containing 3 characters.
If I connect the GSM shiled to a serial monitor, I see SMS containing more than three characters.
It seems that something is wrong in the code or something has happened to the Arduino.
A few weeks ago, everything worked and I have not changed in the code ...

What could be wrong?

Code:
#include <SoftwareSerial.h>
 
//http://www.instructables.com/id/Control-the-relays-via-GPRS-SMS/?ALLSTEPS
// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int GreenLed=6;
int RedLed=7;

 
void setup()
{
  Serial.begin(19200);                 // the GPRS baud rate
  // Initialize  PINs
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
 Serial.println( "AT+CMGF=1" );
 delay(200);
}
 
 
void loop()
{
    char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
       
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           msg += String(SerialInByte);
         }
     }   
}
// EN: Make action based on the content of the SMS.
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
 
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  GreenLed, HIGH );   
  }
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  RedLed, HIGH );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  GreenLed, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  RedLed, LOW );
  }
 Serial.println("AT+CMGD=1,4"); // delete last SMS
}

// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=" );
  Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
 
  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "*** SMS Received ***" );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }
 
  // EN: SMS store readed through UART (result of GprsReadSmsStore request) 
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
 
  // EN: +CMGR message just before indicate that the following GRPS Shield message
  //     (this message) will contains the SMS body
  if( SmsContentFlag == 1 ){
 //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
 //   Serial.println( msg );
 //   Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
 
  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0;
}
2  Using Arduino / Project Guidance / How to write position in a SMS? on: November 21, 2013, 04:50:54 pm
I can control two LEDs by sending a SMS, but I also want to get the GPS position delivered in a SMS. Don't manage this and want some help with the code. Or should I stop with Arduino programming...?

Code:
// ---------------  HOW TO SEND POSITION

   if( sms.indexOf("position") >= 0 ){
     textForSMS = lat; //HOW TO WRITE
  sendSMS(textForSMS);

// ---------------  HOW TO SEND POSITION


Code:
#include <SoftwareSerial.h>
#include "DHT.h"
#include <TinyGPS.h>

long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(2, 3); // create gps sensor connection
TinyGPS gps; // create gps object

String msg = String("");
String textForSMS;
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int GreenLed=6;
int RedLed=7;
int t; //Holds temp
int h; //Holds hum fukt

int tempfukt = 12;     // digital pin for temperature and humidity
DHT dht(tempfukt, DHT11);

// Array to hold the number a SMS is retreived from
// char senderNumber("AT+CMGF=1",20);
 
void setup()
{
  Serial.begin(19200);                 // the GPRS baud rate
    gpsSerial.begin(38400); // connect gps sensor
  // Initialize  PINs
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
 Serial.println( "AT+CMGF=1" );
 delay(200);
}
 
 // --------------- Funktion for sending SMS
 void sendSMS(String message)
{
     Serial.println( "AT+CMGF=1" );
     delay(100);
     Serial.write("AT+CMGS=\"+46706610100\"\r");    //Start accepting the text for the message
     delay(100);
     Serial.print(message);   //The text for the message
     delay(100);
     Serial.write(26);   // Ctrl + Z
     }
// ---------------   
 
void loop()
{

    char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
       
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           msg += String(SerialInByte);
         }
     }   
     
      if(gps.encode(gpsSerial.read())){ // encode gps data
    gps.get_position(&lat,&lon); // get latitude and longitude
     
     }
}
// EN: Make action based on the content of the SMS.
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
 
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  GreenLed, HIGH );
 // --------------- Send Message
  sendSMS("Green LED On");
  }
 // --------------- 
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  RedLed, HIGH );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  GreenLed, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  RedLed, LOW );
  }
// ---------------  Temp
  if( sms.indexOf("temp") >= 0 ){
   h = dht.readHumidity();
   t = dht.readTemperature();
     if (isnan(t) || isnan(h)) {
       textForSMS = "Temp error";
       }else {
  textForSMS = "Temp "; 
  textForSMS.concat(t);
  textForSMS = textForSMS + " C and humidity ";
  textForSMS.concat(h);
  textForSMS = textForSMS + " percent";
     sendSMS(textForSMS); } 
 }
// ---------------  HOW TO SEND POSITION

   if( sms.indexOf("position") >= 0 ){
     textForSMS = lat; //HOW TO WRITE
  sendSMS(textForSMS);

// ---------------  HOW TO SEND POSITION

 
 Serial.println("AT+CMGD=1,4"); // delete last SMS
}

// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=" );
  Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
 
  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "*** SMS Received ***" );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }
 
  // EN: SMS store readed through UART (result of GprsReadSmsStore request) 
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
 
  // EN: +CMGR message just before indicate that the following GRPS Shield message
  //     (this message) will contains the SMS body
  if( SmsContentFlag == 1 ){
 //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
 //   Serial.println( msg );
 //   Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
 
  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0;
}
3  Using Arduino / Project Guidance / Re: Answer SMS to the sender on: November 19, 2013, 05:32:02 am
Thanks. I have read that file... Realise that I'm not the programmer as I want to be.
I think the solution for me is to hard code the phone number.
4  Using Arduino / Project Guidance / Re: Answer SMS to the sender on: November 19, 2013, 02:19:00 am
Thanks for the reply. I have an EFcom Pro with a SIM900. After eight hours of reading and searching I still haven't found relevant information to solve my problem...

If I manage to put the incoming number in an array, I also can use that function to check if the number is an authorized number to control my device.
5  Using Arduino / Project Guidance / Answer SMS to the sender on: November 18, 2013, 06:13:32 pm
When I receive a SMS I want to store the sender's number in an array to be able to automatically answer to that number.

Can someone help me with the code for that AT command? Should I use +CMGF or CMGL and how do I sort out just the phone number?
6  Using Arduino / Programming Questions / Re: Serial communication between two arduinos on: February 27, 2012, 04:01:15 pm
Thank you. It seems to work :-) and I think I understand your code ...
Does this only with one sensor or can I define multiple "outputs"?

/Örjan
7  Using Arduino / Programming Questions / Serial communication between two arduinos on: February 27, 2012, 03:25:21 pm
I need som help with my code (is not a programmer...
I want to communicate serial between two Arduino. A potentiometer on one board to control an output on the other. I'm building a ROV and want to control the steering in this way.
Can I have the serial communication through 60 feet of cable?)

------------Transmit code on board no 1---------------
//Send potentiometer value from one Arudino board to another
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin with LED for control of pot function
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  // read the analog in value:
  sensorValue = analogRead(analogInPin);           
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255); 
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);           

  // print the results to the serial monitor:
   Serial.println(outputValue);   
  delay(10);                     
}

------------Receiving code on board no 2---------------
//Recive potentiometer value and dim a LED
int outputValue = 127;         // start value
const int analogOutPin = 6; // Analog output pin that the LED is attached to

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  // if we get a valid byte, read analog ins:
   if (Serial.available() > 0) {
    // get incoming byte:
    outputValue = Serial.read();
     delay(10);         
  }
analogWrite(analogOutPin, outputValue);
}


8  International / Scandinavia / Styra ett Arduino från ett annat? on: January 27, 2012, 04:24:16 pm
Jag håller på att bygga en undervattens-ROV som kommer att styras via en kabel. För att få ner antalet trådar funderar jag om man enkelt kan kommunicera med två kort via seriell anslutning. Som exempel, en lampa sitter på det ena kortets utgång, men jag vill tända den när jag ger en signal på det andra kortets ingång. Skulle också kunna tänka mig att det ena kortet har en tempgivare och jag visar temperaturen på en LCD på det andra kortet.

Är seriell komminukation mellan de två kortetn rätt väg att gå?

Hej - Örjan
Pages: [1]