Introduction: Morse Code Decoder

Picture of Morse Code Decoder

In this project, my sister and I use an Arduino UNO board along with a push button switch and a serial monitor to decode Morse code. It is a very simple project and any Arduino beginners will have fun doing it.

This is the first project I am uploading on So any feedback is welcome.

Step 1: Parts Required

Picture of Parts Required

Parts required for building this project:

  1. Arduino UNO
  2. Breadboard
  3. Tactile switch (Push button)
  4. LED 5mm
  5. Resistor 220 Ω
  6. Jumper wires Male-to-Male (4 nos.)
  7. Laptop/Desktop computer for Serial Monitor

Step 2: Connections

Picture of Connections

1. Connect one end of the push button to the digital I/O pin no. 2 of the Arduino UNO board and the other end to the ground.

2. Connect the anode of the LED to the digital I/O pin no. 4 and the cathode to the ground through a 220 Ω resistor.

3. Connect the Arduino UNO to a PC using the serial communication USB cable.

4. After completion, your circuit should look similar to the given picture.

Step 3: Arduino Sketch

Initialize all the variables:

unsigned long signal_len,t1,t2; //time for which button is pressed
int inputPin = 2; //input pin for push button int ledPin = 4; //outpu pin for LED String code = ""; //string in which one alphabet is stored

Setup the serial connection and I/O pins:

void setup()

Serial.begin(9600); pinMode(inputPin, INPUT_PULLUP); //internal pullup resistor is used to simplify the circuit pinMode(ledPin,OUTPUT); }

Main Loop for running program and decoding:

void loop()
{ NextDotDash: while (digitalRead(inputPin) == HIGH) {} t1 = millis(); //time at button press digitalWrite(ledPin, HIGH); //LED on while button pressed while (digitalRead(inputPin) == LOW) {} t2 = millis(); //time at button release digitalWrite(ledPin, LOW); //LED off on button release signal_len = t2 - t1; //time for which button is pressed if (signal_len > 50) //to account for switch debouncing { code += readio(); //function to read dot or dash } while ((millis() - t2) < 500) //if time between button press greater than 0.5sec, skip loop and go to next alphabet { if (digitalRead(inputPin) == LOW) { goto NextDotDash; } } convertor(); //function to decipher code into alphabet }

Function for reading dot or dash:

char readio()
{ if (signal_len < 600 && signal_len > 50) { return '.'; //if button press less than 0.6sec, it is a dot } else if (signal_len > 600) { return '-'; //if button press more than 0.6sec, it is a dash } }

Function for converting dots and dashes into alphabet:

void convertor()
{ static String letters[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "E" }; int i = 0; if (code == ".-.-.-") { Serial.print("."); //for break } else { while (letters[i] != "E") //loop for comparing input code with letters array { if (letters[i] == code) { Serial.print(char('A' + i)); break; } i++; } if (letters[i] == "E") { Serial.println(""); //if input code doesn't match any letter, error } } code = ""; //reset code to blank string }

Download attached file for the complete code.

Upload the code on Arduino using the serial USB connection.

Step 4: Using the Morse Code Decoder

Picture of Using the Morse Code Decoder

Once you have uploaded the program to the Arduino board, you are ready to use your morse code decoder.

You can refer the attached morse code chart to try out your decoder.

The LED helps to know for how long the push button is pressed, so that you can differentiate between a dot and a dash.

You will have to open the serial monitor from your Arduino app on the PC. All decoded morse codes will appear on the serial monitor.

I have attached a youtube video where I am using the morse code decoder to decode a message.

In case of a any doubt, feel free to contact me or comment.


dashiell.barkhuss (author)2017-09-29

I tried compiling the code but I got these errors

F7P3LDOIYOQISM2.cpp.o: In function `convertor()':

F7P3LDOIYOQISM2.cpp:66: undefined reference to `atexit'

Hey, I am not sure what this error is related to. Did you type in the code manually or did you directly download the .ino file and try to upload it.?

Hugo Díaz (author)2017-03-06

Hi! we're a group of students in Spain and we'd like to make a portable version of this(with a LCD screen), have you got any tips? anything could help us a lot!

One of our problems is that we're trying to put a buzzer into it, our teacher can't help us doing this project so that's why we are telling this to you.

pinaki_s91 (author)Hugo Díaz2017-03-08

Using an LCD should be simple enough. Instead of using Serial.print, use a standard LCD library with print or write command. For the buzzer, the code should be similar to the one I have used, only, instead of the LED diode connect a buzzer.

Hope that helped. If you need help with something specific, do ask.

TherkelL (author)pinaki_s912017-06-08

I love this idea! i am however working on a morse-lock.

Any idea how this could be tied to a password? So when a certain code has been pressed the lock opens?

Hugo Díaz (author)pinaki_s912017-04-06

Thank you, we finally did it!

pinaki_s91 (author)Hugo Díaz2017-04-07


HardlyHumanFX (author)2017-02-17

I'd like to make this print to a portable thermal printer. Any notion on where I might start? :)

I'm thinking two sets with transceivers attached to actuate the 'switch' used. Steampunk spy walkie talkies. Without the talkie bit. Dottie Dashies?

pinaki_s91 (author)HardlyHumanFX2017-02-18

Awesome idea. I have never really worked with a thermal printer but I guess you should check out the one by Adafruit. It's quite neat ans simple. As for your idea of using a transceiver, I am working on something similar right now. I am using an HC-05 bluetooth module to send data to my Android phone. But, your idea with with transceivers sounds cool too. Do keep me posted of your progress.

MarkD355 (author)2017-02-14

Just what I'm looking for. Thanks.

petercheng (author)2017-02-12

excellent. I will try it

terry stockstill sr (author)2017-02-11

great I have need to know this thanks

Swansong (author)2017-02-09

Fun project :) This would have been fun when i did a class on codes.

About This Instructable




More by pinaki_s91:Morse Code Decoder
Add instructable to: