Skip to main content

33. Morse Code Encoder

Hello everyone!
Today I am going to teach you about making a Morse code encoder. Morse code is a character encoding scheme used in telecommunication, and is named after Samuel F. B. Morse, an inventor of the telegraph. You would have probably seen movies where spies or secret agents transmit secret messages in form of Morse code. Actually, according to Crypto Museum, Morse code was heavily used for secret transmissions during WWI and WWII. Morse code 
I have used a Green LED and Active Buzzer in this project, so that people with hearing disabilities and visual impairment, respectively can decipher Morse Code. As you can see in the image above, the Morse code is composed of 'dot' and 'dash'. Dot is one unit long and dash is three units long. 
I have prepared my sketch in such a way, that all the characters in the book from the image above can be encoded with ease. 

Supplies

  • Arduino Uno/ Nano
  • USB Type A/B cable (for Arduino Uno) or USB Type A to mini B cable (for Arduino Nano)
  • Solderless Breadboard - Mini
  • LED - Any colour ( I have used Green)
  • Resistor - 220Ω
  • Active Buzzer module (KY-012)
  • Male-to-Male Jumper wires (x4) - 10cm
  • Jumpers (x7) 

Setup


Your setup must look somewhat similar to the one from the images above.

Connections

LED
  • Anode (+) - D3
  • Cathode (-) - Ground (GND)
Active Buzzer Module (KY-012)
  • S - D4
  • (+) - 5V
  • (-) - Ground (GND)

Coding

Even though the hardware setup of this project looks really simple, the sketch is actually composed of 994 lines. It can be compressed to nearly 950 lines. I will explain you prepare the sketch, but before you continue, please watch the YouTube video in the last section of this page to get an idea of how this works. 
Create a String type variable named morseCode. It must look like this:
String morseCode = ""
Create global variables for LED and the active buzzer. Create two functions named 'dot' and 'dash'. You would not need the functions to return any information so use the keyword void. As I already mentioned in the first section of this page, Morse code is composed of 'dot' and 'dash'. You may have noticed something in the video. The LED lights up for 100 milliseconds to denote the dot and 300 milliseconds to denote the dash. The buzzer also functions similar to the LED. 
Within dot( ), set the pin of the LED HIGH and, after 100 ms, set the pin LOW. You can use the delay( ) function in this case. Before calling the delay( ) function, use the tone ( ) function to control your active buzzer. Calling the tone ( ) function before delay( ) function will make both buzzer and LED operate at the same time.  If you are unfamiliar with the tone( ) function, please click the hyperlink and it will lead you to Arduino's function reference website. The buzzer must have a frequency of 200 Hz and must be switched on for 100 ms.
Within the dash( ) function, set the pin of the LED HIGH for 300 ms. The buzzer must have a frequency of 200 Hz and be switched on for 300ms as well. Now, within void setup( ), use the pinMode( ) function to configure each pin as an INPUT or OUTPUT. Call the Serial.begin( ) function and within the parentheses type 9600 which means the baud rate of the Serial port is 9600 bits per second. Use the Serial.print( ) function to print "Morse Code: " in your Serial Monitor.
Now, within void loop( ), type the following:
while (Serial.available( ) > 0){
int ascii = Serial.read( );
...
}
I will explain you how these lines of code works. The codes within the curly brackets will only be executed if you receive data. For more information on Serial.available( ), please visit:
You will be using 'switch...case' function to execute a certain set of codes only if the conditions match that case. The argument within switch( ) function will be ascii. Refer to this website to obtain the decimal values for each ASCII characters. Decimal values differ for uppercase and lowercase alphabet, which means you have to repeat the set of codes so that both uppercase and lowercase alphabet will execute the same function, as you might have seen in the video. The Morse code is the same for both uppercase and lowercase alphabet.
The backslash button must be pressed to encode a new text. The ASCII value for backlash button is 92. Here's an example:
switch (ascii){
case 92: //Set of functions that will be executed when backspace is pressed
Serial.println("\n\nMorse Code: ");
delay(100);
break;
case 82: // Set of functions that will be executed when letter 'R' is pressed.
morseCode.concat(".-.");
Serial.print(".-.   ");
dot();
delay(100);
dash();
delay(100);
dot();
delay(300);
break;
case 114: // Set of functions that will be executed when letter 'r' is pressed.
morseCode.concat(".-.");
Serial.print(".-.   ");
dot();
delay(100);
dash();
delay(100);
dot();
delay(300);
break;
...
}
Using morseCode.concat(paprameter) function, appends the parameter to the morseCode string. I have added 3 units space, so that when a word is typed, there are 3 units space between the letters. delay(100) function is used to add one unit space between parts of a letter and delay(300) function is used to add three units space between the letters. The delay( ) function makes the morse code to be interpreted corrected via the LED and buzzer.
You must write codes similar to this, for each characters (letters, numbers, punctuation marks and other symbols). For the morse codes of each character, please refer to the second image from the first section. 
If you still have any questions with the codes, please feel free to comment below or send an email to arduinoprojectsbyr@gmail.com.

Final Look

If you have any questions or suggestions about this project, please feel free to comment below or send an email to arduinoprojectsbyr@gmail.com.

Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu