Skip to main content

7.6 Morse Code Transmitter

placeholder
Morse Code Transmitter project demonstration

The goal of this project is to create a Morse code transmitter using the NULA MINI and a single LED.
When you type a message in the Serial Monitor, the board converts it into Morse code and blinks the LED to represent dots and dashes.

This example demonstrates timing control, text processing, and LED output — combining them into a fun and educational light communication project.

In this documentation you will learn:

  • How to convert text into Morse code patterns.
  • How to use Serial.readStringUntil() to receive user input.
  • How to blink a LED using timed delays for dots and dashes.
  • How to control message pacing using letter and word gaps.

Hardware required

  • 1× Soldered NULA MINI board
  • 1× LED
  • 1× 330 Ω resistor
  • Breadboard
  • Jumper wires
  • USB-C cable
placeholder
All components required for Morse Code Transmitter project

How it works

Each letter or number in Morse code is made of a sequence of short and long light pulses:

  • Dot (·) = short blink (300 ms)
  • Dash (–) = long blink (900 ms)
  • Pause between symbols = 300 ms
  • Pause between letters = 900 ms
  • Pause between words = 2100 ms

When you type a message in the Serial Monitor (for example, SOS), the NULA MINI:

  1. Looks up the Morse equivalent (... --- ...).
  2. Blinks the LED accordingly using delay() to time each pulse.
  3. Waits between letters and words automatically.

This simulates how early telegraph systems transmitted coded messages over light or radio.

placeholder
Morse code table

Wiring and connections

ComponentNULA MINI PinDescription
LED anode (long leg)IO2Digital output for Morse signal
LED cathode (short leg)→ 220 Ω resistor → GNDCurrent-limiting resistor path
Common groundGNDShared system ground
placeholder
Wiring diagram for LED Morse Code Transmitter

Full code

Below is the full example code for this project:

#define LED_PIN 2  // LED output pin

int DOT_DURATION = 300; // base time unit (ms)
int DASH_DURATION = DOT_DURATION * 3;
int SYMBOL_GAP = DOT_DURATION; // gap between dots/dashes
int LETTER_GAP = DOT_DURATION * 3; // gap between letters
int WORD_GAP = DOT_DURATION * 7; // gap between words


struct MorseEntry { char letter; const char *code; };
const MorseEntry morseTable[] = {
{'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."},
{'F', "..-."}, {'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"},
{'K', "-.-"}, {'L', ".-.."}, {'M', "--"}, {'N', "-."}, {'O', "---"},
{'P', ".--."}, {'Q', "--.-"}, {'R', ".-."}, {'S', "..."}, {'T', "-"},
{'U', "..-"}, {'V', "...-"}, {'W', ".--"}, {'X', "-..-"}, {'Y', "-.--"},
{'Z', "--.."},
{'1', ".----"},{'2', "..---"},{'3', "...--"},{'4', "....-"},{'5', "....."},
{'6', "-...."},{'7', "--..."},{'8', "---.."},{'9', "----."},{'0', "-----"},
{' ', " "}
};
const int MORSE_COUNT = sizeof(morseTable) / sizeof(MorseEntry);

// Lookup function
const char* getMorseCode(char c) {
c = toupper(c);
for (int i = 0; i < MORSE_COUNT; i++)
if (morseTable[i].letter == c) return morseTable[i].code;
return "";
}

void blinkSymbol(char symbol) {
int duration;
if(symbol=='.'){
duration=DOT_DURATION;
}
else{
duration=DASH_DURATION;
}
digitalWrite(LED_PIN, HIGH);
delay(duration);
digitalWrite(LED_PIN, LOW);
delay(SYMBOL_GAP);
}

void transmitText(const String &text) {
Serial.println("\n--- TRANSMITTING ---");
Serial.print("Text: "); Serial.println(text);
Serial.print("Morse: ");

// Display Morse translation in serial
for (unsigned int i = 0; i < text.length(); i++) {
const char *code = getMorseCode(text[i]);
Serial.print(code);
Serial.print(" ");
}
Serial.println("\n--------------------");

// Blink Morse code on LED
for (unsigned int i = 0; i < text.length(); i++) {
const char *code = getMorseCode(text[i]);
if (*code == ' ') {
delay(WORD_GAP);
continue;
}
for (int j = 0; code[j]; j++){
blinkSymbol(code[j]);
}
delay(LETTER_GAP);
}

Serial.println("\nTransmission complete!\n");
}


void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
Serial.println("Enter text to send via Morse code:");
}

void loop() {
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.length() > 0) transmitText(input);
}
}


Full example

placeholder
Full Morse Code Transmitter demonstration video

Check out the full example code on the link below:

7.6_Morse_Code_Transmitter.ino

Project that converts text entered in the Serial Monitor into Morse code blinks using a single LED on the NULA MINI board.