
The addition of a LCD Screen and rotary encoder gives us the capability to adjust the words per minute. The LCD screen has a I2C module to help reduce wiring. This module has been used in past projects and works well. The library used is in the links at the bottom of the post.

Since the rotary encoder used in this project has resistors installed on the break out board, I did not have to worry about installing any. If you use an encoder that is not mounted to a break out board, it will require resistors to be installed. Most rotary encoders also have a push button. This project did not require one but it may be used in the future.


Arduino Keyer Sketch
//Arduino Keyer with Straight Key 9/28/19
//LCD and Rotary encoder added 9/29/19
//https://MacarrLabs.com/
//https://KM4NMP.com/
//common plug pinouts are:
// Tip – left lever, or left side of single lever, normally Dot
// Ring – right lever, or right side of single lever, normally Dash
// Shaft – common
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Rotary.h>
int LeftPin = 2; //left paddle push pin
int RightPin = 3; //right paddle push pin
int Straightkey = 6; //Straight key pin
int LeftPinState = 0; //left paddle pin state
int RightPinState = 0; //right paddle pin state
int StraightkeyState = 0; //Straight key pin state
int audio = 12; //audio out pin
int note = 600; //note pitch change for a different tone
float dotTime;
float dotTimeSec;
float dashTime;
int wpm = 15;
float CharPerMin;
int buttonNeg = 5; //ground connection for paddle and straight key
int buttonPlus = 4; // + connection for paddle
int StraightkeyPlus = 7; // + connection for straight key
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
Rotary r = Rotary(9, 8); //set pins for rotary encoder
void setup() {
Serial.begin(9600); //for debugging
lcd.begin(16,2);
r.begin(true);
pinMode(buttonNeg, OUTPUT);
pinMode(buttonPlus, OUTPUT);
pinMode(StraightkeyPlus, OUTPUT);
digitalWrite(buttonNeg, LOW);
digitalWrite(buttonPlus, HIGH);
digitalWrite(StraightkeyPlus, HIGH);
pinMode(LeftPin, INPUT); //set pin as input
pinMode(RightPin, INPUT); //set pin as input
pinMode(Straightkey, INPUT); //set pin as input
lcd.setCursor( 0, 0 );
lcd.print("KM4NMP.COM Keyer");
lcd.setCursor( 11, 1 );
lcd.print(wpm);
lcd.print("WPM");
delay(2000);
}
void loop() {
LeftPinState = digitalRead(LeftPin);
RightPinState = digitalRead(RightPin);
StraightkeyState = digitalRead(Straightkey);
unsigned char result = r.process(); //check Rotary encoder for change
if (result) {
Serial.println(result == DIR_CW ? "Right Turn" : "Left Turn"); //for debugging
if (result == DIR_CW) {
wpm = wpm + 1;
}
if (wpm > 35) {
wpm = 35;
}
if (result == DIR_CCW) {
wpm = wpm - 1;
}
if (wpm < 10) {
wpm = 10;
}
Serial.print(wpm); //for debugging
Serial.println("WPM"); //for debugging
lcd.setCursor( 11, 1 ); //set lcd cursor
lcd.print(wpm); //print words per minute on LCD
}
//calculate dot time
CharPerMin = wpm * 50;
dotTimeSec = 60 / CharPerMin; //dot time in seconds
dotTime = dotTimeSec * 1000; //dot time in milliseconds
dashTime = dotTime * 3; //dash time
if ( StraightkeyState == 1) {
Serial.print("Straight Key active "); //for debugging
Serial.println(StraightkeyState); //for debugging
tone(audio, note);
}
if ( StraightkeyState == 0) {
noTone(audio);
}
if (LeftPinState == 1) {
Serial.print("left paddle "); //for debugging
Serial.println(LeftPinState); //for debugging
tone(audio, note); //start tone
delay(dotTime); //tone length
noTone(audio);
delay(dotTime); //time between tones
}
if (RightPinState == 1) {
Serial.print("Right paddle "); //for debugging
Serial.println(RightPinState); //for debugging
tone(audio, note); //start tone
delay(dashTime); //tone length
noTone(audio);
delay(dotTime); //time between tones
}
}

The Keyer is capable of 10 to 35 wpm. This can be easily changed in programming. 35 wpm is very fast but fun to play with.
Links
https://km4nmp.com/2019/09/28/arduino-keyer-with-straight-key-port/
https://km4nmp.com/2019/06/09/basic-arduino-keyer/
https://km4nmp.com/2019/06/16/arduino-keyer-with-adjustable-speed-and-lcd/
https://www.ardumotive.com/i2clcden.html
http://www.mathertel.de/Arduino/RotaryEncoderLibrary.aspx
Latest Posts