The Vodafone K3770 and K3772-Z modems allow you to connect your mbed to the internet from (almost) any location in the world.

The K3770/K3772-Z modems can be purchased directly from :

Many supermarkets and independent phone stores also sell these modems.

Hardware Setup

mbed Vodafone K3770/media/uploads/chris/vf-schematic.jpg

Because of the high current that the USB dongle requires, it is not possible to power it from the Vu pin on the mbed. In the example show, an external linear regulator board has been used to provide a high current regulated 5v supply from a 9v wall adaptor. The parts shown are :

Hello World

This example application uses the VodafoneUSBModem and the HTTPClient interface, enabling the mbed to fetch a URL over HTTP, and print the contents.

There are various other "hello world" programs that demonstrate SMS, NTP, Socket and Websocket interfaces, as well as management commands (check balance, link status, etc). See "Resources" section below.

You'll notice that this "Hello World" program is a little more complex that others, as we're using the mbed RTOS to manage the memory and processing resources/requirement of the USB Modem driver and the TCP/IP stack.

Import program

#include "mbed.h"
#include "VodafoneUSBModem.h"
#include "HTTPClient.h"

void test(void const*) 
    VodafoneUSBModem modem;
    HTTPClient http;
    char str[512];
    int ret = modem.connect("pp.vodafone.co.uk");
      printf("Could not connect\n");
    //GET data
    printf("Trying to fetch page...\n");
    ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
    if (!ret)
      printf("Page fetched successfully - read %d characters\n", strlen(str));
      printf("Result: %s\n", str);
      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
    //POST data
    HTTPMap map;
    HTTPText text(str, 512);
    map.put("Hello", "World");
    map.put("test", "1234");
    printf("Trying to post data...\n");
    ret = http.post("http://httpbin.org/post", map, &text);
    if (!ret)
      printf("Executed POST successfully - read %d characters\n", strlen(str));
      printf("Result: %s\n", str);
      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());

    while(1) {

int main()
  Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
  DigitalOut led(LED1);

  return 0;


Import library

Public Member Functions

  VodafoneUSBModem (PinName powerGatingPin=NC, bool powerGatingOnWhenPinHigh=true)
  Create Vodafone USB Modem (K3770/K3772-Z) dongle API instance.
int  connect (const char *apn=NULL, const char *user=NULL, const char *password=NULL)
  Open a 3G internet connection.
int  disconnect ()
  Close the internet connection.
int  sendSM (const char *number, const char *message)
  Send a SM.
int  getSM (char *number, char *message, size_t maxLength)
  Receive a SM.
int  getSMCount (size_t *pCount)
  Get the number of SMs in the incoming box.
int  sendUSSD (const char *command, char *result, size_t maxLength)
  Send a USSD command & wait for its result.
int  getLinkState (int *pRssi, LinkMonitor::REGISTRATION_STATE *pRegistrationState, LinkMonitor::BEARER *pBearer)
  Get link state.
ATCommandsInterface getATCommandsInterface ()
  Get the ATCommandsInterface instance.
int  power (bool enable)
  Switch power on or off In order to use this function, a pin name must have been entered in the constructor.
char *  getIPAddress ()
  Get the IP address of a connected device.

Protected Member Functions

int  init ()
  Initialise dongle.
int  cleanup ()
  De-initialise dongle.

Resources and references

Network APN

To connect to the internet you must establish a PPP connection. You can then use BSD Sockets or any high-level component (HTTP Client, NTP Client).

To establish this connection, one single function is used:

int ret = modem.connect("pp.vodafone.co.uk");

pp.vodafone.co.uk is the APN value for a Vodafone Pay as you Go SIM. Change it to the relevant value if your SIM is different:

SIM TypeContract TypePlanAPNUserPassword
Mobile BroadbandPay as you go£5 for 250MB, lasting up to 30 dayssmartwebweb
Mobile BroadbandPay as you go£15 for 2GB, lasting up to 30 daysppbundle.internetwebweb
Mobile BroadbandPay as you go£15 for 1GB, lasting up to 90 dayspp.internetwebweb
Mobile BroadbandPay monthlyAnyinternetwebweb
PhonePay as you goAnypp.vodafone.co.ukwebweb
PhonePay monthlyAnyinternetwebweb

For details please check Vodafone's dedicated page.

The variable, "ret", allows you to check whether the connection was successful or not (0 on success, a negative value on error).

Please note that the "connect" command can take a few minutes to complete in worst case scenarios, as it initializes the modem and then waits for network registration.

Other Examples

Import programVodafoneUSBModemNTPClientTest

NTP Client Test with the Vodafone USB Modem library

Click here to the programs that are using the NTPClient

Import programVodafoneUSBModemSMSTest

SMS test with the Vodafone library

Import programVodafoneUSBModemWebsocketTest

Websocket client test with Vodafone USB Modems

Click here to the programs that are using the WebsocketClient

Import programVodafoneUSBModemUSSDTest

Test of USSD commands transmission over the Vodafone network with the Vodafone library

2 related questions:


01 Nov 2012

How do I buy a k3772-z from Vodafone? The dedicated page gives an error. I tried ordering one from Vodafone directly, but they decided to ship me an R205 instead (after confirming my k3772-z order). Any contact at Vodafone who can help me receive a k3772-z if I order one?

01 Nov 2012

OK, that's pretty odd, since the R205 is a wifi hotspot device. What did they say when you told them this?

02 Nov 2012

Ashley Mills wrote:

OK, that's pretty odd, since the R205 is a wifi hotspot device. What did they say when you told them this?

It was pretty odd! They said nothing when I returned it - it went back in the post with an explanation and a copy of the order confirmation (showing the k3772-z). This was the middle of October. I have not heard anything back from them.

08 Nov 2012

Is it possible to use a prepaid contract (Vodafone Web Sessions) with this Lib? As Vodafone descripes the first HTTP-request is rerouted to their Site and then I have to choose between 15minutes, 24h, 1week... first.

25 Nov 2012

The easiest way for experiments is to buy the dongle and get a prepaid pay as you talk "phone" SIM , not a Vodafone Mobile Broadband data SIM .... Vodafone Data SIMs can not send SMS messages , due to marketing reasons . Have a look at the forum http://mbed.org/forum/mbed/topic/3596/?page=2#comment-18628


26 Nov 2012

Is it possible to use this without an RTOS, using a polling system?

When I read about LWIP it appeared to support polling but it looked as if the MBED version had had the ability removed?

24 Jan 2013

Does this library support K3771. Thank you

24 Apr 2013

The sketch of the USB connection (inc. 15k resistors) is misleading as D+ is next to GND, D- next to 5V.

19 Jul 2013

Along with my team, we managed to use the vodafone K3770 to work in the UK with an o2 sim card. All you need to do is unlock the modem. Instructions for unlocking the modem can be found here http://modemunlock4u.blogspot.co.uk/2013/01/unlock-vodafone-huawei-modem-k3770.html.

Next, you need to change the apn you are using to the mobile provider that you are using e.g. for o2 it is mobile.o2.co.uk. And this will work.

We've also got it to work in Rwanda with an MTN sim card, therefore in theory it should work in most countries.

The best place to buy the modems is through ebay, I've found some for £10. And also make sure it is the K3770 because the K3772-z did not work for me.

23 Mar 2014

Tried the "Hello World" and SMS programs. Both give the same error Error: Identifier "ip_input" is undefined in "VodafoneUSBModem/lwip/api/tcpip.c", Line: 107, Col: 9 any suggestions ? thx !!