Projects / Morse code practice oscillator

Morse code practice oscillator

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANO

    Wire the key

    One side of the push button to D2, the other to GND. Mount it on a block so you can tap with one finger.

  2. NANO

    Add the sidetone

    Passive buzzer to D8 and GND.

  3. NANO

    Wire the display

    SDA to A4, SCL to A5, VCC to 5V, GND to GND.

  4. NANOHelloPCF8574

    Upload

    Install the LCD library and upload.

  5. NANO

    Send your name

    Press for short and long beats with a steady rhythm. Letters appear after a short pause.

  6. NANO

    Check your speed

    The second line shows words per minute as the sketch learns your timing.

In short

How do you build a morse code practice oscillator?

Press a key to beep Morse. The Arduino learns your speed, decodes your dots and dashes into letters on an LCD, and shows words per minute. You need Arduino Nano, Passive buzzer, Tactile push button 12 mm with cap, 16x2 LCD with I2C backpack (PCF8574), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Key (push button)Nano D2 and GNDInternal pull-up
Passive buzzer + / −Nano D8 / GNDSidetone
LCD SDA / SCLNano A4 / A5Display
LCD VCC / GNDNano 5V / GNDPower

Code

Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "LiquidCrystal I2C" by Frank de Brabander. A straight key or a push button both work. Use a passive buzzer, since the tone comes from the Arduino.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte KEY = 2, BUZ = 8;
const char* CODE[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
                      "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
const char* DIGITS[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."};
float unitMs = 120;                      // dot length, learned from your sending
char sym[8]; byte n = 0;
char text[17] = "                ";
unsigned long downAt = 0, upAt = 0;
bool wasDown = false, pending = false, spaced = true;

void addChar(char c) {                   // scroll the text line
  for (byte i = 0; i < 15; i++) text[i] = text[i + 1];
  text[15] = c;
  lcd.setCursor(0, 0); lcd.print(text);
}

char decode() {
  sym[n] = 0;
  for (byte i = 0; i < 26; i++) if (!strcmp(sym, CODE[i])) return 'A' + i;
  for (byte i = 0; i < 10; i++) if (!strcmp(sym, DIGITS[i])) return '0' + i;
  return '?';
}

void setup() {
  pinMode(KEY, INPUT_PULLUP);
  lcd.init(); lcd.backlight();
  lcd.setCursor(0, 0); lcd.print(text);
  lcd.setCursor(0, 1); lcd.print("Tap the key");
}

void loop() {
  bool down = digitalRead(KEY) == LOW;
  unsigned long now = millis();
  if (down && !wasDown) { downAt = now; tone(BUZ, 700); }
  if (!down && wasDown) {
    noTone(BUZ);
    unsigned long dur = now - downAt;
    if (dur > 20) {                                   // ignore bounce
      bool dash = dur > unitMs * 2;
      if (n < 7) sym[n++] = dash ? '-' : '.';
      unitMs = unitMs * 0.7 + (dash ? dur / 3.0 : dur) * 0.3;     // learn the speed
      unitMs = constrain(unitMs, 40, 400);
      pending = true; spaced = false; upAt = now;
      lcd.setCursor(0, 1); lcd.print("WPM "); lcd.print((int)(1200 / unitMs)); lcd.print("        ");
    }
  }
  wasDown = down;

  if (!down && pending && now - upAt > unitMs * 2.5) { addChar(decode()); n = 0; pending = false; }   // letter gap
  if (!down && !pending && !spaced && now - upAt > unitMs * 6) { addChar(' '); spaced = true; }        // word gap
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Send a short then a long pressThe letter A appears after a pause
Send ... --- ...The word SOS appears
Pause longer than a word gapA space is added
Send fasterThe WPM figure rises

If it does not work

Every letter is wrong

Your dots and dashes are not different enough. Make dashes clearly three times as long.

Extra dots appear

The button bounces. The sketch ignores presses under 20 ms; add a 10 nF capacitor across it if needed.

No sound

Use a passive buzzer on D8.

LCD is blank

Adjust the contrast and try address 0x3F.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the morse code practice oscillator?

Arduino Nano, Passive buzzer, Tactile push button 12 mm with cap, 16x2 LCD with I2C backpack (PCF8574), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the morse code practice oscillator take to build?

About 90 minutes for a beginner maker, in 6 steps.

How do I know the morse code practice oscillator works?

Send a short then a long press: The letter A appears after a pause. Send ... --- ...: The word SOS appears. Pause longer than a word gap: A space is added.

Every letter is wrong: what should I check?

Your dots and dashes are not different enough. Make dashes clearly three times as long.

Extra dots appear: what should I check?

The button bounces. The sketch ignores presses under 20 ms; add a 10 nF capacitor across it if needed.

No sound: what should I check?

Use a passive buzzer on D8.

LCD is blank: what should I check?

Adjust the contrast and try address 0x3F.