Question

In: Computer Science

Using Arduino to blink an LED in morse code. Morse code is used as one of...

Using Arduino to blink an LED in morse code.

Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for 0.3 seconds and then off for 0.3 seconds; express one “dah” with LED on for 0.9 seconds and then off for 0.3 seconds; express the space between letters with LED off for 0.9 seconds; and express the space between words with LED off for 2.1 seconds.

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for question .Be safe .

Note : check attached image for simulation schematic . Code compiled in arduino ide . simulation tested in proteus VSM.

Program Plan :

  1. Create a string of morse code of "We are students . " , we can find morse code of equivalent char .
  2. and create a four function one for dit ,dah ,and char space and word space .
  3. dit() blink led for 0.3 seconds
  4. dah turn on led for 0.9 seconds and off for 0.3 seconds
  5. char space 0.9 seconds turn off led.
  6. word space 2.1 seconds .
  7. in arduino we have delay function takes mili seconds . 1 seconds =1000 mili seconds . delay(900) = 0.9 seconds.
  8. set LED pin 13 as output .
  9. set high and low led inside function .
  10. / use for space between words . and space char used for space between chars .

Program :

#define morseLed 13 //define led pin 13 PB5
String phrase="We are students"; //string of we are students
String morsePhrase=".-- . / .- .-. . / ... - ..- -.. . -. - ..."; //morse code

void setup() {
pinMode(morseLed,OUTPUT); //led pin set OUTPUT DDRB|=(1<<PB5)
//DDRB|=(1<<PB5);
delay(100);

}

void loop() {
//run a loop from 0 index to till length of string moresephrase
for(int i=0;i<morsePhrase.length();i++)
{
if(morsePhrase[i]=='.') //if char is dit call dit message
dit();
else if(morsePhrase[i]=='-') //if char is dah call dah message
dah();
else if(morsePhrase[i]==' ') //if char space call charSpace message
charSpace();
else if(morsePhrase[i]=='/') //if char is / call wordspace message
wordSpace();
}


delay(5000); //each iteration 5 seconds delay

}

void charSpace()
{
digitalWrite(morseLed,LOW); //set low on led
//PORTB&=~(1<<PB5);
delay(900);
}

void wordSpace()
{
  
digitalWrite(morseLed,LOW);
//PORTB&=~(1<<PB5);
delay(2100);
}

void dit()
{
digitalWrite(morseLed,HIGH);
//PORTB|=(1<<PB5);
delay(300);
digitalWrite(morseLed,LOW);
//PORTB&=~(1<<PB5);
delay(300);
}

void dah()
{
digitalWrite(morseLed,HIGH);
//PORTB|=(1<<PB5);
delay(900);
digitalWrite(morseLed,LOW);
//PORTB&=~(1<<PB5);
delay(300);
}

Schematic :

Please up vote ,comment if any query .


Related Solutions

1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Write a function that can be used to blink an LED when called.
Write a function that can be used to blink an LED when called.
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red,...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red, blue, and green. Use ‘analogWrite’ command inside the 'for loop.' Use the value ranges from 0-255 for this command. So, to activate any of the pins, the value should be 255. To turn off 0. pattern: First for loop Red light – delay – Second for loop for blue light – delay - Third for loop for green light - delay. (The resulting lights...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
Produce program code to facilitate LED and switch interface with a microcontroller-based development board (Arduino). Explain...
Produce program code to facilitate LED and switch interface with a microcontroller-based development board (Arduino). Explain the programming process and interface circuits required
Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must...
Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must read two digital input signals and turn on two LEDS as needed to show the sum of the inputs. e.g. 0 + 1 = 01.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Arduino code , using DS3231 library to set time/ date by keypad and print that on...
Arduino code , using DS3231 library to set time/ date by keypad and print that on lcd. i would like to make user to set time and date from the keypad .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT