From charlesreid1

Line 42: Line 42:


<source lang="c">
<source lang="c">
#define MORSE_PIN 12
#define MORSE_PIN 9
#define MORSE_WPM 20
#define MORSE_WPM 20
#include <morse.h>
#include <morse.h>
Line 60: Line 60:


</source>
</source>


==Morse Speaker Sketch Code==
==Morse Speaker Sketch Code==

Revision as of 00:22, 20 July 2015

This page extends the discussion of the morse code blink circuit to making a morse code beep circuit. This replaces the blinking LED with a beeping piezoelectric speaker.

Start The Beeping Project

We want to replace the resistors and LED with a piezoelectric speaker. This will work essentially the same way - the piezoelectric speaker, like the LED, is a widget designed to turn a voltage into noise or light. By connecting the speaker to a voltage pin, and controlling the voltage of that pin with the Arduino microcontroller, we can generate morse code tones in a speaker.

The Speaker

The speaker I used was a 3 - 28 V DC piezoelectric speaker - these can be scavenged from many old electronics like phones, and since they're just generating a buzzing, they don't need to be fancy. No resistors were needed between the voltage pin and the speaker, since the board was using 5 volts, and that was well within the range of the speaker.

The Morse Code

As before, depending on your application, you may want to use either the Arduinomorse Library or the Morse Library, so I'll use both in this example.

The Circuit

The circuit is pretty simple: the microcontroller code turns the message into dashes and dots with voltage. The speaker turns voltage dashes and dots into beeps.

The Circuit

Breadboard Diagram

Here is a breadboard layout using Fritzing:

Bb BlinkSpeaker.png

As mentioned, pretty straightforward: we're powering the positive and negative buses with the red and black cables, connected to the Arduino's 12 pin and ground, respectively. We then route power from the positive bus to the piezo speaker's red wire, then the voltage passes through the speaker (generating sound), and the remaining voltage passes through the black wire to ground.

Breadboard Photo

Here is a photo of the above circuit, constructed on a breadboard:

Photo BlinkSpeaker2.jpg

The Morse Code Code (The Sketch)

Below are two sketches for sending morse code, one using Arduinomorse and the other using Morse.

Arduinomorse Speaker Sketch Code

Use the Arduinomorse library to generate our morse code tones, by switching from a LEDMorseSender object to a SpeakerMorseSender object:

#define MORSE_PIN 9
#define MORSE_WPM 20
#include <morse.h>

//LEDMorseSender sender(MORSE_PIN);
SpeakerMorseSender sender(MORSE_PIN);

void setup() {
    sender.setup();
    sender.setWPM(MORSE_WPM);
    sender.setMessage(String("v v v de kc7dbu ar"));
    sender.startSending();
}
void loop() {
    sender.continueSending();
}

Morse Speaker Sketch Code

#include <Morse.h>
 
#define MORSE_PIN 9
#define MORSE_WPM 20
 
Morse morse(MORSE_PIN, MORSE_WPM, 1);
 
void setup()
{
  // Nothing here for the Morse lib
}
 
void loop()
{
  morse.sendmsg("V V V DE KC7DBU AR");
  delay(5000);
}

Upload and Go

Once you upload the sketch, your piezo speaker should start sending out morse code.