How To Connect Arduinos

to other devices over serial channels

This is a menu page to guide you to the article you need in the realm of connecting Arduinos to external devices with a serial port. (Here, you can either jump down to the "how tos", or continue to read my attempt to give you a useful overview.) That "external device" might be a "big" computer, i.e. what we usually mean by "computer"... a Linux or Windows laptop. Or it might be another Arduino. Or it might be a printer. These articles are meant to show you general skills and tools.

Breaking the material up was quite a challenge! I've tried to address many different combinations of possible requirements. I've tried to work progressively from simple ideas through to more complex situations.

Just before we start.... please take note of the following warning:

"Serial" and "RS-232" are NOT just two ways of saying the same thing. RS-232 comms do use serial data, so you might think that you can (directly) hook up any serial "stuff"... including your Arduino... to RS-232 devices. Or to the RS-232 port of a big PC. NOT SO!!

All the ins and outs of that are beyond the scope of this introduction. I've inserted this warning here just in case someone is tempted to "extend" the ideas in early pages and hook an Arduino directly to something RS-232... and fry their Arduino! (I've done a separate page with the details of how RS-232 and "serial" are not the same thing... and "fixes" for the problems.) (I've also created a page for you about the pins on various serial devices... which pin carries which signal... useful when you're trying to hook things up!)

Slice and Dice

So what were the different design requirements which made organizing this material difficult?

Channel: In some essays, I will only use the "basic" serial port of the Arduino, the one that you use to program it via the standard IDE

Direction: Sending from the Arduino entails some challenges. Receiving to the Arduino poses different challenges.

Other party- simple: What is the Arduino connecting to, and what software does it have? In the work explained in these essays I will usually just be connecting to a Windows PC, but it will in many cases merely be standing in for other things which could be put in its place. In the early, easy "How To"s, the Windows PC will only be running the usual Arduino IDE. Even this simple set up does have some "real world" uses.

Other party- level 2: Then I will show you how to replace that "other party" with any PC running any simple terminal software, e.g. Hyperterminal or the freeware serial terminal software for Windows and Unix platforms called PuTTY. (There's a welcome change! Something coming out of Windows, and being left for third parties to benefit from supplying!)

Other party- level 3: And the ultimate goal... not reached by me yet!... is to show you how to write applications to run in the "other party" which will interact with the Arduino over the serial channel. The "other party" could, of course, be another Arduino, running a different program! I have "finished" the Arduino end of that challenge, and there are plenty of solutions, e.g. use the "Processing" language... but I have yet to "roll my own" serial comms software for the "other party" end of the package. Too busy writing these essays for you! (If you use Windows, please consider trying some of my shareware!! (Opens in new tab))

Mega Users, N.B.: I read in a post at the excellent Arduino forum that (at 21 Dec 2010) the Mega does not support NewSoftSerial unless you use "the patched version", and that the Mega has four hardware serial ports which "are the way to go"! That should save Mega owners some of the tasks in what follows, but other material will still be useful to them.

Furthermore: If you are using ver 1.0 (or higher) of the Arduino development software, you no longer need to worry about NewSoftSerial... it was incorporated, from ver 1.0, as SoftwareSerial

The How To pages....

Very simple answer: It only displays incoming ASCII from a source that doesn't need to receive commands to start that ASCII flowing, but it could be a useful starting point for many things.

Biggest and Best to Date: Linking multiple devices Arduino "master/slave" setup: With a program running in a "master" PC, an Arduino "slave", with an LED and "doorbell" switch can be "driven" / monitored. The window on the PC's screen tells you from moment to moment whether the "doorbell" connected to the Arduino is pressed, and there are two buttons: "Turn LED On", "Turn LED Off". With a click of the mouse on the master, the PC, the LED on the Arduino can be turned on or off. The two are connected by a simple serial link. You don't NEED Delphi to benefit from the material in the tutorial, even though the PC part of it is couched in Delphi terms.

Simplest Case: Information from Arduino to PC running IDE, over basic serial port. (This is just a second link to an article also mentioned above!)

To Arduino from PC running IDE, over basic serial port.

It may not be pretty... but it WORKS!!! Forgive a little shouting... I have tried to do this for many, many years... having tackled it many times, and come away bruised and defeated previously. But, April 1st, no fooling, 2010, I DID IT!!!

As part of my Delphi tutorials collection, I offer you an essay on a bi-directional serial comms program, with sourcecode or compiled .exe which can run in a Windows PC, and "talk"... both ways... to anything across a serial link. It is "crude"... but it shows the essentials better than an all singing, all dancing, "fancy" program. Sadly, at the moment, it is hard coded for COM1, 9600 bps. No hardware handshake. But if you can program, you can "fix" those things. Don't let the "Delphi" bit scare you... it is made up mostly of API calls.... you should be able to translate to the language of your choice.

If you want to do something better, by all means do, and share your work. There's a page at Microsoft (36 pages, actually, I believe) to tell you about serial comms, if you want to do something better.

The program is "eccentric"... to keep what is "under the hood" easy... relatively!... to follow. It puts three buttons on the screen. Click one, and "Hello" is sent from the PC to the remote device. Click the second, and "Bye" is sent, but the program doesn't "go anywhere". So far so simple. The third button is the one that is a little non-obvious. If you send things from the remote device to the PC, and then click the third button, you will see a message box on the PC with what was sent from the remote device. Hyperterminal it isn't! Or even PuTTY, which I commend to you if you want a free Hyperterminal replacement. But my program has within it all the building blocks you need for any interaction between a PC and something external, over a serial link.

Another detail.... If you...

...you WON'T see the stuff you sent to the PC before using the "Send Hello". In the course of "going off" to send "Hello", the PC discards the contents of the incoming buffer. Not as big a problem as it seems... but it could be confusing if you download the program and play with it.

REMEMBER MY WARNING about RS-232 not being the same as "serial comms"... the voltage levels in a Windows PC and at an Arduino are not the same. You need a MAX232 chip or similar if connecting the two.

I will be writing this up properly in due course, and doing a second program which will be more like a Hyperterminal clone.

But even that is just the tip of the iceberg.... you could, for instance, have a remote keypad for a burglar alarm on the outside of your house. There would be an Arduino in it to handle keypresses, beep beepers, turn LEDs on an off.... AND important "stuff" could be passed on, over a serial connection, to a bigger PC (or another Arduino) inside the house, where other parts of the alarm/ home automation system would be implemented. Now that I have the basic send and receive routines figured out AT LAST, the sky's the limit!!

See also...

Besides the above, which were written with a care to minimize duplication, I've put other material on the web which concerns connecting things to the Arduino via a serial channel. The following isn't comprehensive....

Drive an inexpensive LCD panel (80 characters or so) from an Arduino

Control VGA display with single serial line: Inexpensive (£25 @11/14, incl p&p in UK) small board which can generate an image on a VGA display. Character based, 50 lines of 100 characters. You only use a single I/O bit of the device controlling the display, to "say" what you want shown on the display. It can have multiple windows, and each scrolls and line-wraps automatically. In multiple colors.

Connect a USB keyboard to a microprocessor: For only £14 (@12/14, incl tax, but plus p&p) small board from Hobbytronics.co.uk to take an ordinary USB keyboard and convert keypresses to a stream of serial data for, say, and Arduino, Teensy, or other microprocessor. Ties up just one pin of the microprocessor and very limited memory, etc, resources.

Off-load the overheads of reading a keypad

Interact with 1-Wire devices via a controller

To search THIS site.... (Go to my other sites, below, and use their search buttons if you want to search them.)
Click this to search this site without using forms.

powered by FreeFind
Site search Web search
The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.
My site at Arunet.
My Sheepdog Software pages, another of this page's editor's sites.
Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Here is how you can contact this page's editor. This page, and the software it references, ©TK Boyd, 1/2010.

Valid HTML 4.01 Transitional Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!