Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Programmable Wireless: Adafruit FONA 3G Machine to Machine Commands Quickstart

The easiest and quickest way to get started with Programmable Wireless connectivity for your IoT (Internet of Things) devices is to use Machine to Machine commands.

With the simple steps in this Quickstart, we will show you how you can send and receive text-based commands using the FONA 3G development board.

While most of your code will be transferable, new product development for 2G in the United States is not a good choice. 2G networks in the United States are being deprecated. For new product development, we suggest researching alternatives or discussing your idea with the Twilio Programmable Wireless team.

In this Quickstart, you'll learn how to:

  1. Sign up for a Twilio account.
  2. Purchase your first SIM cards for Twilio Programmable Wireless.
  3. Insert your SIM card into the Adafruit FONA 3G development board.
  4. Power, connect and flash the board.
  5. Send a Machine to Machine command from the Adafruit FONA 3G and read it in the Wireless Console.
  6. Receive a Machine to Machine command on the Adafruit FONA 3G.

Not the quickstart you were looking for today? See our other Programmable Wireless quickstarts or see all Wireless resources.

I've gathered the hardware - now I need to get my SIMs!

Already have a Twilio account and a SIM card? Skip ahead to the register and activate step by clicking the button at the end of this section.

Before you can connect with Twilio Programmable Wireless, you'll need a Twilio Account and a SIM card.

After you have signed up, then purchase a set of 3 starter SIMs:

  1. Open the Console and from the Programmable Wireless menu, click Orders.
  2. On the Order SIM Cards page, enter your details (Order Details, Delivery Address, and Payment method), and then submit your order.

Orders of 10+ SIMs will be delivered with the SIM cards already registered to your account.

Order SIM Cards from Twilio

Detailed information about ordering SIMs is available here.

I've got my SIMs! How do I register and activate a SIM?

Register, choose a rate plan, and activate the SIM

Once you receive your SIM shipment, pick a favorite and unpack it.

Register and give a unique name for the SIM

In the Console, open the Register a SIM page in the SIMs section of the Programmable Wireless menu and enter the registration code as instructed:

SIM Card Registration Code

Next, pick a distinct Unique Name for this SIM.

Choose a Rate Plan

Select a Rate Plan from the options provided by Twilio.

We have created data metering quotas that are optimized for both high and low usage devices. You can use our data usage estimator to find the right Quota for you. Rate Plans also let you control every aspect of what your device can do with data, voice, and messaging.

For this quickstart, you can choose a low volume plan but ensure the plan you choose includes messaging.

Activate your SIM card

When you're happy with the name and plan, Activate the SIM card.

Detailed information about registering and activating SIMs is available here.

I'm active! Let's plug things in and get ready to connect.

Getting ready to connect to the network

For the quickstart, we will use an Arduino UNO to communicate with the FONA 3G. In the next steps, we will demonstrate how to prepare the device for cellular connectivity.


We need to solder pin headers to the FONA 3G board. The Adafruit website covers this step of the project within their FONA tutorial.


Wire up the Arduino

After soldering the FONA 3G header pins, place the board on a breadboard. Using hook-up wires, connect the pins noted below to the Arduino UNO.

3G FONA ----- Arduino UNO
5V ------------ 5v
GND ---------- GND
KEY ----------- GND
RST ----------- 4
TX ------------ 3
RX ------------ 2


Insert the SIM Card

Punch out the large form factor of the Twilio SIM from the card and insert into the SIM slot. Note the SIM orientation in the image below.


Attach the LTE antenna

Carefully attach the antenna to the FONA 3G like in the image below.


Insert the Lipoly Battery

Plug the Lipoly Battery into JST connector. For the best chances of connectivity keep the battery attached during use.


Plug in the Micro-USB cable

Connect the Adafruit FONA 3G to a computer using a Micro-USB cable.


The hardware setup will look similar to the image below.


Configure the Arduino IDE to work with the Adafruit FONA 3G

Install the Adafruit FONA library

  1. Download the Adafruit FONA library by Adafruit.
  2. In the Arduino IDE add the .ZIP to the Library folder by going to Sketch > Include Library > Add .ZIP Library.


Install the Adafruit FONA board cores

Add board manager URL

  1. In the Arduino IDE, select File > Preferences.
  2. Find the field Additional Boards Manager URLs and paste the following URL, then click OK:


Install the Arduino AVR Boards package

  1. From the Tools menu, select Board > Board Manager.
  2. Search for the Adafruit AVR Boards package and install the latest version of the package.
  3. Restart the Arduino IDE.


Whew, that was a rush. Let's program the Adafruit FONA 3G.

Connect and Program the Adafruit FONA 3G

You can download the code directly from this directory on Github.

  • Load the file m2m_command_fona3g.ino into the Arduino IDE. Alternately, you can copy/paste the code into a new Arduino sketch using File > New Sketch.

Power the FONA 3G and select the Arduino UNO

  1. Power the Adafruit FONA 3G by connecting it to the computer using a Micro-USB cable.
  2. Select your board and the serial port it enumerates from Tools > Board > Arduino UNO in the Arduino IDE.


Upload the code to the board

You have a choice:

  • One way is to use the Upload button on the toolbar
  • Another is to select Upload from the Sketch Menu.

After uploading the code, open the Serial Monitor from the Tools menu.

And that's all you need to do on the Arduino side! Watch the monitor and you should see the modem come online:


If you don't see the above, make sure the power is connected and you have set the speed set to 115200 baud. Power cycle or hit the reset button on the Adafruit board to have it spin through again.

Let's look at how the message was sent in the next section and to send a response from our computer.

How did you send the M2M command?

Send a Machine to Machine Command from an Adafruit FONA 3G

We've included a very small helper library to assist with sending M2M commands. Here's the method to send a machine to machine command:

        Sending an M2M Command with the Adafruit FONA 3G using the helper functions provided.

        Send a Machine to Machine Command from an Adafruit FONA 3G

        Sending an M2M Command with the Adafruit FONA 3G using the helper functions provided.

        Behind the scenes, we send an SMS to the shortcode 2936. The Serial Monitor will print the following message when the Command is successful from the FONA 3G.


        Verify the Machine to Machine Command was sent

        The easiest way to check if the command was successful is through the Programmable Wireless Console.

        1. Within the Console, select SIMs from the Programmable Wireless menu.
        2. Click the SIM we are using for this project, then navigate to the Commands tab.
        3. Copy the SIM Sid.


        As you might guess, we will implement the reverse - you'll receive an inbound SMS from 2936 on the FONA 3G triggered by an API call using the SIM's Sid. Let's look at that next.

        Cool, show me how to receive a M2M command.

        Receive a Machine to Machine Command on the Adafruit FONA 3G

        Sending (or in this case, manually responding to) a Machine to Machine command is very straightforward from your development machine.

        Send a command to the SIM

        The fastest way to respond to a command is to use cURL. Send a command (under 160 ASCII characters) back to the SIM using cURL:


        Otherwise, commands can be sent from our helper library:


              Receive the Command on the Adafruit FONA 3G

              Again, we've included code to help you receive the M2M command easily.

                    Receive a M2M command by searching for the 2936 short code in incoming SMS messages to the Adafruit FONA 3G.

                    Receive a Machine to Machine Command on the Adafruit FONA 3G

                    Receive a M2M command by searching for the 2936 short code in incoming SMS messages to the Adafruit FONA 3G.

                    Return to the Arduino IDE and test it out.

                    Reset or power cycle the Adafruit FONA 3G, open the Serial Monitor, and you should see...



                    ... magic!

                    And that's all there is to Machine to Machine commands. You now know how to send Commands from an Adafruit FONA 3G and check their status in the console. You can also return a message from your machine and have seen how to receive it.

                    With those basic building blocks, you're ready to build the next big IoT Thing!

                    What's Next?

                    Now that you have seen how to send and receive Machine to Machine commands on both your Adafruit FONA 3G and development machine, you're ready for your custom application. Here are some possible ideas to take it to the next level:

                    Rate this page:

                    Need some help?

                    We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.