- AR-AD1: Sanguinoscope Blood Group Typing Project
- AR-AD2: Arduino Advanced Calculator
- AR-AD3: Arduino based Fastest Figure First Controlling System for Quiz Competition
- Convert Text into Morse Code with beeps & back into Text with Arduino
What is Morse Code?
Morse code is a method of communication that uses short and long signals, represented by dots and dashes, to represent letters, numbers, and punctuation.
It was invented in the 1830s and 1840s by Samuel Morse to be used with the telegraph, an early electrical communication system.
Let us understand details of Morse code:
Signals: Morse code uses two basic signal lengths: dots (short) and dashes (long).
Encoding: These dots and dashes are combined in specific sequences to represent letters, numbers, and punctuation.
Transmission: Morse code can be transmitted in a variety of ways, including electrical pulses, sound beeps, or light flashes. While less common today, Morse code was once a vital tool for long-distance communication. It played a significant role in the early days of the telegraph and even had applications in maritime communication and early radio.
Morse Code Reference Chart
How to construct the project?
For that you need following material –
- Arduino UNO/ Arduino Nano
- Data cable
- Buzzer
- Jumper Wires
Make sure that Arduino IDE Software is installed on your PC. If not you can download it and install.
Now let us see the code and the connection details to construct the circuit.
The Code
/* * Written by: Prof. Yash Vidyasagar * for Vidyasagar Academy's Robotics Course students * Lab tested code. No errors...!!! */ const int buzzerPin = 11; // Pin connected to the buzzer const int dotDuration = 100; // Duration of a dot in milliseconds const int dashDuration = 300; // Duration of a dash in milliseconds const int letterSpace = 300; // Space between letters const int wordSpace = 700; // Space between words // Morse code representation String morseCode[36] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." }; // Function to convert a character to Morse code String charToMorse(char c) { if (c >= 'A' && c <= 'Z') { return morseCode[c - 'A']; } else if (c >= 'a' && c <= 'z') { return morseCode[c - 'a']; } else if (c >= '0' && c <= '9') { return morseCode[c - '0' + 26]; } return ""; } // Function to beep the Morse code void beepMorse(String morse) { for (int i = 0; i < morse.length(); i++) { if (morse[i] == '.') { digitalWrite(buzzerPin, HIGH); delay(dotDuration); digitalWrite(buzzerPin, LOW); } else if (morse[i] == '-') { digitalWrite(buzzerPin, HIGH); delay(dashDuration); digitalWrite(buzzerPin, LOW); } delay(dotDuration); // Space between dots and dashes } } void setup() { Serial.begin(9600); pinMode(buzzerPin, OUTPUT); Serial.println("Enter a string to convert to Morse code:"); } void loop() { if (Serial.available() > 0) { String input = Serial.readStringUntil('\n'); Serial.println("Input: " + input); Serial.print("Morse Code: "); for (int i = 0; i < input.length(); i++) { char c = input[i]; if (c == ' ') { delay(wordSpace); Serial.print(" | "); } else { String morse = charToMorse(c); Serial.print(morse + " "); beepMorse(morse); delay(letterSpace); } } Serial.println(); } }
Connection Details
- Actually the connections of this project are very simple.
- Just take a breadboard and fix buzzer on it.
- Take Arduino Uno / Arduino Nano and connect its pin-11 to +ve terminal of the buzzer.
- Connect -ve terminal of the buzzer to ground (GND) of Arduino.
Procedure
- Connect Arduino to your PC through data cable and upload the above given code.
- Then open serial monitor and type a word “Hi” in it.
- You will hear six beeps from the buzzer and after that you will see the Morse Code of the word “Hi”.
- The Morse Code of the word “Hi” is 4 dots then a space and then 2 dots, like this: . . . . . .
- In this way, you can convert text like a long sentence into corresponding Morse Code with beeps and after that you get the corresponding Morse Code value of the text, that you had entered.
Hope you liked the project. Please let us know your feedback below in comments area. You can comment below to get the guidance about converting Morse Code into corresponding text.