[SMS] Sony Ericsson PDU


For nothing have I had more requests than this piece of code. It’s use is obvious; forcing a turned on Sony Ericsson that supports a real serial interface to send a sms, receive, read, call etc. The hardest part in this is sending an SMS through real serial with f.e. an Arduino using this Sony Ericsson cellphone. This is because the info within the sms has to be coded in PDU. All other stuff you can just write, but the info has to be coded in a crappy fashion. Sadly, i lost most of the bookmarks i had on this.

Hooking it up

Datacable pins

Pin 4 RX (connect to your TX)
Pin 5 TX (connect to your RX)
Pin 10 GND
Pin 11 Vcc (3V)

Also, the phone wants 3V. You can give it 5V, but it doesnt like that a lot, so just either tune it down to 3V (pot. divider?) or just put a resistor in there in series so that the current stays low.

You are going to need a Data Cable just get it for $2. I got 2 for $3 on eBay, they worked fine. With mine, some chips were in the USB exit, this was great because i could just cut the cable and use the correct pins using the above linked pinout!

Also get The Phone, i have two t68i’s, i got one for $5 on eBay, another for $7. I actually say someone selling 5 for €15 on ebay once, but eh, yeah.

Also, this link here tells you the this and that about PDU coding.

Now the implementation in your Arduino sketch would be as described in the bottom of this page.

Reading Textmessages

Try this:

Other useful commands for reading textmessages:

AT command Meaning
+CNMA New msg acknowledgement
+CNMI New message id
+CMGL List msgs
+CMGR Read msg


Dont forget to turn off your phone’s pincode and request for pincode. Also, this code works fine when the phone is ‘keyboard-locked’

Please notify me or comment here if you use the code. Any flaws of this code can be posted in the comment below. The code is intended for personal use. Don’t forget to either comment on the code, or donate me a cup of coffee for writing this!

  1. /*
  2. /*
  3.     Copyright (C) 2010  Daniel Richman (/Timbobel)
  5.     This program is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     GNU General Public License for more details.
  15.     For a full copy of the GNU General Public License,
  16.     see .
  17. */
  19. /* From hexdump.h ALIEN Project Daniel Richman */
  20. #define num_to_char(number)   ((number) < 10 ?
  21.                                                ('0' + (number)) :
  22.                                                (('A' - 10) + (number)) )
  24. /* To select the 4 bits we do this */
  25. #define first_four(byte)       (0x0F & (byte))
  27. /* Last four: Shift left to get to a number &lt; 16 */ #define  last_four(byte)      ((0xF0 & (byte)) >> 4)
  29. /* The MSB goes first. */
  30. #define hexdump_a(byte)  num_to_char( last_four(byte))
  31. #define hexdump_b(byte)  num_to_char(first_four(byte))
  32. /*
  33.  */
  35. int timesToSend = 1;        // Numbers of SMS to send
  36. int count = 0;
  38. //next is just the setup; he loops that once.
  39. void setup(){
  40. //Hook up your phone to the serial connection (Rx to Tx and Tx to Rx). If you dont have a
  41. //serial connetion free, just use a library like "nss"(newsoftwareserial) which is good.
  43.   Serial.begin(9600);               // the GPRS baud rate
  45. }
  47. //then next is the loop. timesToSend=1 so it sends an textmessage only once with the information "hello world"
  49. void loop(){
  51.   while (count < timesToSend){
  52.     send_sms("Hello World");
  54.     count++;
  55.   }
  56. }
  58. void hexdump_byte(unsigned char byte)
  59. {
  60.   Serial.print(hexdump_a(byte), BYTE);
  61.   Serial.print(hexdump_b(byte), BYTE);
  62. }
  64. void send_sms(char *data)
  65. {
  66.   size_t data_length, x;
  67.   char c, l;
  68.   long i;
  69.   long n;
  71.   data_length = strlen(data);
  72.   i = data_length * 7;
  74.   /* Round i up to a multiple of 8 */
  75.   if (i & 0x07) i = (i & ~0x07) + 0x08;
  77.   /* Calculate the number of message octets */
  78.   i = i / 8;
  80. //Select operating mode for sms: PDU, since it doesnt understand anything else
  81.   Serial.println("AT+CMGF=0");
  82.   delay(1500);
  83. //Now we say "AT+CMGS=..." that gives it the cellphone number.
  84. //This is also in weirdass PDU format, so i am sending a message to myself at "0031-653587738"
  85. // which was the destination phone nr.  Serial.print("AT+CMGS=");
  86.   delay(1500);
  87.   Serial.println(i + 14);
  88.   delay(1500);
  89. //This is actually the number. If you want to use your own number you just have to figure out where to put your digits.
  90. //Mine was "31653587738" Because this is an uneven amount of numbers, there is an F included before the last 8.
  91. //If you check it out you probably figure it out: you have to make your phonenumber so that they're
  92. //switched in pairs of two, so like if your number is "123456789" it will become "21436587F9"
  93. //And if its "123456" it will be "214365". I know, it's weird and ancient.
  94. //that's why im posting this code.
  95.   Serial.print("0011000B911356537837F80000AA"); //1356537837F8 is the phonenr
  96.   hexdump_byte(data_length & 0xFF);
  98.   l = 0;
  99.   n = 0;
  101. //The rest of the code then is just about changing our serial info "Hello World" into neat PDU HEX format.
  102.   for (x = 0; x < data_length; x++)
  103.   {
  104.     if (data[x] == '$')  data[x] = 0x02;
  106.     n |= (data[x] & 0x7F) << l;
  107.     l += 7;
  109.     if (l >= 8)
  110.     {
  111.       hexdump_byte(n & 0xFF);
  112.       l -= 8;
  113.       n >>= 8;
  114.     }
  115.   }
  117.   if (l != 0)
  118.   {
  119.     hexdump_byte(n & 0xFF);
  120.   }
  122.   Serial.println(0x1A, BYTE);
  123. }
  124. }

Previous usage setup


On request you can download the above into a textfile:
Download: code.txt

Tim Zaman

MSc Biorobotics. Specialization in computer vision and deep learning. Works at NVIDIA.

You may also like...

79 Responses

  1. Marius says:

    Hello great post! I have some question :
    – the code posted converts all the text to pdu format before sending it?
    – in order to use this daily on a se k700i should I use 1k resistors to all wires connected to arduino uno? I don’t want to fry the phone nor the ardunio uno!
    – Can I send IR commands from arduino using k700i built in infrared?
    Thanks a lot

  2. kamezian says:

    Hi Tim,
    you did a great job, did you develop same function for SMS read (decode PDU)?


  3. ico says:

    will the phone charge it self when you connect it your selfe or do you need to do something else?

  4. saleh says:

    i have sonyericsson K700 and I want to connect with a remote control arduino via sms. Data pin out is the same as the T68i

    the system works like this:
    on when the sensor arduino digital pin 4 high arduino send SMS to the number specified by the content of status sms “pin 3 lives”
    and then we send sms to arduino to the content “turn on pin 5″ the arduino pin 5 on the condition of high,
    if the condition pin 5 already is high and arduino send back sms with the content “pin 5 high”.
    as well as the turn off.
    we send sms to arduino to the content “turn off pin 5″ the arduino pin 5 on the condition of low,
    if the condition pin 5 already is low and arduino send back sms with the content “pin 5 low”.

    This project will use my own and I will send a little donation to your. you can contact me via email. please help me .thank you very much

  5. Paolo says:

    Hello Tim, thanks a lot for the code and explanation, but I have a simple question:
    Your phone number (3165687738) have the international phone code (+3165687738) or not (+xx3165687738)?
    Xcuseme for orrible english.
    Thank you

  6. Arsene Daniel says:

    Hi Tim,
    i do the same thing with SonyErricson T230, but i guess i need level shifter since phone comunicate with 3v3 and Arduino with 5v. I send AT commands with USB to serial using well-known PL2303, but i can’t send AT commands with Arduino. Any suggestion? Thank you!

  7. Francisco says:

    Hello Tim.
    Thanks for your post, but I have a question.
    I have a Sony Ericsson T290 and I connect the pin 4 (RX with TX), pin 5 (TX with RX), pin 10 (GND) and pin 11 (3V). The development card is a chipKit Max32 with 3 port for communication, and I use the first port.
    I don’t know if I need a RS232 interface or just connect directly.
    Sorry for my english, I hope you understand me.

  8. Bob says:

    So i.e if my 8digit hp number is 12345678 i won’t need to add an F into it right ? so will be 21436587, changed the number ad detached but still the same. Anyway i knew it did not work because the t68i is not reacting to the AT command sended and to double confirm i check the sent msg folder in the t68i, there is no sended msg.

    Was wondering if i need initialize the pin of the TX and RX ? and did you used newsoftwareserial while doing this ? I am also curious which TX RX pin you used on the Arduino mega 1280.

    Still trying to find out what has gone wrong . Would be glad if you could point it out.

  9. Bob says:

    Hi Tim, sorry trouble you again, i got everything connected up as per your instruction on Arduino 0020 with no error. I am using Arduino mega 1280 and T68I. But no sms nor anything is happening at the phone beside the phone is charging by itself upon connection to the board. What could be the problem ? Please kindly help out thank you.

    SERIAL monitoring

    Before Connected handphone

    After connected to handphone

    • Tim Zaman says:

      How can you know that it doesnt work? Because i get frequent textmessages by people using this code, but not changing the cellphone number in there, because now it still include smy number as i see your code.
      Also, you can’t monitor the code with the serial monitor, you have to fully detach that or it will interfere. you can only use a logic analyzer to see what its doing. For the rest, i guess it should work then! put you have to change the cellphonenumber in there. ” 1356537837F8 ” is actually my number; 3165687738. That F is in there, i believe, because my cellphonenumber has an uneven amount of digits

  10. Bob says:

    Hi tim may i know what complier your are using ?

    I get the error “As of Arduino 1.0, the ‘BYTE’ keyword is no longer supported.Please use Serial.write() instead.”

    • Tim says:

      Anything from Arduino IDE v16 to v21 (current i believe) should work. Not sure ir byte is neccessey anyway

  11. ila says:

    HI, TIM.can i use pinguino that have board and pic 18f4450 to sending sms?what part and component i have to add?

    • Tim says:

      Ehh yeah ofcourse that will work. Anything that can talk through serial can send an sms with the above c++ code.

    • ila says:

      Hi Tim, tanks….can i use only pic 18f4550 and sk 40c board to send a sms without using arduino board?plez reply me…any suggestion if i want to use pic 18f4550 and sk 40 for related to sms part?

  12. ila says:

    HI, TIM….i want to know if your sending part is work or not?can i get the coding please?gps 1@2 is compulsory or not ?hope you are reply my question as soon as possible because i have to complete my final project before end of this year.tanks so much..

  13. wilson says:

    hi tim. i’m just wondering whether Microchip PIC18F4550 can replace the arduino board to trigger a sms?

  14. tazma says:

    hello sorry if I question
    not suitable
    here is to send sms?
    send_sms (“testabcABC123.,-00testabYES”);

    and here phone number?
    Serial.print (“0011000B911356537837F80000AA”);

    I am newbie

    • Tim says:

      yes it works like that if you use thw above function as it says. BUT if you are a newbie, please ecperiment witj arduino ans sensors ans serial first!

    • tazma says:

      hello sorry but I do not understand
      you mean well

      the question I want to know
      is the phone number
      is this place and if it makes
      Is an invented nuemero 0034-7773399

      • Tim Zaman says:

        0011000B911356537837F80000AA = 31653587738
        0011000B9143773793F90000AA = 347773399 (=0034-7773399)
        its fairly obvious

      • tazma says:

        hello a question
        but, what software you use
        conversion of
        phone number
        that I do not understand

        that part

      • Tim says:

        it’s logic. i told you, you have to put it in PDU format, and you have to know how that works in order to convert the phone number. Please, if you’re new to electronics and programming, you’re better off starting with more basic projects, before you dive into this one 🙂

    • Owen says:

      .,hello..i have read your post but can you tell me how to interface it with an analog input like a sensor?..I want that when the arduino receive an input from a sensor (Sharp IR sensor) connected to the arduino then sends the value via the sony ericsson phone to another phone?..im practically using it as a data logger which sends the data detected through sms..is it possible?…here is my code for the sensor..

      int IRpin = 1; // analog pin for reading the IR sensor
      void setup() {
      Serial.begin(9600); // start the serial port
      void loop() {
      float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) – if running 3.3.volts then change 5 to 3.3
      float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S – luckylarry.co.uk
      Serial.println(distance); // print the distance
      delay(100); // arbitary wait time.

    • Wilson says:

      Hi would like to confirm with you the board you are using is Arduino Mega 2560 ?

  15. Vinicius says:

    Hi, someone knows if is possible connect a cellphone with USB directly in Arduino, like this article? I tested with hyperterminal and the AT commands are OK with my cellphone. Thak you

  16. Jon Telling says:

    Thanks for your reply, Can I ask another question?
    What was the value of the resistors you used between the T68 and the arduino serial pins?

    • Tim says:

      Well.. 5V is actually too much for the phone. I believe ideally it wants something like 3V. Though, if you are not using it for weeks on end straight, 5V wont kill it. To be even more sure of that, i put some resistors in between that make sure some load is taken of the phone. Not sure if that’s really helpinh though, but still, i’m never out of spare resistors.

      • Jon Telling says:

        I think all knock up a voltage divider, I’ll just have to check the extra load that create, hummm I think there’s a few chips out there that are for this sort of low mA conversion, I’ll double check.

        My setup will communicate with the phone maybe every 15min for few seconds…

        Has anyone tried the above library that turns a digital pin into a serial output? Maybe this can be used but on the PWM ports. 😀

      • Jon Telling says:

        Or maybe a Zener diode or two ;P

      • Tim says:

        The library you are referring to is either “SoftwareSerial” or better, “NewSoftwareSerial” (or NSS). The latter is a lot better, it uses interrupts. Though, if you use this library you can’t use the modern servo library anymore.
        NSS is very easy to use, very reliable up to 4800 baud in my experience. But generally you don’t really need it. Otherwise, try using a Arduino Mega.

    • Tim says:

      1K ohm is good by the way. Try to keep it as simple as possible, dont use circuits if not neccesary. especially with prototyping!

      • Jon Telling says:

        I’m at work at the moment and so can’t test this directly, but do you know what the drain is on the T68 on the serial pins? That way a “perfect” resistor can be selected”.

  17. sam says:


    love your tut here it pritty cool 🙂

    umm just asking if there is away of coding this so when i send a text message to the sony phone it notifies the ardunio and the ardunio runs a function etc

    Thanks alot 😀

    • Tim says:

      Well.. 5V is actually too much for the phone. I believe ideally it wants something like 3V. Though, if you are not using it for weeks on end straight, 5V wont kill it. To be even more sure of that, i put some resistors in between that make sure some load is taken of the phone. Not sure if that’s really helpinh though, but still, i’m never out of spare resistors.

  18. Jon Telling says:

    As the T68 has a real serial connection does this mean it can be directly connected to a PC just like the arduino? I ask as all the cables I’ve seen have a interface chip.
    I’ve not tried it yet, but will…… wish me luck?

    PS if the RX is connected can SMS be read from the T68 (with the correct code)?

    • Jon Telling says:

      I’ve found out why they have the chips, the voltage! RS232 can output 12V and will a mobile input!!


    • Tim says:

      Indeed you can directly connect it. SMS can be read, yes, but its difficult with arduino. with the PC its a lot easier as there is good software that handles all the commands =)

  19. Bagas says:

    i got PDU encoder ->
    but still would not send sms,,

    i use arduino mega 2560,
    black cable in GND pin
    red cable in 13 pin
    green cable in rx0 pin / 0 pin
    white cabla in tx0 pin / 1 pin
    is that true?

    • Tim says:

      i don’t think you need the red cable for anything. i do recommend that you use softwareserial; the NewSoftwareSerial “nss” library for arduino; then, you hook the rx and tx of the phone up to for instance pins 2 and 3 on the arduino. that should make things less prone to errors. then run the code. and try calling first through your arduino; just send a ATD command. if that works, the rest’ll work too!

  20. Bagas says:

    Hi Tim,,
    I’m using K800i, i have try using hyperterminal to write ATcommand and it’s work.
    so, i think, my phone don’t have problem..

    actualy i don’t realy understand about C++,
    i copy all script from txt file to arduino software, and there is so much error when i click verify button.

    some erros is in line :
    while (count < timesToSend){

    #define num_to_char(number) ((number) < 10 ?
    (‘0’ + (number)) :
    ((‘A’ – 10) + (number)) )

    #define first_four(byte) (0x0F & (byte))

    please help me to fix it..

    • Tim says:

      That’s because of wordpress, it doesnt display the code properly. That is exactly why you can just download the code in the link at the bottom of the post =)

      • Bagas says:

        thank you very much for your suggestion..
        may i ask again,,
        what number this bold font : 0011000B911356537837F80000AA

      • Tim says:

        The bold part you can ignore, just some standard settings. If you want an answer you really have to dive into C++ and PDU first. otherwise just ignore it. If you execute the code above, it will send a textmessage to me. I actually had quite a few textmessages from over the worls of people who are trying my code; with my cellphone nr still in their code 🙂

  21. john says:

    I am a boy from Romania and my problem is: I try to put your code on the Arduino and I connected with a Sony Ericsson T230 and it did not work, then I tried another Sony Ericsson T610 and just did not work! how do you make your code work with one of my phone? no bonding opportunity?

    • Tim says:

      Hi John. It depends on wether or not your phone actually handles PDU. It is possible that your phone can’t work with the arduino; some phones have a virtual serial interface, if that’s the case you can’t use it with arduino. Also, check out if you can get it working with HyperTerminal first (serial interface from your computer). If that doesn’t work you can stop right there; also this is a good way to check if your connections are good.


  22. Cristi says:

    please! give me a code in which there is, put yourself, RX and TX, because I’m so stupid and not know where to add it!

    • Tim says:

      The code is clear enough as it is. You have to learn programming [and english] before you can use it ;-). Then return with clear questions =D

  23. Cristi says:

    hello! I need the code! and tell me if it works with Sony Ericsson T230! Thanks!

  24. José Luis says:

    Hello Tim, I’José Luis from Spain. I’n trying to run this sketch for a Phone Siemens M55, but I have problems with some characters of the program like “<” etc. I’ll be very happy if you post a link to the code or if you send the sketch by e-mail. I want to make a remote control with arduino and a legacy phone.

    Thanks in advance.

    • Tim says:

      Sure, i’ve now made a download section in the bottom of this post including the code in a .txt file. Have fun

  25. Gilbert says:

    Hi Tim Zaman, job well done! Your wireless system saves a lot of money. I am really interested on this kind of project. I tried your setup also connecting the wires to my PIC16F877A but the phone seems cant communicate to my microcontroller. I tried everything first on hyperterminal and simulations and there’s no single problem. Any help on the hardware part?

    This is my setup:
    Blue wire – tx of PIC
    Black wire – gnd of PIC
    Red wire – 4v
    White – unused

    I tried swapping blue and white but still no luck. Any solution you can suggest?

  26. Tim G. says:

    I’d be happy to buy you plenty of coffee if you could please comment the code more so we can understand it’s operation more. Also, it seems as though this should be easy enough to reverse – having the Arduino receive messages as well. Have you attempted this?

    • Tim says:

      OK i’ve heavily commented the code now; you should understand clearly i think :).
      If you just want to call someone with this code (use other AT command) you don’t even need the PDU format. And even if you did need the PDU code for (for example reading textmessages) then you can just use this code. But i don’t think its difficult reading textmessages. And yes, i already managed to read textmessages using AT commands. But i don’t know how to know when a message has been received (just havent looked into that). I have some exams this week so i wont be posting any more code this week.

    • Tim says:

      Also, i have not been able to get acces to GPRS with the T68i, although i did succeed with another GPRS (Sagem/Hilo) module (shield).

  27. The Cageybee says:

    Hi again. I just tried to get the code working but have run into a couple of problems.

    The definition for last_four() is missing. Going from the comments I tried:
    #define last_four(byte) (byte << 4)
    but that didn't work.

    Also, at the end of line 65 there's a close bracket which has no corresponding open bracket. Should it be a semi-colon instead?

    The Cageybee

  28. The Cageybee says:

    A couple of Q’s.
    Firstly, could we have the code as a download if possible as code always seems to get a bit screwed up after it’s been through the html ringer. For instance, line 70. I didn’t know a smiley was valid arduino code. LOL. What’s that supposed to be anyway? Should it be:
    0 ;
    Also, where do I enter the phone number for the phone I want to send the sms to?
    One last thing, what’s the data on line 60? Confused!
    The Cageybee

  29. Claes Nordquist says:

    I shall give this a try this evening…and get back to you if i have something to share!
    -Thanks a bunch!

  30. Claes Nordquist says:

    Hi there!

    -I’m really interested to get my hands on the code that handles the encoding/decoding of PDU messages.

    Is it possible that you would share that to the public?

    • Marcus Weldeborn says:

      Oh, i am also very interested in that code. I have succeeded to send predefined messages for Arduino with a T610 connected, but to get encode/decode working would definitely be nicer.
      (I thought that T610 should have text mode, but i haven’t been able to use it.)

      The thing i am building is just for my own use, and i will not make any money on it. I can make a small donation for the code.

    • Tim Zaman says:

      send me an email

  31. varun says:


    Can you possibly put a circuit online. I am trying to do this but, haven’t found a circuit for this anywhere. Or do I just attach the GND and TX to the phone without anything in the middle?

    Thank you!

    • Tim Zaman says:

      That is correct. The phone runs ~3v though. But i have experienced in my lazyness that it accepts 5V serial as well, although i have occasionally just placed a 10kOhm resistor in between in series just to lower the power through the phone.

  32. Marcus says:

    Hi, nice work there.
    Im trying to make my arduino recieve and send SMS but with no success. I can send sms when connected to a computer but not to arduino. Im using a Sonyercisson T700 and i believe that its the same +AT commands that Ti68.
    Im trying to find information about it but its kind of hard, i dont have very much experience of programming but i think i can do it.

    Im wondering how you send the PDU message to arduino, when i try it my mobile doesn’t respond in any way. Would be nice if i could get a hint how you have solved it.

    Keep ut the good work! 🙂

    • Marcus says:

      Ok, i meant “send the PDU message from arduino to the mobile”.

    • Tim Zaman says:

      That’s because the T700 uses a virtual serial connection. It seems real through the computer, but its just emulated. You have to use an older version. Just pick up a t68i for $5 from ebay as i did once, that one is old enough, and really works very well.

      • Marcus Weldeborn says:

        Ahhh, i see. I will keep my eyes open for an older phone with a non virtual serial connection. Thank you!

  33. Aureja Zelvyte says:


    Hey we are working on project in University of Iceland with arduino and we want to send cheap sms then our system is on. Can you send the code of this cool project to my email? auz1@hi.is

  34. Mark McGurie says:

    How did you get the arduino to send the location by text message to the iphone?

    • Tim Zaman says:

      I connected the arduino to the T68i and used serial code to make him send a text-message. Read more carefully this is in the text!

      • Wilson says:

        Hi would like to confirm with you the board you are using is Arduino 2560 ?

      • Tim says:

        No, good old 1280. But any chip with a serial interface will work with this code. Anything that can handle c++, that means it includes at least the 328, 1280, 2560. So any arduino will do, even the voltages doesnt matter, 3v3 or 5v will both work. Did use this successfully with a seeduino 3v3 arduino; arduino uno, arduino 328, arduino mega.

      • Wilson says:

        Hi Tim , so let say i am using a Mircochip PIC18F4550 that comes with Serial interface , it will still work ? thks