I'm new to Arduino..

I'm currently trying to create a GPRS connection through SIM card. For that, I need to connect a serial UART port.

I don't know how to define the Serial UART. Could you please help me with that?

  • 2
    There are millions of examples on google for how to do it. Have you tried asking it?
    – Majenko
    Jan 6, 2017 at 17:14

2 Answers 2


In the setup function you will need to call the Serial.begin() function.

To receive a serial character you should call the Serial.available() function inside an if statement.

To send a character you can either use the Serial.write() or Serial.print() functions.

Below is a simple example program that will echo the characters back to the PC.

// Simple serial loopback

void setup()
  // initialize the serial communication:

void loop()
  byte inChar;

  // check if data has been sent from the computer:
  if (Serial.available())
    // read the most recent byte
    inChar = Serial.read();
    // send back the charater

There are plenty of "built-in" examples in the Arduino IDE that use the various serial functions. These can be viewed without any hardware attached. In the IDE go to File > Examples and from there a lot of the examples for the serial UART are in the Communications section. Details of these examples can be found on the Arduino Tutorial site.

  • 1
    The uno's only hardware UART is used for peogramming and producing debug outpt. If it is connected to a GPRS module then programming will not be possible and debug output will be problematic. Jan 6, 2017 at 15:39
  • I've seen many boards use jumpers/switches/solderlinks/shields that you disconnect when you need to reprogram. Hopefully you get to a stage where you device works and you don't need to reprogram the micro.
    – sa_leinad
    Jan 7, 2017 at 12:13

The Arduino has only one UART which is used for program upload and for the serial terminal output to your computer. While you can connect it to another serial device that will make debugging cumbersome as 1) you won't be able to send any debug output; and 2) you will need to change it back and forth between your computer and the GPRS as you re-build and upload your code. You pretty much need a second UART to do this any kind of conveniently.

Look up the library module called SoftwareSerial which can simulate a UART on a second pair of pins, with some limitations: It is limited to communicating at 9600 baud; it can not transmit and receive at the same time; at most, one SoftwareSerial port can be receiving (or even listening) at any one time; and it can interfere with some other internal hardware, notably the interrupt system and at least one of the timers. (The link points to the Arduino website whose documentation isn't always the very latest, but what's there will give you the idea).

In many cases, and yours is likely one of them, these are not show-stoppers, just something to be aware of as your code becomes more complex. As long as you can operate your device by occasionally sending it a string and receiving another in reply, and your system doesn't include other high-speed devices that must be serviced quickly when they request it, you probably won't notice the limitations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.