Morse code using aurdino using simulation(online)


i have doubt
please clarify by using online simulation like tinkercad etc

1.Write a code to encrypt text to Morse.
2.Create a link (program or interface (no external components)) between Morse
and a flashlight and that should blink with respective to Morse.
3.Create another program to record the flash and that flash-toggling should be
again reconverted into Morse and then decrypted into text.

we did the transmitter part in tinkercad it worked and but could not do the 3 rd part receiving frm blink light to text
please help me out to do …i need this to be done in online simulation …
i have attached the files few of them i have ,if you can help it will be helpful
Thankyou
waiting for your reply

Hey,

Welcome to the forum!

Could you clarify what you meant by:

Also, what outputs are you getting on the receiver? We’ll try and take a look into this for you ASAP!

we could do to Create a link (program or interface (no external components)) between Morse
and a flashlight and that should blink with respective to Morse

but could not do to .Create another program to record the flash and that flash-toggling should be
again reconverted into Morse and then decrypted into text.

in tinker cad the photodiode or ldr is not varied depending the light…(.it should be varied manully in tinker cad…)
i need the photo diode or ldr to vary automatically on the change of led

i will attach the code and snip of tinker cad ,better if you do it on ther platform and share …plz


transmitter code
const char* MorseTable[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
// space, !, ", #, $, %, &, ’
NULL, β€œ-.-.–”, β€œ.-…-.”, NULL, NULL, NULL, NULL, β€œ.----.”,
// ( ) * + , - . /
β€œ-.–.”, β€œ-.–.-”, NULL, β€œ.-.-.”, β€œβ€“β€¦β€“β€, β€œ-…-”, β€œ.-.-.-”, β€œ-…-.”,
// 0 1 2 3 4 5 6 7
β€œ-----”, β€œ.----”, β€œβ€¦β€”β€, β€œβ€¦β€“β€, β€œβ€¦-”, β€œβ€¦β€, β€œ-…”, β€œβ€“β€¦β€,
// 8 9 : ; < = > ?
β€œβ€”β€¦β€, β€œ----.”, β€œβ€”β€¦β€, β€œ-.-.-.”, NULL, β€œ-…-”, NULL, β€œβ€¦β€“β€¦β€,
// @ 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 [ \ ] ^ _
β€œ-…-”, β€œ-.–”, β€œβ€“β€¦β€, NULL, NULL, NULL, NULL, β€œβ€¦β€“.-”,
// ’ a b c d e f g
NULL, β€œ.-”, β€œ-…”, β€œ-.-.”, β€œ-…”, β€œ.”, β€œβ€¦-.”, β€œβ€“.”,
// h i j k l m n o
β€œβ€¦β€, β€œβ€¦β€, β€œ.—”, β€œ-.-”, β€œ.-…”, β€œβ€“β€, β€œ-.”, β€œβ€”β€,
// p q r s t u v w
β€œ.–.”, β€œβ€“.-”, β€œ.-.”, β€œβ€¦β€, β€œ-”, β€œβ€¦-”, β€œβ€¦-”, β€œ.–”,
// x y z { | } ~ DEL
β€œ-…-”, β€œ-.–”, β€œβ€“β€¦β€, NULL, NULL, NULL, NULL, NULL,
};

int dotLength = 50;
int dashLength = dotLength*3;

void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {
char ch;
if(Serial.available()){
ch = Serial.read();
flashDashDot(MorseTable[ch]);
delay(dotLength*2);
}
}

void flashDashDot(const char * morseCode)
{
int i = 0;
while(morseCode[i] != 0)
{
if(morseCode[i] == β€˜.’){
dot();
} else if (morseCode[i] == β€˜-’){
dash();
}
i++;
}
}

void dot()
{
digitalWrite(13, HIGH);
delay(dotLength);
digitalWrite(13, LOW);
delay(dotLength);
}

void dash()
{
digitalWrite(13, HIGH);
delay(dashLength);
digitalWrite(13, LOW);
delay(dotLength);
}

Receiver code
//Morse Code Binary Tree
// Left child at 2n+1
// Right child at 2n+2
// <.|->
// .E -T
// .I -A .N -M
//
const char MorseTree[] = {’\0’,β€˜E’, β€˜T’, β€˜I’, β€˜A’, β€˜N’, β€˜M’, β€˜S’,
β€˜U’, β€˜R’, β€˜W’, β€˜D’, β€˜K’, β€˜G’, β€˜O’, β€˜H’,
β€˜V’, β€˜F’, β€˜U’, β€˜L’, β€˜A’, β€˜P’, β€˜J’, β€˜B’,
β€˜X’, β€˜C’, β€˜Y’, β€˜Z’, β€˜Q’, β€˜\0’,’\0’,β€˜5’,
β€˜4’, β€˜\0’,β€˜3’, β€˜\0’,’\0’,’\0’,β€˜2’, β€˜\0’,
β€˜\0’,’+’, β€˜\0’,’\0’,’\0’,’\0’,β€˜1’, β€˜6’,
β€˜=’, β€˜/’, β€˜\0’,’\0’,’\0’,’(’, β€˜\0’,β€˜7’,
β€˜\0’,’\0’,’\0’,β€˜8’, β€˜\0’,β€˜9’, β€˜0’, β€˜\0’,
β€˜\0’,’\0’,’\0’,’\0’,’\0’,’\0’,’\0’,’\0’,
β€˜\0’,’\0’,’\0’,’?’, β€˜_’, β€˜\0’,’\0’,’\0’,
β€˜\0’,’"’, β€˜\0’,’\0’,’.’, β€˜\0’,’\0’,’\0’,
β€˜\0’,’@’, β€˜\0’,’\0’,’\0’,’\0’,’\0’,’\0’,
β€˜-’, β€˜\0’,’\0’,’\0’,’\0’,’\0’,’\0’,’\0’,
β€˜\0’,’;’, β€˜!’, β€˜\0’,’)’, β€˜\0’,’\0’,’\0’,
β€˜\0’,’\0’,’,’, β€˜\0’,’\0’,’\0’,’\0’,’:’,
β€˜\0’,’\0’,’\0’,’\0’,’\0’,’\0’,’\0’
};

int val = 0; // A Variable to Store the Light Value from the LDR
int ctrHigh = 0;
int ctrLow = 0;
int codePtr = 0;
int dotLen = 400;

void setup()
{
Serial.begin(9600);// Start a Serial Connection
Serial.print(codePtr);
}

void loop()
{
val = analogRead(4);
if (val >= 10)
{
ctrHigh++;
ctrLow = 0;
digitalWrite(13, HIGH);
tone(9, 1000);
} else {
ctrLow++;
if ((ctrHigh >= dotLen) && (ctrHigh < dotLen2)) {
Serial.print(".");
codePtr = (2
codePtr) + 1;
} else if (ctrHigh >= dotLen * 2) {
Serial.print("-");
codePtr = (2codePtr) + 2;
} else {
if(ctrLow == dotLen
2){
Serial.print(MorseTree[codePtr]);
codePtr = 0;
}
}

ctrHigh = 0;
digitalWrite(13, LOW);
noTone(9);

}
}

…
if photodiode recognizes the led light then it will decode ,but in tinker cad the photodiode is not recving the led light as shown in diagram… pls look into it .
even if you have any simullation please attach

1 Like

The Tinkercad simulator will not automatically simulate the transmission of the light from the transmitter to the receiver. One trick worth trying is to place the transmitter and receiver right on top of each other - that may cause the receiver to respond.

1 Like

Hey SK,

You could also use an optocoupler in the sim to emulate the interaction. I got one to pop up using the search box.

1 Like

Hi,

Welcome to the forums!! Sounds like a great project!

I had a look through some other TinkerCAD simulations regarding linking the two signals and it looks like no one has tried using that setup, all of them used a single microcontroller, reacting from the LDR rather than sending a signal through.

@Jeff105671 and @Liam120347 had some really good ideas to get the two connected.

In the receiver code not using delays was a good call!

Liam.

2 Likes