Introduction: Arduino Morse Code Generator | SOS Morse Code Arduino

Hi guys in this instructables we will learn how to create different MORSE code with Arduino. Since Morse code is very popular specially SOS morse code but you can make any of your choice. We will discuss this further in our instructables.

Step 1: Things We Need

For this instructables we will need following things :

Arduino Uno :
Buzzer
Breadboard :
Jumper wires :

Step 2: About Morse Code

Morse code is a system of communication to encode any character in two different durations of signals called Dots and Dashes. Morse code is developed by Samuel F.B. and further used in telegraphy for transferring secret information. It was most used at the time of World War II. A Morse code can be performed by tapping, flashing light or writing. The Morse code is available in two versions, the original and the international morse code. In the international morse code, the original version is modified by removing spaces and designing the dashes in a specific length. The Morse code is available for encoding alphabets and numbers. It is mainly used in the radio and ocean communication and also a part of training for soldiers.


The language has always been the barrier for the Morse code, as it’s hard to perform the code for diacritic characters in other language. There are some famous words considered as important feature of Morse code like ‘SOS’. SOS full form is Save Our Souls created as a universal distress signal represents danger.

The below image shows the Morse code for the alphabets from A to Z.


Today in this tutorial we will build a Morse Code Translator using Arduino which will take any character as an input from serial monitor and convert it into Morse code equivalent beeps by buzzer.

Step 3: Schmatics

Please follow the shown schmatics and connect everything According to the schmatics.

Step 4: Code

Please copy the following code and upload it to your arduino Board :

char stringToMorseCode[] = "";
int audio8 = 8; // output audio on pin 8
int note = 1200; // music note/pitch
int dotLen = 100; // length of the morse code 'dot'
int dashLen = dotLen * 3; // length of the morse code 'dash'
void setup() {
Serial.begin(9600);
}
void loop()
{
char inChar = 0;
char inData[100] = ""; // data length of 6 characters
String variable = "";
String variable1 = "";
int index1 = 0;

if ( Serial.available() > 0 ) { // Read from Rx from atmega16
while (Serial.available() > 0 && index1 < 100) // read till 6th character
{
delay(100);
inChar = Serial.read(); // start reading serilly and save to variable
inData[index1] = inChar;
index1++;
inData[index1] = '\0'; // Add a null at the end
}
variable.toUpperCase(); // convert to uppercase
for (byte i = 0 ; i < 100 ; i++) {
variable.concat(String(inData[i])); // concat strings
}
delay(20);
}
String stringToMorseCode = String(variable);
for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++)
{
char tmpChar = stringToMorseCode[i];
tmpChar = toLowerCase(tmpChar);
GetChar(tmpChar);
}
}
void MorseDot()
{
tone(audio8, note, dotLen); // start playing a tone
delay(dotLen); // hold in this position
}
void MorseDash()
{
tone(audio8, note, dashLen); // start playing a tone
delay(dashLen); // hold in this position
}
void GetChar(char tmpChar)
{
switch (tmpChar) {
case 'a':
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'b':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 'c':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 'd':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 'e':
MorseDot();
delay(100);
break;
case 'f':
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 'g':
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 'h':
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 'i':
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 'j':
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
break;
case 'k':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'l':
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 'm':
MorseDash();
delay(100);
MorseDash();
delay(100);
break;
case 'n':
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 'o':
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
break;
case 'p':
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 'q':
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'r':
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
break;
case 's':
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
case 't':
MorseDash();
delay(100);
break;
case 'u':
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'v':
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'w':
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
break;
case 'x':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
break;
case 'y':
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDash();
delay(100);
MorseDash();
delay(100);
break;
case 'z':
MorseDash();
delay(100);
MorseDash();
delay(100);
MorseDot();
delay(100);
MorseDot();
delay(100);
break;
default:
break;
}
}

Step 5: Generating Morse Code.

After uploading the code to arduino board then type any character into the serial monitor and hit the enter button to send the characters to the Arduino.
Here we have typed ‘SOS’ which is a universal distress signal, to create the sound for the same.