Morse Code on Arduino — Morseduino
In a previous article, I wrote a brief introduction to Morse code. We will take a look at Morseduino in this article.
Morseduino is a recent project I worked where I built a simple Morse code oscillator and player on the Arduino platform. The capabilities of this device include translating text input from a serial terminal to Morse code sound output in addition to working as an oscillator. In other words, it has two modes of operation; oscillation mode and player mode. In oscillation mode, depending on the Morse keystroke, it plays a tone for the dits and dahs in addition to identifying the characters and printing it out to a serial terminal, whereas in player mode it waits for a text input from the serial terminal and plays the Morse code tones. For example, in player mode, if you entered “CQ” - a common way of calling in amateur radio - you would hear “dah-di-dah-dit dah-dah-di-dah” which is the same as _._. __._ in the dots and dashes notation.
The diagram below depicts the circuit diagram for Morseduino.
A piezo electric buzzer is controlled by digital pin 8 and the Morse key is connected to pin 2. Note that there is a 200nF capacitor for debouncing the switch. There are 2 modes; oscillator mode and player mode which is selected by a two-way switch connected to digital pin 4.
The gist of the code is shown below. The Arduino firmware will keep this endless loop executing and depending on the position of the mode selection switch, it will work either as a player or oscillator.
Let’s look at the two modes in more detail.
Oscillator Mode
This mode would be very useful for practising sending Morse code since it prints out the characters. For example, if you entered di-dah-dah-dah using the Morse key connected to Morseduino, you would see the character j output to the serial terminal. It has the capability of identifying distinct characters as well as words along with the ability to identify invalid input which will result in the # character being printed on the serial terminal.
The above function identifies symbols (dits and dahs), next identified characters and lastly identifies word boundaries. Depending on the time interval of between the Morse key being pressed and released, the function first identifies whether the symbol is a dit or dah and keeps adding those symbols to a char array called currentSymbolBuff. If the time of receiving the last symbol exceeds CHAR_SPACING, the function decides that a character has been received and proceeds to print that character out to Serial out. Finally, if the time of receiving the last character is greater than WORD_SPACING, the function decides that a word has been completed and prints a space to Serial out.
Player Mode
In this mode, one could input character to the serial terminal and send them to Morseduino, which would then play the notes corresponding to each character in addition to pausing in between words. This would be very useful for practising copying Morse encoded messages.
In player mode, it reads the input from Serial and then plays the Morse notes.
The complete Arduino code is available at https://github.com/afkham/arduino-sketches/tree/master/morseduino. Feel free to copy, reuse, distribute and improve this code.