What you need
An AVR-based Arduino Uno (such as the Uno Rev3) or classic Nano, a suitable USB cable, and the Arduino IDE. This sketch uses LED_BUILTIN and assumes HIGH turns the LED on, as on these boards. This sketch stores the pattern in AVR flash memory to leave room in the small working memory. It needs adaptation for newer non-AVR boards such as the Uno R4 or Nano 33, which may also use different pins or inverted LED behavior.
Send your first message
- Write your message above and choose a speed. Audio volume and tone do not change the LED sketch.
- Choose “Download Arduino sketch” and open
morse_message.inoin the Arduino IDE. - Connect your board. Select its board type and USB port in the IDE.
- Upload the sketch. The built-in LED repeats your message with a seven-unit pause between repetitions.
- Change the message in the generator and download a new sketch when you want another pattern.
A complete HELLO example
This example uses a 60 ms dot at 20 WPM. Positive numbers switch the LED on; negative numbers switch it off. The same pattern generates the sound and downloads above.
View the Arduino sketch
// Morse Code Generator — morsecodegenerator.top
// AVR Arduino Uno / classic Nano: uses the built-in LED.
// No external wiring needed. Pattern is stored in flash, not limited SRAM.
// Speed: 20 WPM. Dot = 1200 / WPM milliseconds, rounded to nearest ms.
// Positive units: LED on; negative units: LED off.
#include <avr/pgmspace.h>
const unsigned int DOT_MS = 60;
const int8_t SIGNAL[] PROGMEM = { 1, -1, 1, -1, 1, -1, 1, -3, 1, -3, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 3, -1, 1, -1, 1, -3, 3, -1, 3, -1, 3 };
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
for (unsigned int i = 0; i < sizeof(SIGNAL) / sizeof(SIGNAL[0]); i++) {
int units = (int8_t)pgm_read_byte(&SIGNAL[i]);
digitalWrite(LED_BUILTIN, units > 0 ? HIGH : LOW);
delay(abs(units) * DOT_MS);
}
digitalWrite(LED_BUILTIN, LOW);
delay(7UL * DOT_MS); // Pause between repeated messages.
}
Download this HELLO sketch. The sketch’s timing has been checked against the generator. It has not been tested on a physical board.
Why the pauses matter
Dots take one unit and dashes take three. Pauses inside a letter take one unit; pauses between letters take three; pauses between words take seven. The sketch stores complete pauses so they do not accidentally become four or eight units. Read the timing guide for worked examples.
What this project does
The browser creates a file you upload through the Arduino IDE. It does not connect directly to your board. The sketch repeats your message and uses delay(), so it suits a simple LED project; a project that needs to handle buttons or sensors at the same time will need a non-blocking approach such as Arduino’s Blink Without Delay example.