Morse Code Translator
  1. Translator
  2. Arduino

Morse code with Arduino

To send Morse code with an Arduino, switch an LED and a buzzer on together for one unit for a dot and three for a dash, with gaps of one, three and seven units. This guide gives a short sketch, the wiring and the timing table at 12 words per minute.

In short: light an LED and sound a buzzer together for one unit for a dot and 3 for a dash, and wait the standard gaps between them. The sketch below does it with only digitalWrite(), tone(), noTone() and delay().

HELLO: what the LED and buzzer play, at 12 words per minute.

Can you try it in Tinkercad first?

Yes. You can try an Arduino circuit virtually in Tinkercad Circuits before you wire a physical board. Autodesk's official guide describes simulated components, editable Arduino code and starter circuits you can modify (Autodesk Tinkercad, PDF pp. 15–17).

  1. Start with an Arduino starter circuit. Use its sample program to check that you understand the simulation before adapting it for Morse. Autodesk documents the Start Simulation button and the editable code view (Autodesk Tinkercad, PDF pp. 7–8).
  2. Switch to the text editor. The sketch below is written as text. Tinkercad offers a pure text view as well as Blocks and Blocks + Text (Autodesk Tinkercad, PDF pp. 16–17).
  3. Check one change at a time. Try the LED output first. Compare its flashes with the HELLO example above, then work toward the circuit in the wiring table. Keep a note of which part you changed before each test.

When you are ready to move to hardware, Autodesk documents exporting the program as an Arduino .ino file (Autodesk Tinkercad, PDF p. 15). Check the physical wiring against the table below before powering your board.

What you need and how to wire it

You need an Arduino board, a passive piezo buzzer, jumper wires and an external LED you can place anywhere, with a resistor. Arduino's Tone Melody example uses a passive piezo buzzer on digital pin 8 (Arduino, Tone Melody), and its Blink example shows how to wire an external LED (Arduino, Blink). The sketch drives the buzzer with tone(), which generates a square wave on a pin; Arduino says the pin can be connected to a piezo buzzer or other speaker to play tones (Arduino, tone()).

Wiring for the sketch on an Arduino UNO
PartConnects toDocumented by
LED (built in)Nothing to wire: LED_BUILTIN is the board's own LED(Arduino, Blink)
External LED, long legOne end of a 220-ohm resistor, whose other end goes to the pin LED_BUILTIN stands for(Arduino, Blink)
External LED, short legGND(Arduino, Blink)
Passive piezo buzzer, + sideDigital pin 8(Arduino, Tone Melody)
Passive piezo buzzer, - sideGND(Arduino, Tone Melody)

Wire the buzzer first, then the LED. Do not wire a coil speaker straight to a pin; an active buzzer ignores the tone() frequency. The table follows Arduino's own examples for an UNO, so check pin names against your board's pinout.

Keep it low voltage

This is a low-voltage project for a board powered over USB: nothing here touches wall power, and nothing should. Do not connect the board or any part of this circuit to mains. If you add an external LED, keep its resistor. Arduino's Blink page says the resistor is essential for safe operation, because it limits the current through the LED and protects both the LED and the board's output pin; it uses 220 ohms with a 5 V UNO R3 (Arduino, Blink).

The sketch

Paste this into a new sketch. The two lists of codes are the letters A to Z and the digits 0 to 9 of international Morse (ITU-R M.1677-1), generated from this site's own table so they match the Morse code alphabet.

const int LED_PIN = LED_BUILTIN;
const int BUZZER_PIN = 8;
const int PITCH_HZ = 600;
const int UNIT_MS = 100;  // 1200 / 12 words per minute

const char *LETTERS[26] = {
  ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
  ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
  "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
const char *DIGITS[10] = {
  "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..",
  "----."
};

void pulse(int units) {
  digitalWrite(LED_PIN, HIGH);
  tone(BUZZER_PIN, PITCH_HZ);
  delay(units * UNIT_MS);
  digitalWrite(LED_PIN, LOW);
  noTone(BUZZER_PIN);
}

void sendCode(const char *code) {
  for (int i = 0; code[i] != '\0'; i++) {
    pulse(code[i] == '-' ? 3 : 1);
    if (code[i + 1] != '\0') delay(UNIT_MS);  // gap inside a letter
  }
}

void sendText(const char *text) {
  int gapUnits = 0;
  for (int i = 0; text[i] != '\0'; i++) {
    char c = text[i];
    if (c == ' ') {
      if (gapUnits > 0) gapUnits = 7;
      continue;
    }
    const char *code;
    if (c >= 'A' && c <= 'Z') code = LETTERS[c - 'A'];
    else if (c >= '0' && c <= '9') code = DIGITS[c - '0'];
    else continue;
    if (gapUnits > 0) delay(gapUnits * UNIT_MS);
    sendCode(code);
    gapUnits = 3;
  }
}

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  sendText("HELLO");
  delay(5000);
}

Each function does one job. pulse() turns the LED and the tone on, waits, then turns both off. sendCode() plays one letter's dots and dashes with a one-unit gap between them. sendText() looks each character up in the lists. It sends uppercase letters and digits, and skips anything else. Consecutive spaces form one word gap; leading and trailing spaces add no delay. setup() sets the LED pin as an output, which digitalWrite() needs before the pin can drive an LED at full brightness (Arduino, digitalWrite()). loop() repeats the message with a pause of five seconds.

The timing, and how to change the speed

Every delay in the sketch is a multiple of UNIT_MS, the length of a dot: 100 ms at 12 words per minute, from the ARRL rule of 1200 ms divided by the speed (ARRL, QEX, April 1990). Dashes and gaps follow the ITU proportions of 3 and 1, 3, 7 (ITU-R M.1677-1). The sketch counts everything in units, so a different speed is a one-line change.

What the sketch waits for at 12 words per minute (one unit is 100 ms)
Part of the signalUnitsMilliseconds
Dot1100
Dash3300
Gap inside a letter1100
Gap between letters3300
Gap between words7700

Only the unit changes with speed, not the proportions. If you want to practice with longer gaps and normal-speed letters, raise only the gaps and leave pulse() alone. The Farnsworth method explains why that helps. To check your numbers against the full rules, see Morse code timing.

Why these four calls

Because delay() blocks, this sketch does not poll a button while it sends. For that you need timing with millis(), which Arduino's reference points to as the alternative (Arduino, delay()). That is also where a decoder would start, and it is beyond this page.

How do you read a Morse key with an Arduino?

Wire the key between a digital pin and GND, set the pin with pinMode(pin, INPUT_PULLUP) and read it with digitalRead(). The pin reads HIGH while the key is up and LOW while it is pressed. Arduino's InputPullupSerial example works this way: the internal pull-up connects the pin to 5 V, so the pin reads HIGH when the button is open, and pressing the button pulls it to ground (Arduino, InputPullupSerial). Do not leave an input unconnected. Arduino warns that digitalRead() on an unconnected pin can return HIGH or LOW, and the value can change randomly (Arduino, digitalRead()).

Then time each press with millis(). It returns the milliseconds since the sketch started as an unsigned long and overflows after about 50 days (Arduino, millis()). Store the time of each change and subtract the last one from it. Do not wait with delay() while you listen: Arduino's Blink Without Delay example says that during a delay "your program will miss the button press" (Arduino, Blink Without Delay). Mechanical buttons also give spurious open and close transitions when pressed, which Arduino's Debounce example filters with millis() (Arduino, Debounce).

To turn the timings into letters, use boundaries halfway between the standard lengths (ITU-R M.1677-1). At 12 words per minute, a press of 200 ms or longer is a dash and a shorter one is a dot. Silence of 200 ms or longer ends a letter, and 500 ms or longer ends a word. These boundaries are our choice, not a standard. This page does not include a decoder sketch.

Is there an Arduino library for Morse code?

Yes. Etherkit Morse sends Morse code by toggling an output pin you choose; its README says you must call its update() function once per millisecond, best done from a timer interrupt (Etherkit, README). The sketch above needs none of this. Read a library's own page for its license and the boards it supports before you install it.

For another beginner board, see Morse code on a micro:bit.

Beyond the sketch

To try a signal circuit in a game world, follow Minecraft Morse code for a redstone build.

The same idea runs in software only in Morse code in Python, where a list of on and off steps comes out of one function. On a Raspberry Pi, Morse code with Raspberry Pi drives an LED from its GPIO pins and reads a key button. To hear what your sketch should sound like first, the translator plays any text, and learning by ear points to lessons by ear in our upcoming app. To compare this sketch with other coding approaches, see Morse code programming.

Sources

  1. Recommendation ITU-R M.1677-1, International Morse code. ITU Radiocommunication Sector, October 2009.
  2. A Standard for Morse Timing Using the Farnsworth Technique, Jon Bloom, KE3Z. ARRL, QEX, April 1990.
  3. tone(), Arduino Language Reference. Arduino, checked 7 November 2026.
  4. digitalWrite(), Arduino Language Reference. Arduino, checked 7 November 2026.
  5. delay(), Arduino Language Reference. Arduino, checked 7 November 2026.
  6. Blink, Arduino built-in examples. Arduino, checked 7 November 2026.
  7. Play a Melody using the tone() function, Arduino built-in examples. Arduino, checked 7 November 2026.
  8. millis(), Arduino Language Reference (source file). Arduino, checked 11 November 2026.
  9. digitalRead(), Arduino Language Reference (source file). Arduino, checked 11 November 2026.
  10. InputPullupSerial, Arduino built-in examples (source file). Arduino, checked 11 November 2026.
  11. Blink Without Delay, Arduino built-in examples (source file). Arduino, checked 11 November 2026.
  12. Debounce on a Pushbutton, Arduino built-in examples (source file). Arduino, checked 11 November 2026.
  13. Etherkit Morse (MorseArduino) library. Etherkit, checked 11 November 2026.
  14. Official Guide to Tinkercad Circuits. Autodesk Tinkercad, checked 11 November 2026.