AT+CUSD=1 command not working

Hi all,

I am from South Africa. I am trying to get airtime balance from my sim800l but the command does not return what I want to see. When I type the command in the serial monitor, it displays the balance, but from the code it just displays the command without the airtime balance in the serial monitor.

#include <SoftwareSerial.h>

SoftwareSerial sim800l(5, 4);

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

  Serial.print("Airtime balance: ");
  Serial.println("AT+CUSD=1,\"*100#\""); //Returns airtime balance
  updateSerial(); 
}

void loop() {

}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    sim800l.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(sim800l.available()) 
  {
    Serial.write(sim800l.read());//Forward what Software Serial received to Serial Port
  }
}

image

Please help!

The command needs to be sent to the sim800l over the software serial connection. When you enter the command from the monitor, the code does that as the software serial echoes the reading from hardware serial. Without the monitor input, the command needs to be sent directly from software serial in the code.

Add this line to setup()
sim800l.println("AT+CUSD=1,\"*100#\""); //Returns airtime balance

Move updateSerial() into loop() where it will be called repeatedly.

You can remove the delay(500) from updateSerial().

1 Like

Thank you so much. It worked.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.