How to Make Light Blink in Morse Code

by ydong02 in Circuits > Arduino

119 Views, 0 Favorites, 0 Comments

How to Make Light Blink in Morse Code

IMG_2156.jpg

Although these instructions pertain specifically to the LED lights that come in the Arduino kit, this can easily be scaled up to higher voltage LEDs (potentially with the help of relays).

Supplies

Screen Shot 2023-12-20 at 4.45.42 PM.png
Screen Shot 2023-12-20 at 4.45.59 PM.png
  • Arduino
  • 5mm red LED
  • 220 (or 1k or 10k) ohm resistor
  • 2 M-M jumper wires
  • breadboard

Wiring Instructions

Screen Shot 2023-12-20 at 4.50.40 PM.png

While the diagram shows the 220 ohm resistor in use, you can easily swap it out for a 1k or 10k ohm resistor as well. Make sure that digital output 9 is connected to the positive rail on the breadboard and that GND on the Arduino is connected to the negative rail on the breadboard. From then on, your circuit is complete/closed, and you are ready to upload the code to your Arduino!

Arduino Code

#define LED 9

const int timeUnit = 250;
const int dotPeriod = timeUnit;
const int dashPeriod = 3 * timeUnit;
const int spacePeriod = 6 * timeUnit;

void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}

void loop() {
morse();
}

void morse() {
String showCode[] = {".", ".", ".", " ", ".", ".", ".", ".", " ", "-", "-", "-", " ", ".", "-", "-", " "};

for (int i = 0; i < 17; i++) {
if (showCode[i] == " ") {
digitalWrite(LED, LOW);
delay(spacePeriod);
} else {
digitalWrite(LED, HIGH);
if (showCode[i] == ".") {
delay(dotPeriod);
} else if (showCode[i] == "-") {
delay(dashPeriod);
}
}
digitalWrite(LED, LOW);
delay(timeUnit);
}
}

The code here shows how to blink the word 'show' in the showCode array, but feel free to replace the characters with anything you want using this translating resource:

https://morsecode.world/international/translator.html

The ratio between the dot period, dash period, and space period is decided using Morse code timing standards, though you can change the amount of time the timeUnit variable denotes.