Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:09:32+00:00 2026-06-02T21:09:32+00:00

How do I capture the output from an AT command on an Arduino? I’m

  • 0

How do I capture the output from an AT command on an Arduino?

I’m using the Arduino Uno R3 with a GSM shield. I have all the AT commands (they can be seen here ) and I can enter them just fine if I use the terminal and get output. However how can I capture the resulting output via code? The code below shows what I’ve tried but it does not work. In particular where I attempt to get the analog input and then print out the result.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

void setup()
{
  char sensorValue[32] ="";
  Serial.begin(9600); 
  mySerial.begin(9600); 
  Serial.println("\r");

  //Wait for a second while the modem sends an "OK"
  delay(1000);                    

  //Because we want to send the SMS in text mode
  Serial.println("AT+CMGF=1\r");    
  delay(1000);

  mySerial.println("AT+CADC?");     //Query the analog input for data
  Serial.println(Serial.available());    
  Serial.println(Serial.read());    //Print out result???

  //Start accepting the text for the message
  //to be sent to the number specified.
  //Replace this number with the target mobile number.
  Serial.println("AT+CMGS=\"+MSISDN\"\r");    


  delay(1000);
  Serial.println("!");   //The text for the message
  delay(1000);
  Serial.write(26);  //Equivalent to sending Ctrl+Z 
}

void loop()
{
  /*
    if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());  
    */
}

I get the outputs:

AT+CMGF=1

AT+CADC? 21 13

or

AT+CMGF=1

AT+CADC? 18 65

Regardless of changes in my analog source

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:09:35+00:00Added an answer on June 2, 2026 at 9:09 pm

    Take a look at the documentation of the SoftwareSerial read function here.

    When you read from the GSM device serial interface, you cannot take for granted that there are bytes to be read on the buffer.

    It’s very likely that mySerial.read() returns -1 (no bytes available), as Arduino runs that code before the GSM device can provide something on the serial port.

    You should use the available function (documentation here) to test the serial interface for incoming bytes. You could use it with a timeout to avoid infinite waiting.

    The best thing you could try is to write a separate class to handle serial operations (read, write, timeouts, delays, etc).

    Also, I wrote a GPRS driver for Arduino once.
    I had a problem with the power supply that required me to install an extra capacitor on the GPRS device and use a power supply with more than 2A of output current.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python2.4 I want to capture output from a mysql command. One caveat is
I am using a thread to capture stream output from a process, and then
I have no idea why this is hanging. I'm trying to capture output from
Is it possible to capture output from wget and other command line programs that
I have a plain perl script that can be run from the command-line via
How can I execute an external command and capture its output in Perl6? Perl5-style
I'm trying to run curl as a process and capture the output from the
Basically, this question with a difference... Is it possible to capture print output from
Hello guys i need to capture the output of an external command, herefore I
I want to do this: run a command capture the output select a line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.