The Morse Code Generator by a PS\2 Keyboard

About: Animation and CG enthusiast. Computer engineer in the free time.

Intro: The Morse Code Generator by a PS\2 Keyboard

Hi, all!
Today I' m trying to explain you my last project: "The morse code generator by a PS\2 keyboard"

I' ve used an PS/2 keyboard to send input to my Arduino board and transform it in morse code that activate a speaker and a relay.

Components:
- PS\2 keyboard
- Arduino Uno(or others)
- Wires
- 5V relay
- BC547 transistor
- Small speaker
- Recirculation Diode

Step 1: Setting Hardware

The Fritzing project image below can explain almost all, but the hardest thing is connect the keyboard to the Arduino board. We must connect the PS\2 connector data pin to the Arduino pin 8, the clock pin to the 2nd, 5V pin to a 5V source and GND pin to GND. If you find a female PS\2 connector you are very lucky and can use it but others can do like me: I've use as replacement the metal part, covered by insulating tape, of connectors that are used on the mother boards (for wires of: power and HDD LEDs, power and reset buttons, USB face connectors , ecc. ecc.) .

Step 2: Software and Conclusions

Here is attached the '.ino' file I've made. You'll find the 'PS2Keyboard.h' library in here. Enjoy it.

/**********
morse.ino
**********/

#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  2;

PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
}

void loop() {
  if (keyboard.available()) {
   
    char c = keyboard.read();
   
    if (c == 'a') {
      p();l();
    } else if (c == 'b') {
      l();p();p();p();
    } else if (c == 'c') {
      l();p();l();p();
    } else if (c == 'd') {
      l();p();p();
    } else if (c == 'e') {
      p();
    } else if (c == 'f') {
      p();p();l();p();
    } else if (c == 'g') {
      l();l();p();
    } else if (c == 'h') {
      p();p();p();p();
    } else if (c == 'i') {
      p();p();
    } else if (c == 'j') {
      p();l();l();l();
    } else if (c == 'k') {
      l();p();l();
    } else if (c == 'l') {
      p();l();p();p();
    } else if (c == 'm') {
      l();l();
    } else if (c == 'n') {
      l();p();
    } else if (c == 'o') {
      l();l();l();
    } else if (c == 'p') {
      p();l();l();p();
    } else if (c == 'q') {
      l();l();p();l();
    } else if (c == 'r') {
      p();l();p();
    } else if (c == 's') {
      p();p();p();
    } else if (c == 't') {
      l();
    } else if (c == 'u') {
      p();p();l();
    } else if (c == 'v') {
      p();p();p();l();
    } else if (c == 'w') {
      p();l();l();
    } else if (c == 'x') {
      l();p();p();l();
    } else if (c == 'y') {
      l();p();l();l();
    } else if (c == 'z') {
      l();l();p();p();
    } else if (c == '1') {
      p();l();l();l();l();
    } else if (c == '2') {
      p();p();l();l();l();
    } else if (c == '3') {
      p();p();p();l();l();
    } else if (c == '4') {
      p();p();p();p();l();
    } else if (c == '5') {
      p();p();p();p();p();
    } else if (c == '6') {
      l();p();p();p();p();
    } else if (c == '7') {
      l();l();p();p();p();
    } else if (c == '8') {
      l();l();l();p();p();
    } else if (c == '9') {
      l();l();l();l();p();
    } else if (c == '0') {
      l();l();l();l();l();
    } else if (c == ' ') {
      pausa();
    } else {
     tone(4, 300, 250); //error tone
    }
  }
}

void p(){            //dot
  digitalWrite(12, HIGH);
  tone(4, 700);
  delay(250);
  digitalWrite(12, LOW);
  noTone(4);
  delay(250);
}

void l(){            //dash
  digitalWrite(12, HIGH);
  tone(4, 700);
  delay(750);
  digitalWrite(12,LOW);
  noTone(4);
  delay(250);
}

void pausa(){         //pause between two letters
  delay(1750);
}



If you have any kind of problems leave a comment

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Metalworking Contest

      Metalworking Contest
    • Furniture Contest 2018

      Furniture Contest 2018

    14 Discussions

    0
    None
    BronycastU

    2 years ago on Introduction

    hi!

    but the hardest thing is connect the keyboard to the Arduino board. As explained here

    where is the page now?

    the "here" link just gave me the old 404 Page Not Found, please help!

    1 reply
    0
    None
    giuliom95BronycastU

    Reply 2 years ago on Introduction

    Thanks for pointing out this issue. The link is broken because the page has been completely removed from the scuola.arduino.cc website. I'm sorry. However you can easily follow this instructable even without that page. Remember that you can find useful stuff on the PS/2 Keyboard library page.

    0
    None
    tanhaye

    3 years ago on Step 2

    after verifying:

    In file included from PS2Keyboard.cpp:51:
    /PS2Keyboard.h:35:30: error: utility/int_pins.h: No such file or directory

    1 reply
    0
    None
    giuliom95tanhaye

    Reply 3 years ago on Introduction

    It works for me. Are you sure that you have unzipped the PS2Keyboard.zip archive in the "libraries" folder inside the Arduino IDE one?

    0
    None
    giuliom95

    5 years ago on Introduction

    I've never used solenoids but I think that it will work properly. The correct schematic is the one on the right ("B"). Remember that the function of a diode with a relay is to void that inductive loads in the relay damage the transistor

    0
    None
    giuliom95

    5 years ago on Introduction

    There is no need to rewrite the whole source code. The difference between my sketch and the one of Pchmielecki is only that mine uses directly a keyboard connected to the arduino while his uses the keyboard trough the serial communication with a computer. If you want to adopt his method you have only to modify the code as I've suggested two replies before

    0
    None
    giuliom95

    5 years ago on Introduction

    It can fit. Every diode fits here because the amount of current is always lower than 1A.

    0
    None
    giuliom95

    5 years ago on Introduction

    It is the most common type of diode:
      "The most common function of a diode is to allow an electric current to pass in one direction (called the diode's forward direction), while blocking current in the opposite direction (the reverse direction)"
         taken from http://en.wikipedia.org/wiki/Diode

    0
    None
    pchmielecki

    5 years ago on Introduction

    Yes, indeed. I changed it already. I tested the program with the "Morse Code Reader" from https://play.google.com/store/apps/details?id=org.jfedor.morsecode&feature=search_result#?t=W251bGwsMSwxLDEsIm9yZy5qZmVkb3IubW9yc2Vjb2RlIl0.

    It works :-)

    0
    None
    pchmielecki

    5 years ago on Introduction

    Helo
    I improved a little bit, your program: after each character should be break equal to dah length. Your program after modification using serial input below:
    /**********
    morse.ino
    **********/
    #include <PS2Keyboard.h>
    const int DataPin = 8;
    const int IRQpin = 2;
    //PS2Keyboard keyboard;
    void setup() {
    //delay(1000);
    //keyboard.begin(DataPin, IRQpin);
    Serial.begin(9600);
    }
    void loop() {
    //if (keyboard.available()) {
    if (Serial.available()!=0) {
    //char c = keyboard.read();
    char c = Serial.read();
    Serial.write(c);
    if (c == 'a') {
    p();l();pausa_l();
    } else if (c == 'b') {
    l();p();p();p();pausa_l();
    } else if (c == 'c') {
    l();p();l();p();pausa_l();
    } else if (c == 'd') {
    l();p();p();pausa_l();
    } else if (c == 'e') {
    p();pausa_l();
    } else if (c == 'f') {
    p();p();l();p();pausa_l();
    } else if (c == 'g') {
    l();l();p();pausa_l();
    } else if (c == 'h') {
    p();p();p();p();pausa_l();
    } else if (c == 'i') {
    p();p();pausa_l();
    } else if (c == 'j') {
    p();l();l();l();pausa_l();
    } else if (c == 'k') {
    l();p();l();pausa_l();
    } else if (c == 'l') {
    p();l();p();p();pausa_l();
    } else if (c == 'm') {
    l();l();pausa_l();
    } else if (c == 'n') {
    l();p();pausa_l();
    } else if (c == 'o') {
    l();l();l();pausa_l();
    } else if (c == 'p') {
    p();l();l();p();pausa_l();
    } else if (c == 'q') {
    l();l();p();l();pausa_l();
    } else if (c == 'r') {
    p();l();p();pausa_l();
    } else if (c == 's') {
    p();p();p();pausa_l();
    } else if (c == 't') {
    l();pausa_l();
    } else if (c == 'u') {
    p();p();l();pausa_l();
    } else if (c == 'v') {
    p();p();p();l();pausa_l();
    } else if (c == 'w') {
    p();l();l();pausa_l();
    } else if (c == 'x') {
    l();p();p();l();pausa_l();
    } else if (c == 'y') {
    l();p();l();l();pausa_l();
    } else if (c == 'z') {
    l();l();p();p();pausa_l();
    } else if (c == '1') {
    p();l();l();l();l();pausa_l();
    } else if (c == '2') {
    p();p();l();l();l();pausa_l();
    } else if (c == '3') {
    p();p();p();l();l();pausa_l();
    } else if (c == '4') {
    p();p();p();p();l();pausa_l();
    } else if (c == '5') {
    p();p();p();p();p();pausa_l();
    } else if (c == '6') {
    l();p();p();p();p();pausa_l();
    } else if (c == '7') {
    l();l();p();p();p();pausa_l();
    } else if (c == '8') {
    l();l();l();p();p();pausa_l();
    } else if (c == '9') {
    l();l();l();l();p();pausa_l();
    } else if (c == '0') {
    l();l();l();l();l();pausa_l();
    } else if (c == ' ') {
    pausa_w();
    } else {
    tone(4, 300, 550); //error tone
    }}}
    void p(){ //dot
    digitalWrite(13, HIGH);
    tone(4, 1000);
    delay(66);
    digitalWrite(13, LOW);
    noTone(4);
    delay(66);
    }
    void l(){ //dash
    digitalWrite(13, HIGH);
    tone(4, 1000);
    delay(198);
    digitalWrite(13,LOW);
    noTone(4);
    delay(68);
    }
    void pausa_w(){ //pause between two words
    delay(1000);
    }
    void pausa_l(){ //pause between two letters
    delay(198);
    }

    1 reply
    0
    None
    giuliom95pchmielecki

    Reply 5 years ago on Introduction

    Hi!
    Your sketch is better than mine but if you want to improve it more you can remove useless call to 'pausa_l()' by putting one of them at the end of 'loop()' method or, if you want to be precise you can add this at the end of loop():

    if (c != ' ' )
    pausa_l();

    Only for advice: the pause between two words is of 3 lines as official standards so the delay in 'pausa_w()' must be of 594 ms

    cool project! you should enter it in the diy audio contest. just a piece of advice- next time you post a project you should take your pictures in a well lit room instead of using flash, it makes them easier to see.

    1 reply

    Thanks a lot for your positive comment! I'm sorry about the photos' quality, but I'll try to improve it. I've already seen that contest; but I don't think this instructable is suitable for that contest. However this evening I'll take new photos and I'll try to enter the contest. Thanks again for your trust.