What does this project do?
We build a transmitter that turns a message typed on the computer into Morse code. When you type “SOS” into the Serial Monitor, the Arduino converts it into short and long signals. It sends the message both with LED light and with buzzer sound. The circuit also has a button: as long as you hold it down, the LED lights up and the buzzer beeps. This way you can also send Morse code by hand, like the telegraph operators of the past.
- Age group: 10 and up
- Level: Intermediate
- Time: About 45 minutes
- What you will learn: reading data from the Serial Monitor, using arrays and characters, writing functions, making sounds with
tone()
Parts list
| Part | Qty |
|---|---|
| Arduino Uno (or compatible) | 1 |
| LED (yellow or white) | 1 |
| 220 Ω resistor | 1 |
| Passive buzzer | 1 |
| Push button | 1 |
| Breadboard | 1 |
| Male-to-male jumper wires | ~8 |
| USB cable | 1 |
Wiring

| Component | Connection | Arduino pin |
|---|---|---|
| Button | One leg | D2 |
| Button | Diagonally opposite leg | GND |
| Buzzer | + (long leg) | D8 |
| Buzzer | – | GND |
| LED | Long leg (through 220 Ω) | D12 |
| LED | Short leg | GND |
We don’t use an external resistor for the button; instead we turn on the Arduino’s internal pull-up resistor (INPUT_PULLUP).
Code
// Arduino Morse Code Transmitter - ozandamci.com
const int buttonPin = 2;
const int buzzerPin = 8;
const int ledPin = 12;
const int unit = 200; // length of one dot (ms); make it smaller to go faster
const int frequency = 700; // sound pitch (Hz)
const char* letters[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--", "--.."
};
const char* digits[] = {
"-----", ".----", "..---", "...--", "....-",
".....", "-....", "--...", "---..", "----."
};
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Type your message and press Enter (letters A-Z and digits 0-9).");
}
// Sends a single dot or dash
void signal(int duration) {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, frequency);
delay(duration);
digitalWrite(ledPin, LOW);
noTone(buzzerPin);
delay(unit); // 1 unit gap between signals
}
// Sends the code for one letter (e.g. "...") from start to end
void sendCode(const char* code) {
for (int i = 0; code[i] != '\0'; i++) {
if (code[i] == '.') {
signal(unit); // dot: 1 unit
} else {
signal(unit * 3); // dash: 3 units
}
}
delay(unit * 2); // 3 units gap in total between letters
}
void loop() {
// Sending by hand: light and sound are on while you hold the button
if (digitalRead(buttonPin) == LOW) {
digitalWrite(ledPin, HIGH);
tone(buzzerPin, frequency);
} else {
digitalWrite(ledPin, LOW);
noTone(buzzerPin);
}
// Send the letters coming from the Serial Monitor
if (Serial.available() > 0) {
char letter = toupper(Serial.read());
if (letter >= 'A' && letter <= 'Z') {
Serial.print(letter);
Serial.print(" ");
Serial.println(letters[letter - 'A']);
sendCode(letters[letter - 'A']);
} else if (letter >= '0' && letter <= '9') {
Serial.print(letter);
Serial.print(" ");
Serial.println(digits[letter - '0']);
sendCode(digits[letter - '0']);
} else if (letter == ' ') {
delay(unit * 4); // 7 units gap in total between words
}
}
}
No Arduino? Try this circuit in your browser with the Wokwi simulation → (free, nothing to install). Type your message in the Serial Monitor below the circuit.
Step-by-step instructions
- Prepare the GND rail. Connect the Arduino’s GND pin to the – rail of the breadboard.
- Place the LED. Connect a 220 Ω resistor to the long leg of the LED and wire it to D12. Connect the short leg to the – rail.
- Place the buzzer. Connect its long leg to D8 and its short leg to the – rail.
- Place the button. Put the button across the gap in the middle of the breadboard. Connect one leg to D2 and the diagonally opposite leg to the – rail.
- Upload the code. In the Arduino IDE, choose Arduino Uno and the right port from Tools → Board, then click Upload.
- Send a message. Open Tools → Serial Monitor and set the speed to 9600 baud. Type
SOSinto the box at the top and press Enter. You should hear three short, three long and three short signals. - Try it by hand. Press the button briefly to send a dot and hold it longer to send a dash.
Troubleshooting
- Nothing happens when I type in the Serial Monitor: The speed setting in the bottom-right corner must be 9600. Accented letters such as É, Ü or Ç are not in the Morse table; type them as E, U or C.
- The buzzer makes the same buzzing noise all the time: You may be using an active buzzer. Use a passive buzzer.
- It beeps without pressing the button: The button legs may be the wrong way round. Make sure you are using diagonally opposite legs.
Try it yourself
- Set
unitto 100 and send messages as fast as a radio operator. - Build a circuit each with a friend; one sends a message with light and the other decodes it on paper.
- Add an LDR to build a receiver that reads Morse messages sent with light.
For teachers: a two-page activity sheet for using this project in class: lesson plan, discussion questions, answer key and a student worksheet.





“Arduino Morse Code Transmitter: Send Messages with Light” için 2 yorum