From charlesreid1

(Redirected from Arduino Morse Code Generator)

Overview

Here's a block diagram of what this circuit will look like. The Arduino sends voltages through its output pins to control an I2C LCD screen (see , where it prints the letters that it has sent and its current words per minute (WPM) sending speed, and a piezoelectric speaker, which will generate the morse code output:

Diagram MorseCodeGenerator.png

Eventually this will also include an input potentiometer, but for now we're building this to send at a fixed WPM speed.

Let's review each part of this circuit.

The Arduino Pseudocode

The pseudocode running on the Arudino will be picking letters at random, sending them to the speaker, then updating the display with the letter. The pseudocode for the Arduino sketch, then, will look something like this:

Include libraries
Set pins

Setup:
    Set CW speed
    Set fixed messages

Loop:
    Read speed potentiometer (if applicable)
    Set CW speed (if applicable)

    Randomly select character
    Send character to morse code speaker
    Update display message

The Speaker Sub-Circuit

This one's pretty easy - we just hook up one of our pulse width modulation (PWM) output pins to the speaker, so that we can send modulated morse code tones to the speaker. See the Morse Code Beep Arduino Micro article for more on that circuit.

The Display Sub-Circuit

For the LCD display, I will be using a 4-pin, 5-volt Sainsmart LCD display. Here are photos of the front and back:

Front Back
Sainsmart front.jpg Sainsmart back.jpg

I already covered a basic Hello World example with this LCD display in the Arduino LCD Display article, so head over there to check it out. Controlling this display will require an additional two voltage pins. We've still got plenty of room left to expand this project with more pins!


First Pass

The Circuit

The Breadboard Diagram

Here is the full diagram for our Arduino. We have a three-circuit layout:

  • LCD screen
  • Piezo speaker
  • LED bulb

And the corresponding full breadboard diagram:

Bb MorseCodeGenerator.jpg

There's a lot going on here, so let's break this down into its constitutive parts.

First, we have the LED circuit - this is our Blink Arduino Micro/Hello World circuit. Striaghtforward. This uses a single voltage pin, and the common ground.

Bb MorseCodeGenerator LED.jpg

Next up, we have the Arduino LCD Display circuit, for printing things to the LCD display. This uses up two pins for signal wires (the SDA and SCL lines), and hooks up to the board's 5 V power:

Bb MorseCodeGenerator LCD.jpg

Last is the piezo speaker, for generating the morse code tones. This speaker shares the same output pin as the LED, since we'll be blinking the LED whenever we activate the piezo speaker. If we wanted the LED to have independent behavior - like being a "mode" or "power" indicator - we would use another pin for it.

Bb MorseCodeGenerator Speaker.jpg

Now, when we put it all together, we get the final breadboard diagram:

Bb MorseCodeGenerator.jpg

The Breadboard Photo

Here's a photo of the assembled breadboard:

Photo CodeGenerator.jpg

This looks a little messy, but it's mainly because of long cables. I've used wires with colors matching the breadboard diagram. You can see the green and yellow wires connecting to pins 2 and 3 - those are controlling the LED. The side-by-side red and yellow wires are controlling the LED and speaker, activating them simultaneously for morse code tones.

And plenty of red and black wires scattered throughout to route voltage around!

The Sketch Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x3F  // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN 3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C lcd(I2C_ADDR,
                      En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin,
                      BACKLIGHT_PIN, POSITIVE);

#include <Morse.h>

#define MORSE_PIN 9
#define MORSE_WPM 20

Morse morse(MORSE_PIN, MORSE_WPM, 1);

void setup()
{
  lcd.begin(20, 4);       // 20 columns by 4 rows on display

  lcd.setBacklight(HIGH); // Turn on backlight, LOW for off

  lcd.setCursor ( 0, 0 );            // go to the top left corner
  lcd.print("  charlesreid1.com  "); // write this string on the top row
  lcd.setCursor ( 0, 1 );            // go to the 2nd row
  lcd.print("     FB FB 73  "); // pad string with spaces for centering
  lcd.setCursor ( 0, 2 );            // go to the third row
  lcd.print("     DE KC7DBU  "); // pad with spaces for centering
}

void loop()
{
  delay(5000);
  
  char msg[] = "XT: V V V";
  
  lcd.setCursor(3,3);
  lcd.print(msg);

  morse.sendmsg(msg);
  
  lcd.setCursor(8,3);
  lcd.print("     ");

  delay(5000);
}


Flags