Hi, I'm getting a problem with my code.
I'm using GSM to trigger/turn on Gear motor and then save to SD card but the GSM automatically turn off.
note: GSM is connected to Arduino 1
and Gear motor pins and SD card are connected to Arduino 2, so im using I2C to communicate with GSM.
if i tried SD or gear motor separate, they are both working fine just when i combined the two, i got GSM problem.
Here's the code for Gear Motor to turn on. no problem here.
int pwm=9;
int servobot=8;
int ldrbot=A4;
int ldrstate=0;
int old_ldrstate;Â
void Setup()
{
}
Void loop()
{
}
void receiveEvent(int howMany)
{
while(Wire.available() > 0)
 {
  char c = Wire.read();
  numbers[i++] = c;
  numbers[i]='\0';
 }
strcat(myBigArray, numbers);
  strcat(myBigArray, str);
  char letter;
if (SD.exists(myBigArray))
  {
   myFile = SD.open(myBigArray);
   if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
     ldrstate=digitalRead(ldrbot);
     ldrstate1=digitalRead(ldrbot1);
     letter =myFile.read();
     switch (letter) {
case 'A':
  digitalWrite(servobot,HIGH);
      analogWrite(pwm,255);
      while(x<3)
      {
       old_ldrstate=ldrstate;
       ldrstate=digitalRead(ldrbot);
       if(ldrstate==LOW && old_ldrstate==HIGH) x=x+1;
      }
      delay(2000);
      digitalWrite(servobot,LOW);
      analogWrite(pwm,0);
      Serial.print(" Success");
      break;
and the code for SD card that i would like to insert is this.
  switch (letter) {
case 'A':
myFile.close();
 myFile = SD.open("Claim/Cookies.txt", FILE_WRITE);  //Write .txt file in SD, done.
      if (myFile) {
       myFile.println("1");
       myFile.close();
      }
but when i combine Gear and SD codes, the GSM turn off.
here's the combine code i've made.
int pwm=9;
int servobot=8;
int ldrbot=A4;
int ldrstate=0;
int old_ldrstate;Â
void Setup()
{
}
Void loop()
{
}
void receiveEvent(int howMany)
{
while(Wire.available() > 0)
 {
  char c = Wire.read();
  numbers[i++] = c;
  numbers[i]='\0';
 }
strcat(myBigArray, numbers);
  strcat(myBigArray, str);
  char letter;
if (SD.exists(myBigArray))
  {
   myFile = SD.open(myBigArray);
   if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
     ldrstate=digitalRead(ldrbot);
     ldrstate1=digitalRead(ldrbot1);
     letter =myFile.read();
     switch (letter) {
case 'A':
  digitalWrite(servobot,HIGH);
      analogWrite(pwm,255);
      while(x<3)
      {
       old_ldrstate=ldrstate;
       ldrstate=digitalRead(ldrbot);
       if(ldrstate==LOW && old_ldrstate==HIGH) x=x+1;
      }
      delay(2000);
      digitalWrite(servobot,LOW);
      analogWrite(pwm,0);
// i just insert here the code of SD card so that when Gear motor is turn low, it will write to SD card.
myFile.close();
 myFile = SD.open("Claim/Cookies.txt", FILE_WRITE);  //Write .txt file in SD, done.
      if (myFile) {
       myFile.println("1");
       myFile.close();
      }
      Serial.print(" Success");
      break;