Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Alex Glow
Published © GPL3+

Morse Code Trainer for #Avnet100Years

Avnet used to sell ham radio parts. Today ham culture is still going strong, and this little gadget can help you join in the conversation!

BeginnerWork in progress3 hours1,852
Morse Code Trainer for #Avnet100Years

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Buzzer
Buzzer
×1
SparkFun Green LED, 1206
Green surface-mount LED
×1
SparkFun Right-angle SMD Switch
×1
IC & Component Socket, 8 Contacts
IC & Component Socket, 8 Contacts
×1

Software apps and online services

Arduino IDE
Arduino IDE
KiCad
KiCad

Story

Read more

Custom parts and enclosures

3D-printable stand

Code

Test: Blinky on Pin 1 (Arduino example sketch)

Arduino
Test the programmer, chip, and 3V battery functionality. From Examples > 01.Basics > Blink
/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(1, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(1, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Test: Morse blinky (MorseCodeMachine example sketch)

Arduino
Test the MorseCodeMachine example on ATTiny85, with an LED on pin 1.
#include <MorseCodeMachine.h>

int ledPin = 1;

void setup()
{
    //You are going to use the built-in LED in the Arduino to send Morse code.
    pinMode(ledPin, OUTPUT);
}

void loop()
{
    //You are going to send "Hello World" as Morse code.
    //You will tell the sendMorse function how to make dots and dashes
    //outside this function.
    sendMorse("Hello World", ledDelay, ledDot, ledDash);
}

//Create a delay function and give it to the sendMorse function so that the
//sendMorse function can space out the letters and the words properly.
//You can give this function any name you want.
void ledDelay()
{
    //Wait for a small amount of time.
    delay(200);
}

//Create a dot function and give it to the sendMorse function so that the
//sendMorse function can create dots.
//You can give this function any name you want.
void ledDot()
{
    //Turn on the LED for a small amount of time, then turn off.
    digitalWrite(ledPin, HIGH);
    ledDelay();
    digitalWrite(ledPin, LOW);
}

//Create a dash function and give it to the sendMorse function so that the
//sendMorse function can create dashes.
//You can give this function any name you want.
void ledDash()
{
    //Turn on the LED three times as long as the dot, then turn off.
    digitalWrite(ledPin, HIGH);
    ledDelay();
    ledDelay();
    ledDelay();
    digitalWrite(ledPin, LOW);
}

Final: LEDs + "Avnet 100 Years" Morse buzzer

Arduino
// Morse Code beeper on ATTiny85
// A mashup of:
// Jeremy Cook, https://www.arrow.com/en/research-and-events/articles/programming-attiny85-with-arduino
// and
// MorseCodeMachine example "Example01-HelloWorld"
// by Alex Glow for Avnet, celebrating 100 years that started with ham radio parts!

#include <MorseCodeMachine.h>

int ledPin = 1;
int beepPin = 2;
int ditLength = 35; // cycles of square wave in a dit (*3 = dah)

void setup()
{
  // Set up the LED and buzzer as 
  pinMode(ledPin, OUTPUT);
  pinMode(beepPin, OUTPUT);
    
  digitalWrite(ledPin, HIGH);
}

void loop()
{
    sendMorse("Avnet 100 Years", ledDelay, ledDot, ledDash);
}

//Create a delay function and give it to the sendMorse function so that the
//sendMorse function can space out the letters and the words properly.
//You can give this function any name you want.
void ledDelay()
{
    //Wait for a small amount of time.
    delay(200);
}

// Beep for a short "dit" (dot)
void ledDot()
{
  for (int i=0; i < ditLength; i++) {
    digitalWrite(beepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(beepPin, LOW);
    delayMicroseconds(500);
  }
}

// A dah (dash) is 3 times as long as a dit.
void ledDash()
{
  for (int i=0; i < (ditLength * 3); i++) {
    digitalWrite(beepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(beepPin, LOW);
    delayMicroseconds(500);
  }
}

Credits

Alex Glow
149 projects • 1595 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments