0% found this document useful (0 votes)
33 views3 pages

Arduino Morse Code LED Transmitter

This document contains an Arduino program that transmits Morse code using an LED. It defines Morse timings, a Morse code mapping for letters and numbers, and functions to blink dots and dashes. The main loop sends a sync pulse followed by the message 'HELLO WORLD' in Morse code, with appropriate timing for symbols, letters, and words.

Uploaded by

tejaravi1611
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Arduino Morse Code LED Transmitter

This document contains an Arduino program that transmits Morse code using an LED. It defines Morse timings, a Morse code mapping for letters and numbers, and functions to blink dots and dashes. The main loop sends a sync pulse followed by the message 'HELLO WORLD' in Morse code, with appropriate timing for symbols, letters, and words.

Uploaded by

tejaravi1611
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

const int LED_PIN = 13;

// Morse timings (milliseconds)


const unsigned int DOT = 300;
const unsigned int DASH = 900;
const unsigned int SYMBOL_GAP = 300;
const unsigned int LETTER_GAP = 800;
const unsigned int WORD_GAP = 1600;
const unsigned int SYNC_PULSE = 2000; // sync signal for receiver

struct MorseMap { char c; const char *code; };


MorseMap morseTable[] = {
{'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', "--.."},
{'0', "-----"}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"},
{'4', "....-"}, {'5', "....."}, {'6', "-...."}, {'7', "--..."},
{'8', "---.."}, {'9', "----."}
};
const int MORSE_COUNT = sizeof(morseTable) / sizeof(MorseMap);

const char* lookupMorse(char ch) {


if (ch >= 'a' && ch <= 'z') ch -= 32;
for (int i = 0; i < MORSE_COUNT; i++) {
if (morseTable[i].c == ch) return morseTable[i].code;
}
return "";
}

void blinkDot() {
digitalWrite(LED_PIN, HIGH);
delay(DOT);
digitalWrite(LED_PIN, LOW);
delay(SYMBOL_GAP);
}

void blinkDash() {
digitalWrite(LED_PIN, HIGH);
delay(DASH);
digitalWrite(LED_PIN, LOW);
delay(SYMBOL_GAP);
}

void sendMorseForChar(char ch) {


const char* code = lookupMorse(ch);
for (int i = 0; code[i] != '\0'; i++) {
if (code[i] == '.') blinkDot();
else if (code[i] == '-') blinkDash();
}
delay(LETTER_GAP);
}

void sendMorseString(const char* msg) {


for (int i = 0; msg[i] != '\0'; i++) {
if (msg[i] == ' ') delay(WORD_GAP);
else sendMorseForChar(msg[i]);
}
}

void setup() {
pinMode(LED_PIN, OUTPUT);
}

void loop() {
// Send sync pulse (2 sec ON + 1 sec OFF)
digitalWrite(LED_PIN, HIGH);
delay(SYNC_PULSE);
digitalWrite(LED_PIN, LOW);
delay(1000);

// Transmit message
sendMorseString("HELLO WORLD");

// Wait before next repeat


delay(3000);
}

#include <Arduino.h>

const int LED_PIN = 13;

// Morse timings (milliseconds)


const unsigned int DOT = 300; // short blink (dot)
const unsigned int DASH = 900; // long blink (dash)
const unsigned int SYMBOL_GAP = 300; // gap between dot/dash in same letter
const unsigned int LETTER_GAP = 800; // gap between letters
const unsigned int WORD_GAP = 1600; // gap between words

// Morse table (A–Z, 0–9)


struct MorseMap { char c; const char *code; };
const MorseMap morseTable[] = {
{'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', "--.."},
{'0', "-----"}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"},
{'4', "....-"}, {'5', "....."}, {'6', "-...."}, {'7', "--..."},
{'8', "---.."}, {'9', "----."}
};
const int MORSE_COUNT = sizeof(morseTable) / sizeof(MorseMap);

const char* lookupMorse(char ch) {


if (ch >= 'a' && ch <= 'z') ch -= 32;
for (int i = 0; i < MORSE_COUNT; i++) {
if (morseTable[i].c == ch) return morseTable[i].code;
}
return nullptr;
}

void blinkDot() {
digitalWrite(LED_PIN, HIGH);
delay(DOT);
digitalWrite(LED_PIN, LOW);
}

void blinkDash() {
digitalWrite(LED_PIN, HIGH);
delay(DASH);
digitalWrite(LED_PIN, LOW);
}

void sendMorseForChar(char ch) {


const char* code = lookupMorse(ch);
if (!code) return;

for (int i = 0; code[i] != '\0'; i++) {


if (code[i] == '.') blinkDot();
else if (code[i] == '-') blinkDash();
if (code[i + 1] != '\0') delay(SYMBOL_GAP);
}
}

void sendMorseString(const char* msg) {


for (int i = 0; msg[i] != '\0'; i++) {
if (msg[i] == ' ') {
delay(WORD_GAP);
continue;
}
sendMorseForChar(msg[i]);
delay(LETTER_GAP);
}
}

void setup() {
pinMode(LED_PIN, OUTPUT);
[Link](9600);
}

void loop() {
const char* message = "HELLO WORLD";
sendM

You might also like