What is Morse Code?

How do you read Morse code? What is Morse Code used for? Is it difficult to learn Morse code?

In this blog, we will talk about the Morse Code. We will discuss why Morse Code was invented and how to read it. We will also look at the applications of Morse Code.

An image that explains what is morse code.

Dec 11, 2023    By Team YoungWonks *

Introduction to Morse Code

Morse code is a method of transmitting textual information in the form of a series of on-and-off tones, lights, or clicks that a trained listener or observer can easily understand without the use of special equipment. It was invented in the 1830s and 1840s by Samuel F.B Morse (aka Samuel Morse) and Alfred Vail for use with the telegraph, an early form of electronic communications system. Americans initially used Morse code primarily in the context of telegraphy. Morse code employs a unique set of signals, such as dots and dashes, rather than letters of the alphabet, to represent the phonetic elements of a language, showcasing a distinctive encoding system for communication.

History of Morse Code

The invention and widespread adoption of the telegraph systems in the 19th century revolutionized long-distance electronic communication. Morse code was widely used in telegraphy, particularly in sea and air communications. It is still used in amateur radio operators and some emergency services today. It is also used to teach telegraphy and can be a useful alternative to written or spoken languages for people with certain disabilities. In the complex landscape of communication, Morse code, often described as God's gift to connectivity, tells a story of simplicity and universality, where the divine precision of dots and dashes surpasses language barriers.

American Morse Code

American Morse code became instrumental for the first time, during World War II as a means of communication of text messages, particularly in distress situations, sending distress signals. 

Employed extensively by the U.S. Navy and Coast Guard, Morse code played a pivotal role in relaying crucial information via telegraph lines and radio waves. Its simplicity and efficiency made it an indispensable code system for encoding and decoding messages. Learning Morse code became a vital skill, especially for telegraph operators who used a Morse key to send electrical pulses that translated into dots and dashes representing the English language, numerals, and even Latin characters. This code system, originally designed for the electric telegraph, found application in various forms of telecommunication, extending from the early use of telegraph lines between Washington, D.C., and Baltimore to the playback of Morse code messages over radio.

In the early days of telecommunication, operators mastered the art of Morse code by engaging in rigorous practice sessions, perfecting their skills through the playback of recorded signals over telegraph lines. Even today, Morse code retains significance, particularly in emergency situations and among hobbyists, showcasing its enduring legacy in the evolution of communication technologies.

International Morse Code

The widespread adoption of Morse code in the 19th century connected communication networks not only across America but also bridged the Atlantic, enabling swift transmission of messages between North America and Europe via telegraph lines.

During World War II, British operatives extensively utilized Morse code for covert communication, sending encrypted Morse code messages to coordinate strategic operations. The effectiveness of the British reliance on Morse code played a crucial role in maintaining secure lines of communication, allowing for discreet exchanges of information in the midst of wartime challenges. The use of Morse code by British intelligence became an integral part of their clandestine efforts, demonstrating the code's enduring significance in military communication strategies.

How do you read Morse code?

Morse code is made up of two basic elements: a period (.) and a hyphen (-) representing dits and dahs. In Morse code, dits are short bursts of sound or light, while dahs are long bursts. Such signals were used for long distance communications. 

Letters of the alphabet are represented by distinct patterns of dots and dashes. In English, the letter A, for example, is represented by a single dot following by a dash, whereas the letter B is represented by a dash followed by three dots.

To read Morse code, you need to familiarize yourself with these combinations. You then interpret the series of dots, dashes, and spaces you receive into the corresponding characters they represent. For example, if you see '.-', it translates to 'A' in English, and '....-' signifies the number '4'. Remember that the space between parts of the same letter is shorter than the space between two different letters or words. This spacing is what allows you to differentiate between separate characters. 

What is Morse Code used for?

Morse code has several applications. Some of them are:

  • Morse Code is used in telecommunications, especially in situations where voice communication is not possible or practical.
  • It is used in aviation and nautical industries for sending distress signals, traditionally known as an SOS signal.
  • Amateur radio enthusiasts and ham radio operators often use Morse Code as a form of basic communication.
  • Morse Code has been used in assistive technology to provide communication capabilities to people with disabilities, using a series of "dots" and "dashes" to represent letters and numbers.
  • It has also been used in military operations for secure and discreet communication.

Transmit Morse Code using Raspberry Pi

In this project, we'll use a Raspberry Pi and an LED to convert text into Morse code and blink the LED to transmit the message.

To build this project, you will need the following:

  • A Raspberry Pi: You can use any model of Raspberry Pi; however, it is recommended to use a Raspberry Pi 3. Even a pi 0 will just work out of the box.
  • An LED: You can use any color LED, but make sure it's the right size to fit in the breadboard or PCB board you're using.
  • A 220-ohm resistor: This is used to limit the current flowing through the LED, protecting it from damage. Ensure you have used a resistor, otherwise, the current may be too much and can burn off the LED.
  • Breadboard or PCB board: This is used to connect the LED and resistor to the Raspberry Pi.
  • Jumper wires: These are used to connect the components on the breadboard or PCB board to the Raspberry Pi.
  • Power supply to power the Raspberry Pi. Remember, to ensure the use of a well-regulated 5V power supply. I would recommend the use of the default 5V adapter from the Raspberry Pi, otherwise, the use of a power bank is best suited. Ensure your power bank can output 5V 3A for a pi3.
  • An SD card with the latest version of Raspberry Pi OS installed. If you have not flashed the Operating system and haven't set up the pi before, check out this blog that will help you with setting up the pi in headless mode.
  • You will need to have a basic knowledge of Python programming and how to use the terminal on Raspberry Pi. Even if you lack basic knowledge, grab a cup of coffee and tag along through this blog.
  • A computer with internet access to download the necessary software and libraries for the project.
  • A keyboard and monitor for your Raspberry Pi, or access to a remote terminal to run the Python script on the Raspberry Pi.

You'll need a Raspberry Pi, an LED, and a 220-ohm resistor to get started. Connect the LED to the Raspberry Pi's GPIO pins, with the positive (longer) leg to the GPIO pin and the negative (shorter) leg to the resistor. The resistor's other end should be attached to a GND pin on the Raspberry Pi. The longer leg is the LED's positive terminal, while the shorter leg is the LED's negative terminal. Refer to the circuit connection schematic below and connect the components as shown.

Next, we'll need to write a program that will convert text into Morse code and blink the LED to transmit the message. The program will use the Python programming language and the RPi.GPIO library, which allows us to control the GPIO pins on the Raspberry Pi. 

You will need a code editor like the Python Thonny editor to write the code. 

Step 1: Import the necessary packages

Let’s go ahead and import the necessary packages. We need the GPIO module to access the GPIO pins on the Raspberry Pi. We need the time module to differentiate between dashes and dots when we visualize the output.

import packages python

Step 2: Setup the board pinout mode and GPIO pins

We shall next go ahead and set the board pinout mode. There are two ways of accessing the pins and using the GPIO.BOARD method, it becomes easier to count the pin numbers. You can also use GPIO.BCM and look at the pin numbers and access them with the GPIO pin name.

If you intend to use GPIO.BCM set the pin number to 17. You can alternatively use any pin from the RPI board and make the changes to the code accordingly.

gpio setmode python

Step 3: Create the Morse Code dictionary

Next, let us go ahead and type the morse dictionary up. Here’s the dictionary for the international morse code.

international morse code

Dictionaries are data structures to store key-value pairs of data. To know more about dictionaries, read our Python dictionaries blog.

Step 4: Write a function to blink the LED

Now we shall go ahead and write a function that blinks the LED. The function accepts 2 arguments, pin and duration. We shall use the same function with varied time duration to represent dots and to represent dashes.

blink led python

Step 5: Write a function to generate the Morse Code

We shall finally write a function that loops through an input string and creates an output string using the dictionary. We need to convert every character to its upper case because our dictionary defines Morse code only for upper case characters. The variable morse_code stores the morse code up. Wherever there is a space, we append the space to the morse_code as it is.

convert to morse code

Step 6: Accept the user input

We shall now finally accept user input, convert it to its morse code, run a for loop across the morse code string, and retrieve the output.

There’s no light when there is a space character in the morse code string to distinguish between different words. Finally, we use GPIO.cleanup() to free up the GPIO pins after the program has finished running. Hence, we complete our code today.

python morse code

Camera and OpenCV to take it further!

We have successfully built a Morse code converter that can translate text into Morse code signals and display them as blinking lights. However, we can take this project further by using a camera to read the Morse code signals from the blinking LED and decode them into text. This requires knowledge of image processing and computer vision techniques, as well as programming skills in Python and OpenCV. While challenging, this project can be a great way to explore the intersection of hardware and software, and to gain hands-on experience with computer vision and signal processing. With a little bit of creativity and tinkering, the possibilities for using Raspberry Pi and other devices to decode and transmit signals are endless. 

At YoungWonks, we believe in fostering a love for technology and coding in children from an early age. That's why we offer a variety of specialized Coding Classes for Kids, tailored to different age groups and interests. If your child is interested in diving deeper into a specific coding language, our Python Coding Classes for Kids provide a more focused approach. For those ready to tackle hardware, our Raspberry Pi, Arduino and Game Development Coding Classes are a fantastic way to combine programming with physical computing.

What is Morse Code?

Frequently asked questions related to Morse Code

The following are some of the frequently asked questions related to Morse Code.

What is the Morse code for the letter A?

The Morse code for the letter "A" is '.-'. 

What is SOS in Morse Code?

In Morse code, "SOS" is signified by three short signals, followed by three long signals, then three short signals again. This distinctive pattern, represented as "...---...", is universally recognized as a distress signal in radio communication.

What is help in Morse Code?

The word "HELP" in Morse code is written as ".... . .-.. .--.". Each letter is represented by a unique sequence of dots (.) and dashes (-), with "H" being "....", "E" being ".", "L" being ".-..", and "P" being ".--.".

*Contributors: Written by Prasanna Gurumallapla; Edited by Rohit Budania; Lead image by Shivendra Singh

This blog is presented to you by YoungWonks. The leading coding program for kids and teens.

YoungWonks offers instructor led one-on-one online classes and in-person classes with 4:1 student teacher ratio.

Sign up for a free trial class by filling out the form below:

By clicking the "Submit" button above, you agree to the privacy policy
Share on Facebook Share on Facebook Share on Twitter Share on Twitter
Schedule a free trial class help