Arduino project for begginers: Morse coder

Arduino project for beginners

With Arduino board you can create almost any hobby electronic device. There are countless ideas for Arduino projects. That is why this board is so popular. You can never get board if you are tech fan. And also, your creation can be very useful. That is why we decided to provide you another Arduino project for beginners. Later, we will be more focused on advanced Arduino projects, but right now we will try to help the folks who just bought the board and want to build their first electronic device.

For this project we will just improve our first one which we posted a few weeks ago. We created S.O.S. Morse code flashlight. Today we will create a device that can Translate characters into Morse code. It will get series of sentences as an input, and it will provide series of dots and lines (coded signals) on output.

For this device, you will need the same parts as for our first project.

One Arduino board or clone
23 D1 5-mm Red LEDs
6 R1 270 Ω 0.5W resistors

The scheme is the same as is in project 1.

For the software part, first you will have to know Morse code. You can find it anywhere on the net. We provided the one from Wikipedia. There are a few rules we must follow. Dash must be three times long as dot. Time between the dashes or dots is equal to the time of dot and the space between words is seven times longer the time between characters.

Here is how to program your arduino board:

int ledPin = 12;
char* letters[] = {“.-”, “-…”, “-.-.”, “-..”, “.”, “..-.”, “–.”, “….”, “..”,”.—”, “-.-”, “.-..”, “–”, “-.”, “—”, “.–.”, “–.-”, “.-.”, “…”, “-”, “..-”, “…-”, “.–”, “-..-”, “-.–”, “–..” };
char* numbers[] = {“—–”, “.—-”, “..—”, “…–”, “….-”, “…..”, “-….”, “–…”, “—..”, “—-.”};
int dotDelay = 200;
void setup()
{ pinMode(ledPin, OUTPUT);
Serial.begin(9600); }
void loop()
{ char ch; if (Serial.available())

{
ch = Serial.read(); // read a single letter
if (ch >= ‘a’ && ch <= ‘z’)
{
flashSequence(letters[ch - 'a']);
}
else if (ch >= ‘A’ && ch <= ‘Z’)
{
flashSequence(letters[ch - 'A']);
}
else if (ch >= ’0′ && ch <= ’9′)
{
flashSequence(numbers[ch - '0']);
}
else if (ch == ‘ ‘)
{
delay(dotDelay * 4);
}
}
}
void flashSequence(char* sequence)
{
int i = 0;
while (sequence[i] != NULL)
{
flashDotOrDash(sequence[i]);
i++;
}
delay(dotDelay * 3);
}
void flashDotOrDash(char dotOrDash)
{
digitalWrite(ledPin, HIGH);
if (dotOrDash == ‘.’)
{
delay(dotDelay);
}
else // must be a -
{
delay(dotDelay * 3);
}
digitalWrite(ledPin, LOW);
delay(dotDelay);
}

We must add the command:

Serial.begin(9600);

This command will se  the speed of USB port on our Arduino. This speed will be enough for our morse code. Also we will need to use tool in Arduino software called Serial Monitor. It will allow us to type messages which will be sent to Arduino for coding. You can start the tool by clicking icon on right side of your software. Then write something in the text box and press return key. Your device will start to blink that sentence in Morse code and your  Arduino project is finished!

 

ElectronicKits.com
You can leave a response, or trackback from your own site.

Leave a Reply