loading

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
<p>hi! </p><blockquote>but the hardest thing is connect the keyboard to the Arduino board. As explained <a href="http://scuola.arduino.cc/en/content/connect-ps2-keyboard-arduino-uno" rel="nofollow">here</a></blockquote><p>where is the page now?</p><p>the &quot;here&quot; link just gave me the old 404 Page Not Found, please help!</p>
<p>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 <a href="http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html" rel="nofollow">PS/2 Keyboard library page</a>.</p>
<p>after verifying:</p><p>In file included from PS2Keyboard.cpp:51:<br>/PS2Keyboard.h:35:30: error: utility/int_pins.h: No such file or directory</p>
<p>It works for me. Are you sure that you have unzipped the PS2Keyboard.zip archive in the &quot;libraries&quot; folder inside the Arduino IDE one?</p>
Yes, indeed. I changed it already. I tested the program with the &quot;Morse Code Reader&quot; from https://play.google.com/store/apps/details?id=org.jfedor.morsecode&amp;feature=search_result#?t=W251bGwsMSwxLDEsIm9yZy5qZmVkb3IubW9yc2Vjb2RlIl0. <br> <br> It works :-)
Helo<br> 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:<br> /**********<br> morse.ino<br> **********/<br> #include &lt;PS2Keyboard.h&gt;<br> const int DataPin = 8;<br> const int IRQpin = 2;<br> //PS2Keyboard keyboard;<br> void setup() {<br> //delay(1000);<br> //keyboard.begin(DataPin, IRQpin);<br> Serial.begin(9600);<br> }<br> void loop() {<br> //if (keyboard.available()) {<br> if (Serial.available()!=0) {<br> //char c = keyboard.read();<br> char c = Serial.read();<br> Serial.write(c);<br> if (c == 'a') {<br> p();l();pausa_l();<br> } else if (c == 'b') {<br> l();p();p();p();pausa_l();<br> } else if (c == 'c') {<br> l();p();l();p();pausa_l();<br> } else if (c == 'd') {<br> l();p();p();pausa_l();<br> } else if (c == 'e') {<br> p();pausa_l();<br> } else if (c == 'f') {<br> p();p();l();p();pausa_l();<br> } else if (c == 'g') {<br> l();l();p();pausa_l();<br> } else if (c == 'h') {<br> p();p();p();p();pausa_l();<br> } else if (c == 'i') {<br> p();p();pausa_l();<br> } else if (c == 'j') {<br> p();l();l();l();pausa_l();<br> } else if (c == 'k') {<br> l();p();l();pausa_l();<br> } else if (c == 'l') {<br> p();l();p();p();pausa_l();<br> } else if (c == 'm') {<br> l();l();pausa_l();<br> } else if (c == 'n') {<br> l();p();pausa_l();<br> } else if (c == 'o') {<br> l();l();l();pausa_l();<br> } else if (c == 'p') {<br> p();l();l();p();pausa_l();<br> } else if (c == 'q') {<br> l();l();p();l();pausa_l();<br> } else if (c == 'r') {<br> p();l();p();pausa_l();<br> } else if (c == 's') {<br> p();p();p();pausa_l();<br> } else if (c == 't') {<br> l();pausa_l();<br> } else if (c == 'u') {<br> p();p();l();pausa_l();<br> } else if (c == 'v') {<br> p();p();p();l();pausa_l();<br> } else if (c == 'w') {<br> p();l();l();pausa_l();<br> } else if (c == 'x') {<br> l();p();p();l();pausa_l();<br> } else if (c == 'y') {<br> l();p();l();l();pausa_l();<br> } else if (c == 'z') {<br> l();l();p();p();pausa_l();<br> } else if (c == '1') {<br> p();l();l();l();l();pausa_l();<br> } else if (c == '2') {<br> p();p();l();l();l();pausa_l();<br> } else if (c == '3') {<br> p();p();p();l();l();pausa_l();<br> } else if (c == '4') {<br> p();p();p();p();l();pausa_l();<br> } else if (c == '5') {<br> p();p();p();p();p();pausa_l();<br> } else if (c == '6') {<br> l();p();p();p();p();pausa_l();<br> } else if (c == '7') {<br> l();l();p();p();p();pausa_l();<br> } else if (c == '8') {<br> l();l();l();p();p();pausa_l();<br> } else if (c == '9') {<br> l();l();l();l();p();pausa_l();<br> } else if (c == '0') {<br> l();l();l();l();l();pausa_l();<br> } else if (c == ' ') {<br> pausa_w();<br> } else {<br> tone(4, 300, 550); //error tone<br> }}}<br> void p(){ //dot<br> digitalWrite(13, HIGH);<br> tone(4, 1000);<br> delay(66);<br> digitalWrite(13, LOW);<br> noTone(4);<br> delay(66);<br> }<br> void l(){ //dash<br> digitalWrite(13, HIGH);<br> tone(4, 1000);<br> delay(198);<br> digitalWrite(13,LOW);<br> noTone(4);<br> delay(68);<br> }<br> void pausa_w(){ //pause between two words<br> delay(1000);<br> }<br> void pausa_l(){ //pause between two letters<br> delay(198);<br> }
Hi! <br>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(): <br> <br>if (c != ' ' ) <br> pausa_l(); <br> <br>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.
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.

About This Instructable

8,750views

18favorites

Bio: I'm an Italian 19 years old automation engineering student.
More by giuliom_95:Color sensors and Arduino serial communication for beginners  A sort of modern kinetic art. The useless alarmed Coke can 
Add instructable to: