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.

- 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.


#include <PS2Keyboard.h>

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

PS2Keyboard keyboard;

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

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

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

void l(){            //dash
  digitalWrite(12, HIGH);
  tone(4, 700);

void pausa(){         //pause between two letters

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>
I've never used solenoids but I think that it will work properly. The correct schematic is the one on the right (&quot;B&quot;). Remember that the function of a diode with a relay is to void that inductive loads in the relay damage the transistor
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
It can fit. Every diode fits here because the amount of current is always lower than 1A.
Take a look to these pages:<br> 1. This is a video --&gt; <a href="http://www.youtube.com/watch?v=MVy_MG0X2h4" rel="nofollow">http://www.youtube.com/watch?v=MVy_MG0X2h4</a><br> 2. This page is the most clear that I've found --&gt; <a href="http://electronicsclub.info/diodes.htm" rel="nofollow">http://electronicsclub.info/diodes.htm</a>
It is the most common type of diode:<br> &nbsp; &quot;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)&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp; <em>taken from <a href="http://en.wikipedia.org/wiki/Diode" rel="nofollow">http://en.wikipedia.org/wiki/Diode</a></em>
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



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: