Arduino Morse Code Generator

Introduction: Arduino Morse Code Generator

Hey guys! I built an Arduino Morse code generator, a device that can turn any chain of words entered into a string of Morse code. The device implements the use of the serial port to control the Arduino’s output Morse code, so a computer is needed for this to work. I have provided the code and circuit routing below, and I will try my best to explain every single thing about this project. If you have any questions or suggestions feel free to comment. Constructive feedback is always welcome!

Supplies

First off, the materials. This project focuses mainly on software-related techniques, so the materials are easy to purchase and the circuits are a piece of cake too.

What you need:

Computer (to control the serial port inputs)

USB cable (to control the serial port inputs)

Arduino board (any can do)

Wires

5V LED

Speaker or Buzzer (choose 1)

Cardboard

Scissors and Tape

Breadboard (optional)

Welding tools (optional)

Where to Get Supplies:

Arduino boards are available on almost every online retailer, they usually come with a USB cable during purchase. If not, then you may buy them separately online or from your local hardware retailer. This is where you’ll find the LEDs, speakers, buzzers, and welding tools you’ll need as well. Be aware that shipping may be delayed or canceled during this period of COVID-19, so if you are in a hurry, avoid buying online. Also, check that your Arduino boards are from reliable sellers as there are many counterfeit Arduino boards out there. If the boards you buy are too cheap, then be extra careful. For the LEDs, I recommend getting a white or red led, as they are the clearest when you flash them quickly during a string of Morse Code. I used a speaker in my model, but feel free to use a buzzer if you like. The buzzer’s code and connection are a tad bit different than a speakers', so be extra careful when handling the code if you are using a buzzer.

Step 1: Curcuit Assembly

When connecting the components to the Arduino board, you may use a breadboard, which makes the wire connections way easier. Or, if you want to make a more permanent and lasting project, consider welding the wires. As for me, I used some pliers to tangle the wires together to connect them. You won’t need to buy anything extra or know how to weld to do this. In addition, it saves space by removing the breadboard, allowing you to make the device even more compact if that’s what you’re going for. The only downside is that they aren’t as secure compared to the other methods. Also, be aware of the digital pins used in this project when assembling the components. The pin for the LED is 13 and the pin for the speaker is 5. Do not connect the wrong pins otherwise the code might not work for you. When connecting the LED, the positive and negative charges of the LED are important. One way to tell the charges is from the “legs” of the LED. The longer leg is the positive side, so connect that directly to pin 13. We can control the LED with the function digitalWrite(13, HIGH) and digitalWrite(13, LOW) to turn the LED on and off. For the shorter leg, connect it first to the resistor and then connect the resistor to a pin called GND. GND is the equivalent to the negative charge. For the speaker, the positive and negative sides should be marked with black and red wires, if not then often the brighter color is the positive and the darker color is negative. Connect the positive end to pin 5 so we can control it with our code, and the negative side to GND. Your board should have at least 2 GND pins, so there should be enough pins.

Step 2: Code

Next is the code. Copy and paste the code below into Arduino IDE and upload it to your board with your USB cable. If uploading is taking a lot of time, press the white “reset” button and upload again.

The code consists of 4 main sections, and I will go through them each briefly; for details please check the annotations done in the code file.

CLICK FOR CODE

Setup

For the setup of our code, we set the bitrate of the serial monitor to 9600 baud. A serial monitor is a tool in Arduino that lets you talk to your board using the USB cable that connects them. You can send characters to the Arduino and the Arduino can send characters back to you. The serial monitor can be found in the top toolbar --> TOOLS --> Serial Monitor, or you can use the keyboard shortcut Ctrl + Shift + M to open it.

Variable & Function Declaration

Next we need to declare all of the functions and variables used in the code. The only variable in our code is the character named “val”. We tell Arduino that this is a character by adding the words “char” before it. A “char” variable can represent any character (numbers, letters, symbols, and I will explain the use of it later. We just let the Arduino know first that the three words “val” represent a character. Then, we use functions to declare the dash, dots, and pauses of the Morse code. Functions are like variables, but they are used to represent a bundle of commands. Once the function is declared, the user only needs to type the name of the function to use it, which saves space and time. Because in our code we need to constantly keep closing and opening our LED and speaker, using a function to represent the commands will keep the code short and understandable.

Main Loop

Then we move on to the main loop. Here we tell the Arduino to read the data sent by the computer and assign the value read from the computer to be the variable “val”. For example: if the character “A” is typed into the serial monitor, the code will turn the variable val to be A.

Switch Case Function

Once val is assigned a character, we move on to the translation of the characters. We use a function called “switch case” to include all the cases we need for the 26 alphabet and 10 numbers. This is why we needed the char val, because the switch function can only work with a character. The function switch case assigns a set of commands to be done with each different input of the serial monitor. Each case stands for what the board should do if the val equals that character. From here we can see the functionality of the functions mentioned earlier, as they save a lot of space and memory.

Step 3: Exterior Casing

For the casing outside, you can make any sized box you like. I used a box with these dimensions, but you don’t have to follow this as the box I made was for an Arduino Leonardo. As long as the box can fit everything in, it is fine. If you have an Arduino nano, then you could probably fit it in a very small box. You could also use 3D printing or laser-cut wood to make your box sturdier. But remember to leave holes for the LED and USB connector to peek out. It would also be a good idea to include a latch that exposes the board just in case you need to repair it.

8cm x 2cm piece x2

14cm x 8cm piece x2

14cm x 2cm piece x2

Step 4: Testing

One last thing to do before sealing the board into the box is to test the code. Make sure the speaker and LED are working properly, and the serial monitor inputs are working as well. If you have any issues, comment below! Most common problems can be solved by compiling the code in Arduino IDE, as it catches most simple errors. To use the translator, you will need to key in the letters in FULL CAPS, and the spaces will need to be “_”. To use it, open the serial monitor and set the line ending into “Both NL and CR”. Type in the phrase and press enter to translate.

Step 5: Putting Everything Together

Once the software and hardware are set, you are ready to put everything together! Secure the board and speaker in the box, and put the LED through the hole you left in the box for it. After that seal the box and voila! You have your very own Morse Code Generator!

Step 6: Tips

You can change the delay and length of the dashes and dots by changing the functions in the code. Sometimes the dots are too short that they sound like one long dash. This is why testing is important. This is another great part of functions. Once you edit the function, all of the places using the function will automatically change as well. Functions are particularly useful in this project.

Here are the official lengths of signals for Morse code if you are interested:

Dot – 1 unit long

Dash – 3 units long

Space between letters – 3 units long

Space between words – 7 units long

Be the First to Share

    Recommendations

    • First Time Author Contest

      First Time Author Contest
    • Fandom Contest

      Fandom Contest
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    Comments