Tag Archives: morse

Morse Code Twitter Wall: A Bit About Morse Code

Morse code was invented as a way of transmitting alphanumeric data across a telegraph wire. The length of each letter, number, or symbol in Morse is inversely proportional to its English language frequency. The letter “E” is a single dot and “T” is a single dash. Most letters combine the two base “characters” — the letter “J” is a dot and three dashes.

The unit of time in Morse is the dot. A dash should be three dots long, and the space between dashes and dots in a single character is a single dot.

To simplify writing characters in Morse in my Arduino code, I’ve attached the single dot intra-character space to the symbol. So to write a dot, I need to turn on the LED for our dot’s length, then turn it off for the same amount of time.

int DOT_LENGTH = 100;

void dot() {
    setPin(led, HIGH);
    setPin(led, LOW);

void dash() {
    setPin(led, HIGH);
    delay(DOT_LENGTH * 3);
    setPin(led, LOW);

This enables me to write the letter “L” (dot-dash-dot-dot) very simply as:


The letter “E” takes 2 × DOT_LENGTH (here, 200 milliseconds) to write: one for the dot, one for the intracharacter space. “T” takes 400 ms. The longest letters contain three dashes and a dot, for 1600 ms.

So with a little math, we can figure out the maximum length of a tweet. The number zero, represented by five dashes, takes the longest to “display”. Since a single dash (400 ms) and its following space (200 ms) takes 600 ms, a zero would take 2200 ms (two seconds). The theoretically longest tweet is therefore 140 zeroes, which would take 140 × 2.2 seconds = 308 seconds to display. (More than five whole minutes!)

Fortunately, this is the very worst case. Assuming a mean tweet length of 68 characters, and a random distribution of letters* such that the average letter length is about 11.25 dot lengths including its intercharacter space, we multiply to find that on average a tweet can be displayed in Morse in 76.5 seconds.

I’ve also set DOT_LENGTH as a constant variable at the top of the program. I can only assume that as I gain more experience reading Morse, I can reduce this number to effectively speed up the “reading” of tweets.

My initial version of the Morse Twitter wall will poll for a new tweet every two minutes. This number is entirely made up. However, it ends up not being that far off base; if an average tweet will take a minute and a quarter to display, then many tweets will be displayed twice before a new tweet is requested.

This also means that I can poll at will rather than at some kind of interval. I was initially afraid of running afoul of Twitter’s API limit (180 requests every 15 minutes), which also had to include my desktop Twitter client’s needs. However, polling for a new tweet would on average happen 12 times every 15 minutes, well below my 180 request limit.

For a woefully outdated introduction to Morse code sponsored by the United States Army Signal Corps (circa 1966), watch this video.

Last time: Project Intro: Morse Code Twitter Wall
Next time: The (Ridiculously Simple) Hardware.

*Since the lengths of the letters in Morse are inversely proportional to their frequency in English text, this particular estimate is higher than it needs to be. However, since I only included letters in this sample, and punctuation and numbers contain five or six dashes or dots, this should even out the error in this estimate.

Project Intro: Morse Code Twitter Wall

I’ve had a fascination with Morse code ever since I was a kid. Still, I never really got anywhere with it. Most ten-year-olds have more interesting things to do than to tap out messages at five words per minute. And it doesn’t take much knowledge of human nature to guess that the kind of kid who had a fascination with Morse code, likely wouldn’t find someone else to be on the other end of the telegraph key.

Now I’m an adult, a software developer and technologist. Even though the range of interfaces available to us now are so wide-ranging, I’m still fascinated by the fact that a single blinking light can convey complex information.

Conveniently, I’ve also been interested in learning how to use Twitter’s API to programmatically interact with the service. So it was tempting (if not a little awkward) to combine the two projects.

Since I had an Arduino and some LEDs lying around, I thought it might be a worthwhile exercise to use the Arduino as a driver to convey information through Morse code.

My goals for this small but manageable project are as follows:

  • Configure the Twitter API and learn some basics.
  • Refamiliarize myself with Arduino sketches by writing a Morse code translator
  • Get in the habit of documenting and sharing my project, which includes these blog posts and publishing code on GitHub

One of the panelists at the Dragon*Con 2010 “Creating Your Hackerspace” session said something that has stuck with me to this day.

“Your project is never finished until you’ve blogged about it.”

In that spirit, I intend to (over?)-document here what I’ve learned.

Future posts will likely include:

  • What is Morse code?
  • Arduino configuration
  • Java client and Twitter API
  • Serial communications
  • Putting it all together

So far I’ve only spent a couple of hours on the entirety of this project. Setting up the infrastructure and retraining myself on how to do some really basic things have been most of my effort.

I know this isn’t the most groundbreaking project — at a glance it’s kind of stupid — but the building blocks can be upgraded to create some useful applications. For example, it’s not a big step to change the Twitter aggregator to grab weather data, and the single LED to an LCD display so as to produce a standalone weather reporter. So my aim is to get components talking and playing nice with each other, so as to allow some branching out in the future.