Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 12 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 3 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 2 | |||
Software apps and online services | ||||||
![]() |
| |||||
![]() |
|
Morse Code Encrypter converts the entered text and numbers into Morse Code (a series of dashes and dots). The same dashes and dots can be seen in the interfaced LED in the circuit and the project.
The entered text and numbers can be seen in the LCD display. The same was also tried with Raspberry Pi 4
It was made as a part of a project-based internship. I also simulated the project on TinkerCAD and implemented it physically. The video of both is available via YouTube link below.
Circuit Diagram
The only challenging part in this project is to interface the LCD Display with the Arduino board and breadboard. You could refer a YouTube Tutorial on how to do that. Once that is clear, it is pretty easy to turn the texts and numbers of our choice into Morse Code.
//Morse Code Encoder and Decoder using C++
/* We could replace the LED's with relays and attach a torch
so that it seems the Torch is encoding and decoding
the Morse Code
*/
#include<LiquidCrystal.h>
LiquidCrystal lcd{1,2,7,8,10,11};
int LED_diode = 9;
const struct {char key, *value;} morse[] = {
// Alphabets
{'A', ".-"},
{'B', "-..."},
{'C', "-.."},
{'D', "-.."},
{'E', "."},
{'F', "..-."},
{'G', "--."},
{'H', "...."},
{'I', ".."},
{'J', ".---"},
{'K', "-.-"},
{'L', ".-.."},
{'M', "--"},
{'N', "-."},
{'O', "---"},
{'P', ".--."},
{'Q', "--.-"},
{'R', ".-."},
{'S', "..."},
{'T', "-"},
{'U', "..-"},
{'V', "...-"},
{'W', ".--"},
{'X', "-..-"},
{'Y', "-.--"},
{'Z', "--.."},
// numbers
{'1', ".----"},
{'2', "..-----"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{'9', "----."},
// special characters
{'!', "-.-.--"},
{'/', "-..-."},
{'.', ".-.-.-"},
{',', ".-.-.-"},
{'(', "-.--."},
{')', "-.--.-"},
{'&', ".-..."},
{':', "---..."},
{';', "-.-.-."},
{'=', "-...-"},
{'+', ".-.-."},
{'-', "-....-"},
{'_', "..--.-"},
{'?', "--..--"},
{'\'',".----."},
{'"', ".-..-."},
{'$', "...-..-"},
{'@', ".--.-."},
};
size_t morseSize = sizeof(morse)/sizeof(*morse);
char *encode(const char key)
{
for(size_t i = 0; i < morseSize; i++)
if(morse[i].key == key)
return morse[i].value;
return "";
}
void enlight(const int &LED_diode, const char* morse)
{
for(size_t i = 0; i < strlen(morse); i++)
{
digitalWrite(LED_diode, HIGH);
morse[i] == '.' ? delay(300) : morse[i] == '-' ? delay(900) : delay(600);
digitalWrite(LED_diode, LOW);
delay(600);
}
delay(1200);
}
void render(const int &LED_diode, const String msg)
{
Serial.print("Encoding message: ");
Serial.println("Look at the LED in the circuit");
Serial.println(msg);
for(size_t i = 0; i < msg.length(); i++)
{
//Serial.print("Decoding this letter: ");
//Serial.print(msg.chartAt(i));
char *morse = encode(toupper(msg.charAt(i)));
//Serial.print(" => ");
//Serial.println(morse);
enlight(LED_diode, morse);
}
Serial.print("Encoded message is: ");
Serial.println(msg);
}
String message = "h1";
// Initialisation du programme
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
Serial.println("Begin the process: ");
pinMode(9, OUTPUT);
render(9, message);
}
// Boucle principale
void loop()
{
if(Serial.available() > 0)
{
message = Serial.readString();
//lcd.print("M:");
lcd.setCursor(1,0);
lcd.print(message);
lcd.clear();
if(message != "")
{
Serial.print("Recieved message is: ");
Serial.println(message);
render(9, message);
}
}
}
Morse Code
C/C++Code for the Arduino IDE. This is a longer code. For a more clear and concise code, you could refer to the second file.
const int led = 7;
String code = "";
int len = 0;
char ch;
char new_char;
int unit_delay = 250;
void dot()
{
Serial.print(".");
digitalWrite(led, HIGH);
delay(unit_delay);
digitalWrite(led, LOW);
delay(unit_delay);
}
void dash()
{
Serial.print("-");
digitalWrite(led, HIGH);
delay(unit_delay * 3);
digitalWrite(led, LOW);
delay(unit_delay);
}
void A()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void B()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void C()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void D()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void E()
{
dot();
delay(unit_delay);
}
void f()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void G()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void H()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void I()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void J()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void K()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void L()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void M()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void N()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void O()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void P()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
}
void Q()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void R()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void S()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void T()
{
dash();
delay(unit_delay);
}
void U()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void V()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void W()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void X()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void Y()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void Z()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void at_the_rate()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void exclaim()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void full_stop()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void one()
{
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void two()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void three()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void four()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dash();
delay(unit_delay);
}
void five()
{
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void six()
{
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void seven()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void eight()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
dot();
delay(unit_delay);
}
void nine()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dot();
delay(unit_delay);
}
void zero()
{
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
dash();
delay(unit_delay);
}
void morse()
{
if (ch == 'A' || ch == 'a')
{
A();
Serial.print(" ");
}
else if (ch == 'B' || ch == 'b')
{
B();
Serial.print(" ");
}
else if (ch == 'C' || ch == 'c')
{
C();
Serial.print(" ");
}
else if (ch == 'D' || ch == 'd')
{
D();
Serial.print(" ");
}
else if (ch == 'E' || ch == 'e')
{
E();
Serial.print(" ");
}
else if (ch == 'f' || ch == 'f')
{
f();
Serial.print(" ");
}
else if (ch == 'G' || ch == 'g')
{
G();
Serial.print(" ");
}
else if (ch == 'H' || ch == 'h')
{
H();
Serial.print(" ");
}
else if (ch == 'I' || ch == 'i')
{
I();
Serial.print(" ");
}
else if (ch == 'J' || ch == 'j')
{
J();
Serial.print(" ");
}
else if (ch == 'K' || ch == 'k')
{
K();
Serial.print(" ");
}
else if (ch == 'L' || ch == 'l')
{
L();
Serial.print(" ");
}
else if (ch == 'M' || ch == 'm')
{
M();
Serial.print(" ");
}
else if (ch == 'N' || ch == 'n')
{
N();
Serial.print(" ");
}
else if (ch == 'O' || ch == 'o')
{
O();
Serial.print(" ");
}
else if (ch == 'P' || ch == 'p')
{
P();
Serial.print(" ");
}
else if (ch == 'Q' || ch == 'q')
{
Q();
Serial.print(" ");
}
else if (ch == 'R' || ch == 'r')
{
R();
Serial.print(" ");
}
else if (ch == 'S' || ch == 's')
{
S();
Serial.print(" ");
}
else if (ch == 'T' || ch == 't')
{
T();
Serial.print(" ");
}
else if (ch == 'U' || ch == 'u')
{
U();
Serial.print(" ");
}
else if (ch == 'V' || ch == 'v')
{
V();
Serial.print(" ");
}
else if (ch == 'W' || ch == 'w')
{
W();
Serial.print(" ");
}
else if (ch == 'X' || ch == 'x')
{
X();
Serial.print(" ");
}
else if (ch == 'Y' || ch == 'y')
{
Y();
Serial.print(" ");
}
else if (ch == 'Z' || ch == 'z')
{
Z();
Serial.print(" ");
}
else if (ch == '0')
{
zero();
Serial.print(" ");
}
else if (ch == '1')
{
one();
Serial.print(" ");
}
else if (ch == '2')
{
two();
Serial.print(" ");
}
else if (ch == '3')
{
three();
Serial.print(" ");
}
else if (ch == '4')
{
four();
Serial.print(" ");
}
else if (ch == '5')
{
five();
Serial.print(" ");
}
else if (ch == '6')
{
six();
Serial.print(" ");
}
else if (ch == '7')
{
seven();
Serial.print(" ");
}
else if (ch == '8')
{
eight();
Serial.print(" ");
}
else if (ch == '9')
{
nine();
Serial.print(" ");
}
else if(ch == ' ')
{
delay(unit_delay*7);
Serial.print("/ ");
}
else if(ch == '@')
{
at_the_rate();
Serial.print(" ");
}
else if(ch == '!')
{
exclaim();
Serial.print(" ");
}
else if(ch == '.')
{
dot();
Serial.print(" ");
}
else
Serial.println("Unknown symbol!");
}
void String2Morse()
{
len = code.length();
for (int i = 0; i < len; i++)
{
ch = code.charAt(i);
morse();
}
}
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
Serial.println("Type the message to be encoded.");
delay(7000);
Serial.println("Message is being encoded, look at the lED in circuit");
}
void loop() {
while (Serial.available())
{
code = Serial.readString();
Serial.print(code);
Serial.print(" = ");
String2Morse();
Serial.println("");
}
delay(1000);
}
Comments
Please log in or sign up to comment.