0

what i'm trying to do is to send message to one whose no. is used in code about balance of sim_card plugged in sim900a. but i get commands in message or blank message after using ATE0.

what i was thinking is, a kind of response to the commands would be generated in the gsm module which in turn be extracted by me by "String balance=readString();" command then will use it as message context to send to next person.

but this is something i'm having difficulty in accomplishing or there is something i'm probably unaware of. any help would be greatly appreciated...thanks...

#include<SoftwareSerial.h>
SoftwareSerial gsm(2,3);

String n="+921234567899";

void setup()
{
  gsm.begin(9600);
  Serial.begin(9600);
  //
  gsm.println("AT"); resp();
  gsm.println("AT+CMGF=1"); resp();
  gsm.println("AT+CUSD=1"); resp();
  gsm.println("AT+CUSD=1,\"*111#\"\r"); resp();
  String balance=gsm.readString();
  //
  gsm.println("AT"); resp();
  gsm.println("AT+CMGF=1"); resp();
  gsm.println("AT+CMGS=\""+n+"\"r"); resp();
  gsm.println(balance); resp();
  gsm.println((char)26);  
}

void loop()
{
  resp();
}

//////
void resp()
{
  delay(500);
  while(Serial.available())
  gsm.write(Serial.read());
  //
  while(gsm.available())
  Serial.write(gsm.read());
  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.