Help me guys...

Hi i’m new in arduino…

is it possible to run a loop or count a number from 1 - 60 continuously while sending message?

for example:

for(seconds=0;seconds<60;seconds ++){
delay(1000);
Serial.print(seconds);
}

if (seconds == 10){
Sms.send(“10 Seconds elapsed”);

}

considering the delay of SMS/GPRS shield on sending message.

The problem is if the loop is equal to 10 it sends the message but the loop stopped and in continue if send is done…
is it possible?

Why is the Sms.send() outside of the for loop in your example ?

for(seconds=0;seconds<60;seconds ++){
delay(1000);
Serial.print(seconds);
}

if (seconds == 10){
Sms.send("10 Seconds elapsed");

}

It seems extremely unlikely that at the end of the loop, “seconds” will have the value 10.

for(seconds=0;seconds<60;seconds ++){
  delay(1000);
  Serial.print(seconds);

  if (seconds % 10 == 0){
    Sms.send("10 Seconds elapsed");
  }
}

might be closer (Cue the cries of pain over the use of “delay()”)

Thank you for the reply....

the reason why the if condition is outside the for loop, coz' i'm in a series of testing..

but i already tried to put the if condition inside the for loop, but it still the same..

if seconds is equal to 10, it sends message from GSM/GPRS shield but the loop stuck at 10 and never to continue again resulting to send message again and again...

but i already tried to put the if condition inside the for loop, but it still the same…

Are you sure you used “==” and not “=” in the condition?
That would gum things up.

yes sir it's "== 0"

I know the problem sir.. the problem is the if condition interrupt the loop when seconds is equal to 10 that's why the loop stuck at 10 and send message again and again and the loop never resume again..

the problem is I don't know how to resolve it.. is there another way to do this?

it's like multi-tasking correct me if i'm wrong. co'z it's some thing like continue to count while sending message every time the value of seconds is equal to 10 without interrupting the loop.

What does your print of seconds show you ?

Please post your whole program so that we can see what else might be happening.

the problem is the if condition interrupt the loop when seconds is equal to 10 that's why the loop stuck at 10 and send message again and again and the loop never resume again..

I'm not sure I see your reasoning there. There is no "interrupt", and the SMS send should not loop.

With a problem like this start without any SMS stuff. Just get your program to show on the serial monitor the stuff you want to send as an SMS. This will make debugging much easier.

When that works, write another short sketch that sends a fixed sms at fixed intervals.

When that works, just combine the two.

...R

UKHeliBob here is the whole code

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include <SD.h>
#define  MODEPIN  2


SMSGSM sms;
File myFile;
int a = 4;

const int switchPin = 7;
int counter;
int infinite; // (/)
int tipped;
int nt;
float perTipped = 0.5; // (/)
int numdata;
//boolean started=false;
char smsbuffer[160];
char n[20];
//---------------------
char val1[25];
char val2[25];
char val3[25];

char asa[10];
//-------------------------
int hh = 0;
int mm = 0;
int ss = 0;
int x = 0;

//---------------------
void setup(){
Serial.begin(9600);
delay(1500);          // Allow time for Serial LCD to set up
digitalWrite(MODEPIN, HIGH);
pinMode(switchPin, INPUT);        // switchPin is an input
digitalWrite(switchPin, HIGH);    // Activate internal pullup resistor
Serial.write(0x02);
Serial.print("F");
Serial.write(0x03);

Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code

while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
   Send_To("1", "Starting SD card..." ,"0");
   delay(1500);
   pinMode(10, OUTPUT);
  if (!SD.begin(4)) {
  Send_To("2", "Starting failed!" ,"0");
  return;
  }
  Send_To("2", "Starting done" ,"0");
//---------------------------------------------------
delay(1500);
Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code
Send_To("1", "GSM Shield testing." ,"0");
if (gsm.begin(2400)){
Send_To("2", "status=READY" ,"0");
}
  else 
  Send_To("2", "status=IDLE" ,"0");

delay(1500);
Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code
};


void loop(){

for(ss=0;ss<60;ss++){
itoa(ss,val1,10);
Send_To("1", val1 ,"6");  
delay(1000);

if(ss == 10){
send_sms();
}
} 
}


void Send_To(char *line,char *message,char *pos){
String k = message;  
  Serial.write(0x02);      //STX
  Serial.print(">");      // Send position info
  Serial.print(pos);
  Serial.write(0x03);    //ETX
 
  Serial.write(0x02); 
  Serial.print(line);    // Send message to line
  Serial.print(k);       // message to send
  Serial.write(0x03);
}

void send_sms(){
sms.SendSMS("09071026556", "10 seconds elapse");

};

±-------------------------+
AWOL

SMS send is looped because the value of Seconds or ss in my code is stuck at 10 thats why it send message again and again…

Robin2…

I also done that before…
some thing like this
for(seconds=0;seconds<60;seconds++){
Serial.print(seconds);
}

if (seconds == 10){
Serial.print(“10 seconds elapse”);

}

the problem is when im trying to combine it with gsm shield…

the GSM/GPRS shield need 3sec delay before sending is done…
that’s why the loop stuck at 10 and send message again and again…

void Send_To(char *line,char *message,char *pos){
String k = message;  
  Serial.write(0x02);      //STX
  Serial.print(">");      // Send position info
  Serial.print(pos);
  Serial.write(0x03);    //ETX

  Serial.write(0x02); 
  Serial.print(line);    // Send message to line
  Serial.print(k);       // message to send
  Serial.write(0x03);
}

Why bother perfectly good string to a perfectly nasty String just to print it out?

Indentation needs more work.

Please use code tags.

AWOL…

sir that function works perfectly i guess that is fine…

the real problem is in the void loop…

is there any function to send a message while looping or counting from 0-60…

that is all i need sir to fix my problem…

hmmmmmmmm…

to simplify the problem… is it possible to run a two different loop at the same time??

for example:
for(a=0;a<10;a++){
Serial.print(a);
delay(1000);
}

for(b=0;b<10;b++){
Serial.print(b);
delay(1000);
}

the output is some thing like this:
loop a loop b
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

it loops at the same…

I hope you get my point sir…
thank you

What's the point of running two loops at the same time that produce the same output?

co'z i think this is the same like i want to do to fix my problem in my project sir..

it is same as looping a number from 0-60 while sending message.

assuming that the loop a is the loop for counting from 0-60 and the loop b is sending a message. co'z when you send a message you need to wait at least 3sec before it done..

Am I correct sir?

Forget delay, and have a look at the blink without delay example in the IDE.

RobinAnd000: Robin2.... I also done that before..

...snip....

the problem is when im trying to combine it with gsm shield..

the GSM/GPRS shield need 3sec delay before sending is done.. that's why the loop stuck at 10 and send message again and again..

It sounds to me that you need to separate the sending from the counting. You should change your timing to use the technique in the Blink Without Delay example sketch. That will allow you to continue your count "in the background" while the GSM thing does its stuff. The extended demo of BWoD in the first post in this Thread may give you the idea.

...R

to simplify the problem… is it possible to run a two different loop at the same time??

for example:

for(a=0;a<10;a++){

Serial.print(a);
delay(1000);
}

for(b=0;b<10;b++){
Serial.print(b);
delay(1000);
}

Those for loops are not running at the same time. They are running one after the other.

the GSM/GPRS shield need 3sec delay before sending is done…
that’s why the loop stuck at 10 and send message again and again…

It cannot simply be the 3 second delay during the message sending that is causing the for loop to stall at a value of 10. That would certainly mess up the timing if you use the delay() function but the for loop would then simply take longer to run and the timing would not be accurate.

You have not answered my earlier question about the value of seconds printed if you use a for loop with the send message function inside it. Does the for loop really stall at 10 ?

Using the BlinkWithoutDelay principle as suggested by others would get round the timing problem, at least within the limits of accuracy that the Arduino can provide without an external time reference.

Tnx for the suggestion sir.. but may i ask you one thing..

what is the meaning of this code? i cant really understand

if(currentMillis - previousMillis > interval) { previousMillis = currentMillis;

tnx guys

If the time in millseconds now, minus the time at some previous juncture is greater than a certain value, then perform some action.