Laser Morse Code Tutor

Jeff Fung    Yen-Khai Lee

May 3, 2004

.---- Introduction ..--- High Level Design ...-- Program/Hardware Design
....- Results ..... Conclusions -.... Appendices

.---- Introduction

In this project we design and construct an interactive Morse code trainer which converts hand movements into Morse code characters via laser beam interruption.

Core components include a laser diode, a PIN photodiode, a Mega32 microcontroller, and a small black-white TV with speaker.  The user initiates Morse code by signaling the laser beam using one finger or an open hand; the interruption of the beam adjusts the bias on the output of a bipolar amplifier from the PIN photodiode to be fed into the Analog-Digital Converter (ADC) of the Mega32.  A Finite State Machine (FSM) parses the finger counts based on voltage thresholds and converts the Morse code into characters as a Morse code character tree is accessed.  On the software side, the TV with speaker instructs the user the basics and smoothly carries the user along through a tutorial in the beginning.  An empty panel is available for the user to practice and experiment with Morse code entry.  The user finally enters into a series of gaming levels where the user's knowledge of Morse code will be tested and score tabulated. 

In effect, this project is a showcase of retro and modern technology, combining light-based Morse signaling, old school typing software, Missile Command, together with laser diodes, microcontrollers, and high-speed PIN photodiodes.  It is one of the few non-contact, serial electronic communication trainers in existence that does not require speech.  Moreover, we hope that the user will be able to learn rudimentary Morse code from this experience.

..--- High Level Design

Project Rationale

Initially, we decided to create a laser window listener using the same core components as this project. However, due to problems with the power of the budget laser diode to pick up vibrations off glass, we redirected our focus towards reusing the core components to create something much more reliable and suitable at the level of complexity that is required.  We felt that by reusing the parts from the preliminary project, the best project was one that had to be educational, comprehensive, and based on laser communications.  Hence, after some consideration, we found that interrupting the laser by hand would simulate old-school Morse code light generation at a great distance, thus enabling smooth incorporation with the MCU and TV as a trainer. 

Morse code, one of the earliest serial communication systems, is the foundation for many binary data interchange codes including ASCII and barcodes.  Our decision to use Morse code stems from the fact that Morse code is the easiest serial code to implement as well as for ham radio beginners to learn the code in a more engaging manner.  By engaging, we mean interactively participating in a frenetic, carpal-tunnel-syndrome-inducing hand waving (with standard Morse code sounds) to pass the tutorials and game levels on TV. 

Logical Structure

As mentioned previously, the core input components of our laser-based Morse code trainer are an infrared laser diode emitter and a PIN photodiode for reception.   The idea is to use a finger or multiple fingers/open hand to interrupt the laser beam at periodic intervals to generate the so-called dits, or "shorts", and dahs, or "longs" based on standard Morse code requirements.  An amplifier picks up the difference in voltages, outputting a voltage to the ADC at given intervals.  The intervals define the number of fingers that cross the beam - in our case, one finger indicates dit and multiple fingers dah.  A Morse code character FSM in the MCU accesses a Morse code tree to based on the dits and dahs and constructs a character. 

The software component is a large FSM composed of a tutorial, a game, and a test sketch. Since it is difficult for the user to understand what to do on the first time through, we decided to lower the learning curve by introducing basic instructions to tell the user to wave a finger to progress.  A tutorial allows the user to learn basic signaling methods, characters/numbers in Morse and thus be able to select the two options on the main menu: (1) sketch (2) game.  Sketch is merely an empty panel for practicing Morse code entry, while the game is loosely based on retro-typing games and Missile Command.  In the game, the user must be able to signal the destruction of a character before the character bombards parts of a futuristic city.  Finally, all sound and video information is sent out through the MCU ports to the TV. Figure 1 below shows the entire high-level logic flow of the Morse trainer.

Figure 1.  High Level Structure of the Laser Morse Code Trainer

Hardware/software tradeoffs

The primary hardware tradeoff was the use of an infrared laser diode as opposed to a regular visible laser diode.  Both are equally suited for the task of finger tracking; differences exist in that visible diodes can be used at a much longer range due to ease of aim while infrared diodes are much less annoying to the user in terms of light reflection.  Visible laser diodes are also significantly cheaper than infrared diodes.  The decision was made to use the infrared laser diode since we already had the infrared set from the initial laser microphone project.

The main software tradeoff that we made was the use of number of fingers instead of timing the beam, e.g. by using a button on the emitter end.  This decision was made in order to simplify the amount of calibration that would be required to get a precise timing from every user.   However, using a button might be easier on the hand, since later it turned out that hand/finger waving is fairly strenuous.

Another important tradeoff revolved around the use of the ADC instead of a comparator that would simply generate 0-5V to the ports.  A comparator would cost us extra solder board space (which is close to full), while using an ADC on a per frame basis is not really a timing problem at all in our case.  It is also much easier to tune the voltage threshold levels in software than in hardware.

In retrospect, the software/hardware split is around 80% software and 20% hardware.

Standards/Existing Patents/Copyrights/Trademarks

The international Morse code standard is composed of long and short sounds/signals, with the long sound exactly three times the length of the short sound; spaces within a character have the length of a dit.  We will hence refer to the long sound as a "dah" and the short sound as a "dit"  throughout the rest of the site.  Each character and number falls under a unique pattern of dits and dahs.  With this information in mind, it is easy to construct a binary tree of dits and dahs as a mnemonic; Figure 2, which is borrowed from, shows the binary tree in all its glorious details.  A 5 WPM speed is required to pass an amateur ham radio test. 

Figure 2.  Morse Code "Binary" Tree [1]

There are also Morse trainer programs that can be downloaded, such as NuMorse Professional [2].  Although these programs train at very high speeds at > 10WPM, they are mostly not very interactive.  We do not make use of any external Morse trainer software.  The game that we derive from, Missile Command, is originally developed by Atari.

The second standard that we use is RS170/NTSC, as a result of the video generation code from Mega32 provided by Professor Bruce Land of Cornell University.  RS170/NTSC defines timing, voltage, sync levels, and other characteristics of a black and white video system.  The stated frequency is 60Hz with 525 lines; Professor Land's version uses a non-interlaced scan, meaning only 262 lines per frame and 30Hz or 30 frames per second. 

Thirdly, there is a safety classification of different lasers according to their power values, regulated by Center for Devices and Radiological Health (CDRH).  The regulations are 21 CFR 1040.10 and 21 CFR 1040.11 [3].  The classes include Class I, II, IIIa, IIIb, and IV, with the least (I) to most dangerous (IV) in that order.  The output power of our IR laser diode is below 5 mW, which places it in the IIIa range.  A class IIIa laser product has a power output between 1mW and 5mW, which could cause possible eye damage/injuries if directly pointed at the eye.  There is no skin or fire hazard for this class of lasers.  

...-- Program/Hardware Design

Program Details

The program is divided into three parts - a Morse code FSM that interfaces with the ADC, a user software interface FSM with the tutorial/sketch/game, and a slew of graphics functions.

The simplified Morse code parsing FSM, called morse_fsm(), in a pseudo-code format is shown on Figure 3.  Basically, when a finger exists, the state moves from Idle into Ditdah and begins checking for the number of fingers that pass through, whilst incrementing a timer.  The timer is displayed on the TV as "DITDAH", and the user must signal one or multiple fingers within this time period to initiate a dit or dah.  A separate FSM is called to check the number of fingers within this time,  incrementing the number of fingers in ditdah_fsm().  Within Ditdah, tones of correct lengths are also played using TCCR0 by counting and the Morse code tree, which is constructed out of C pointers, is traversed. 

Once the time is up, the Ditdah state enters Waitchar, where another character timer waits for the next finger(s).  This timer is shown as "CHAR" on the TV, indicating the amount of time left before the system recognizes the full entry as a character.  Within this time, if another finger is waved, the Ditdah state will be entered again.  Otherwise, the state will move to Endchar when time is up.  Note that in Ditdah, there is a possibility of going straight to Endchar if the tree has been fully traversed.

The end of character state, EndChar, checks whether the character is valid and goes to an Error state or returns to Idle after displaying the character.  In the error state, a error tone is produced using TCCR0 once again to signify to the user that his entry is incorrect, which then returns to Idle.

The ditdah_fsm() is a simple three state "debounce" type FSM which counts the number of fingers that pass through.  finger_check() is a function that compares to a value in ADCH and returns 1 or 0 depending on the presence of a finger, with the ADC value sampled every frame. 

Figure 3.  Morse Code FSM

On a higher level, we have the user interface FSM which controls the main menu, tutorial, sketch and gameplay:

Figure 4.  main user interface/menu FSM

The sketch function does not require too much programming detail.  Slightly more complicated is the tutorial, which runs through a series of frames that increment screen_char_xpos such that the user is brought along frame by frame.  The user is told to start from the basics and progress on to finishing all the alphabets and numbers by learning how to signal.  This is done one step at a time, in order to be able to master the methods of finger and open hand signaling, until the user officially "graduates."

The game is the most complicated of the three functions, with the general algorithm shown on Figure 4.  A title is drawn in a couple of frames, followed by the city being drawn in 8 frames such that video artifacts do not occur.  A random character is generated using rand() as well as the horizontal position of the random character.  The character is then animated on screen if no correct signal has been detected, i.e. letter does not equal curr_letter. An explosion is drawn if the dropping letter is equal to the curr_letter or if the letter reaches the city.  Score is then updated upon the successful entry of a letter, and level/speed is increased upon every 5 successful entries.  If dah is detected six times, the game will exit to menu, displaying characters per minute (CPM) and words per minute (WPM), where the average of 5 character/word is used for conversion. Otherwise, the game will continue from the randomization of a new letter.

Finally, all graphics functions are grouped together in proj_header.h.  It is too exhaustive to list them here, but examples include video_putg2(), which prints a user specified x and y bitmap; the detailed 8 block bitmap list which we drew for the city; an explosion bitmap; the dit-dah bitmaps; and the title screen bitmaps in the beginning.

By far the most challenging aspect software-wise is lines per frame in both the Morse code FSM and the game.  The Morse code FSM requires very careful control and resetting of variables, as well as fine tuning on the dit-dah and character intervals to achieve a signally sound speed, such that no video artifacts occur.   On the other hand, the game is severely restricted by speed and even drawing three bytes of bitmaps at once immediately creates video artifacts.  To overcome this barrier we split the drawing up into multiple frames, especially in the drawing of the city.  The game also has to create random characters and positions while running the Morse code FSM, which makes us circumvent the speed constraint by calling a random number once.

Hardware Details

In actuality, any laser diode is suitable for generating a long-range light source, although a visible laser might be more preferable if aiming is required.  In our case, since we already had a infrared red laser diode (5.6mm apt, 780nm wavelength, 5mW) left over from the initial project, we were able to solder it to a small board and tape it to a 90-degree angular stand.  According to specifications, the typical operating current and voltage are around 35mA and 2.1V [4].  Now, resistive biasing of laser diodes is a tricky operation - the maximum diode operating current is around 50mA, while the threshold current is merely half of the maximum current at 25mA.  Assuming the diode operating voltage is 2.1V and VDD is 5.0V, the resistor required to bias the laser is around:

A 100-ohm resistor was used instead, yielding a lower operating current at 29mA and thus placing us on the safer side.  Also, note that in order to prevent high frequency transients from destroying the laser diode, 0.01uF and 10uF capacitors must be added in parallel to the diode along with the resistor to form a low-pass filter (see Sam's Laser FAQ, [3]).  The low pass filter essentially prevents voltage from being passed on to the diode at high frequencies, as the capacitors act as shorts.

Photo 1.  Emitter board

On the receiving end, the PIN photodiode should be at least faster than the sampling speed of the ADC. Our Hamamatsu S1223 - generously donated by Professor Apsel from her optoelectronics lab - meets the requirements at a cutoff frequency of 30MHz [4].  The photodiode can be placed as part of a resistor bias to a 2N3904 NPN bipolar junction transistor.  The sensitivity range of the photodiode is from visible to infrared light; by observing the variation in collector voltage and trying various resistor values, we ended up with a 4.4k-100k configuration for biasing.  The collector voltage in a well lighted room varies from 3.8V (finger on) to 3.45V (finger off), which is fed into the ADC from Port A.0. The red LED for receiver circuit operation checking does not interfere with the S1223 since it is never "on" at the separation distance we are considering.  A external comparator is not used here since the ADC is after all capable of making voltage comparisons in software. 

Other hardware constructs include the Digital-Analog Converter (DAC) to the TV from MCU from Ports D.6 and D.5, a resistor for audio from Port B.3, programming from pins [9, 8, 7, 11, 6, 10], XTAL with 22pF, and finally connecting AREF to 5V.  The details for these constructs can be found in the Appendix.  The receiver circuit, including the photodiode and the BJT, is soldered together with the MCU on one large board to cut down on cost.  The board is then taped to a stand, and placed opposite to the emitter board.  The photodiode and the laser must be aligned correctly, while leaving some room in between the two boards for a hand to pass through.

All the hardware can easily be replicated as long as the conditions and instructions that have been mentioned are followed. 

Photo 2.  Receiver and MCU board

Failed Attempts

We had initially tried to optimize recognition times by doing finger checks in between video lines, but it required the implementation of an entire FSM in every line, which would undoubtedly cause the video to not display properly.  We also attempted to initiate a timing routine near the end of the project instead of finger counting, but decided not to follow through due to the lack of project time.

....- Results of the Design

Speed of Execution

Experimentally, the trainer only supports up to approximately 25 CPM if the user is able to signal all the characters perfectly.  On an average of 5 characters per word in the English language, this translates into an upper limit of 5 WPM.  The sounds are on a per frame basis, with a dit of the length of one frame and dah at three frames.  Since there is a time interval required to check for fingers, the space in between a dit and dah is governed by this time; hence this slightly longer interval makes it a pseudo-Morse standard that is actually hard to notice aurally.  In addition, it is possible to beat a frame by chopping through the hand space extremely quickly, but it would be ridiculous to do so if one wanted to communicate properly.


If the user manages to time and signal correctly perfect accuracy can theoretically be achieved.  However, it is very easy for the user to accidentally misplace his/her hand or miss fingers, thus generating unwanted dits or dahs.   Through practice and awareness, it is possible to almost never make mistakes, although the developers cannot make the perfection claim themselves.


The key safety issue is the IR laser which potentially could be hazardous if pointed at the human eye.  To ensure that never happens, we point the laser only at the photodetector and turn on only afterwards.  The final product should be affixed to the board and should not allow a person to stick his/her head in the hand space.  

Another safety issue that was unforeseen turned out to be the hand/finger waving as it is a fairly strenuous exercise.  We advise that the user not use the system for too long (e.g. greater than half an hour continuously)  as it might lead to hand injuries, but instead take a break in between uses as with keyboards.

Interference with Other Groups

As far as RF noise is concerned, there is very little interference with other groups since we do not generate any reasonably powered RF signals.  The IR laser is blocked by the photodetector with very little reflection.  We use conventional 9V power supplies that are independent of other groups' supplies.  The speakers from the TV may have been the worse interference as a human annoyance, but we turned it down to a level that can only be recognizably heard in our station.


Some advantages of this trainer system include a better operating range than conventional keyboards - if the laser is aimed properly, zero contact serial communications, and better entertainment than conventional Morse trainers.  Disadvantages include an occasional difficulty with differentiating between dits and dahs as a result of the timing slip-ups in timing or finger space, occasional misses if the user goes too fast, strenuous hand work, and slow speed with a maximum of around 5 WPM.  

As we recognized that the first time user will have trouble figuring out how to access the Morse-based main menu, we decided to incorporate a tutorial in the main menu as long as the user signals his/her finger or hand once.  The system as a whole may not be the most intuitive and practical communication device on the planet, but it is technical feat as a collage of retro and novel ideas, such as laser hand signaling, typing tutors, Morse, and Missile Command.  Practically, at best this would be a form of entertainment for skilled Morse code learners and an interesting way to begin a beginner's Morse code learning journey.

In-Trainer Photos/Video

Photo 3.  Main Menu

Photo 4.  Tutorial Mode

Photo 5.  Sketch Mode

Photo/Video 6.  Game Mode (click to download video)

..... Conclusions

Analysis and Future Work

Our project turned out to be as what we expected in the beginning.  The finger/hand waving interface of demodulating Morse codes to characters was successfully implemented, while the tutorial, sketch, and gaming section was completed as planned.  As a basic entertainment/training system the laser Morse code trainer is complete. However, we did not manage to implement random playback capabilities (including Fansworth compression) due to time constraints, nor did we manage to change the code speed to high levels of WPM, which would very likely require a second MCU.  At this level, we believe that our system is only useful as a form of entertainment for advanced Morse code learners or as a rudimentary training device for beginners.

A redesigning of the project would entail using button presses to trigger laser transmission for a less strenuous exercise, a random playback + keypad mode, Fansworth compression, and a second MCU for speed sampling.  Furthermore, different game levels and surprises would make this a more comprehensive device a whole lot more interesting training experience, while saving score counts might be useful for recurring practices.  Finally, the sensitivity of the demodulator in recognizing the difference between dit and dah inputs might be further improved as well.

Standards & Intellectual Property

Professor Bruce Land created the base for the NTSC video generation code in Lab 4 of ECE 476.  Our Morse code system is constructed on an internationally predefined standard, taken from  The gameplay is derived from Atari's Mission Command.  Parts of laser diode emitter and receiver setup, as well as safety labels, are credited to Sam's Laser FAQ

The rest of the hardware and software setup is designed by ourselves.  We do not believe that any patent opportunities exist since our project is more of a novelty/entertainment system than a fully practical trainer for ham radio amateurs.

Ethical Considerations

There are five points taken into consideration out of the IEEE Code of Ethics:

3.  To be honest and realistic in stating claims or estimates based on available data;
We were honest about the limitations of the Morse code trainer, e.g. it is incapable of reaching extremely high speeds (> 5 WPM) and has occasional inconsistencies with finger counting.  We believe that it is better for us to state the limitations publicly such that improvements can be made in the future, and such that highly skilled Morse code learners should use our system for entertainment purposes only.

5.  To improve the understanding of technology, its appropriate application, and potential consequences;
We have added a new dimension to the applications of laser technology by adding finger counting to the list, while learning ourselves the various aspects of old communication technology (Morse code).  We have created a possible learning tool using a combination of laser, microcontroller, and video technology, while improving our own understanding in these areas.

6.  To seek, accept, and offer honest criticism of technical work, to acknowledge and correct errors, and to credit properly the contributions of others;
From our initial project with the laser microphone, we accepted criticism from the TAs and Professor Land that the beam signal was far too weak to be implemented - and hence we began this project instead.  Some of our classmates (along with ourselves) also gave us feedback on the project, which we took to heart to improve.  We credit Professor Land for the NTSC non-interlaced video generation code, Professor Apsel for the Hamamatsu S1223 photodiode, the TAs for their comments and help on finding parts, Morse code website administrators, and others who we did not mention. 

8.  To treat fairly all persons regardless of such factors as race, religion, gender, disability, age, or national origin;
We strongly believe that our system, if properly translated, can be universally used.  In and out of our design process, we respected all other lab groups and their work, extending to universal users of our project.

9.  To avoid injuring others, their property, reputation, or employment by false or malicious action;
We were very careful not to point the laser diode at any individual.  Furthermore, we turned off solder irons when not in use, took care of cleaning up our stations, turned down speaker volumes, and respected other groups' properties by not touching them - even when they appear to have discarded certain items.

-.... Appendices

Appendix 1: Commented Program Listing

The code is extremely long and is divided into three sections:

project_header.h - all video functions and newly created bitmaps
morse_header.h - Morse code binary tree using pointers
project.c - main project file with all main state machines

Appendix 2: Schematics

Appendix 3: Cost

Part Name Quantity Digikey # Total Cost Origin
Atmel Mega32 MCU 1 N/A $8.00 Lab
16MHz crystal 1 N/A $0.00 Lab
2N3904 bipolar transistor 1 N/A $0.00 Lab
Resistors/Capacitors/LED Various N/A $0.00 Lab
IR Laser Diode (780nm) 1 38-1028-ND $24.00 Digikey
Large solder board 1 N/A $2.50 Lab
Small solder board 1 N/A $0.80 Lab
Wooden frames + Nails + Tape Various N/A $0.00 Self
Hamamatsu S1223 PIN photodiode 1 N/A $0.00 (from Prof. Apsel)
  TOTAL $35.30  

Appendix 4: Division of Labor



Appendix 5: Links

[1] Learn Morse Code

[2] NuMorse Professional, the ultimate Morse code trainer

[3] Sam's Laser FAQ

[4] Digikey - US Lasers Infrared Laser Diode [780nm, 5mW, 5.6mm]

[5] Hamamatsu S1223 PIN photodiode

[6] Atmel Mega32 Datasheet

[7] NTSC video generation via Mega32 by Professor Land