Arduino based Morse Code Generator

8,368 views

Here in this instructional exercise, we will give you a complete guide on how to make a “Morse Code generator using Arduino” in detail. However, it will accept any input character from the serial monitor and convert it into Morse code proportional blares by a buzzer.

Morse Code?

Meanwhile, a Morse code is an arrangement of correspondence to encode any character in two unique duration of signals called Dots and Dashes. Generally, s Morse code is created by Samuel F.B. also, further used in telecommunication for moving confidential data.

The use of this Morse code was widespread during World War II. However, a Morse code can be performed by tapping, blazing light, or writing. The Morse code is accessible in two forms, the original and the universal model.

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

Hardware Required

The required hardware components for making Arduino based Morse Code Generator are:

S. noComponentValueQty
1.ArduinoUNO1
2.Jumper wires
3.Buzzer1
4.Breadboard1

Circuit Diagram

Working Explanation

Under this heading, we will discuss the working of the project “Morse Code Generator.” In this circuit, we are using a few low-cost components that include an Arduino, jumper wires, buzzer, and breadboard. The working of the circuit is likewise simple and easy. Firstly, interface the buzzer’s positive pin to the eighth pin of the Arduino UNO and the negative pin to the ground of Arduino.

Now, Transfer the code utilizing Arduino IDE and type the characters on the serial monitor to generate the buzzer sound. An LCD can be added with Arduino to show the dots and dash.

Code

 

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;
  }
}