Search
  • Jason Ron

Typewriter Keyboard

Updated: May 7

So here we have the typewriter keyboard. I used this to play some red dead redemption 2 to get a historical feel while playing the game. So much fun ! love the feeling and sound of a typewriter.

For this project I used

(1) Arduino Leonardo

(4) 2 pin IR (Infrared) emitters and receivers

(1) pushbutton

(2) Solder boards

(2) 22ohm resistors

(2) 10Kohm resistors


For documentation on the Arduino Leonardo Keyboard functionality please see link below


https://www.arduino.cc/reference/en/language/functions/usb/keyboard/

https://www.arduino.cc/en/Reference/KeyboardModifiers


Construction tips:

Using a screwdriver take off the side front and back cover of typewriter. I used a Underwood typewriter. This exposes two holes on the side of the typewriter. Then loop electrical tape around the part of metal that moves forward inside the typewriter when you press a key. I use a chop stick to hold the key down and carefully looped the tape around the metal parts. Practice makes it easier, but is is very tricky. The keys that you want to use I used "w" "s" "a" "d" " "p" and "l" . I actually taped all keys but had a hard time getting good data for the center keys. That is when I decided to limit the functionality to play a video game. Also note you must press the button to get the keyboard to start working. This is intentional because if you have the keyboard running it can take over your computer so please use a button to turn on keyboard functionality.


Also the IR sensors data is very sensitive, changing every time you move the sensors. It is very important to solder the IR sensors and not use a breadboard (trust me I tried) to get the best data. Also use two books to get the IR sensors at the correct height to stick in the side holes of the typewriter. Then use sticky tack or tape to make the IR sensors not move. My data numbers probably wont match what you are getting so heads up.


Also note that the receiver (black) IR sensors are for some reason reverse polarity. I showed this in the wiring diagram but it is confusing. I use 2 pin IR sensors.



Here is a picture of the typewriter keyboard and circuit diagram





Arduino code////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Keyboard.h>



int val1p;

int val2p;

int val1;

int val2;


const int inputpin = 13;

int lastButtonState2 = 0;

int buttonState2 = 0;

int buttonPushCounter2 = 0;


void setup() {


Serial.begin(9600);

pinMode(A0,INPUT);

pinMode(A1,INPUT);

pinMode(inputpin, INPUT);


val1p=analogRead(A0);

val2p=analogRead(A1);


}


void loop() {

buttonState2 = digitalRead(inputpin);

if (buttonState2 != lastButtonState2) {

if (buttonState2 == LOW) {


buttonPushCounter2++;

}


}

lastButtonState2 = buttonState2;


val1=abs(val1p - analogRead(A0));

val2=abs(val2p - analogRead(A1));

delay(100);



Serial.print(val1);

Serial.print(" , ");

Serial.print(val2);

Serial.print(" , ");

Serial.println(buttonPushCounter2);


if (buttonPushCounter2 == 1)

{

Keyboard.begin();



if(val1<440 && val1>430 ){

//Send the message

Keyboard.press('a');

// delay(30);

// Keyboard.release('a');

}

else if(val1<350 && val1>340 ){

//Send the message

Keyboard.press('w');

// delay(30);

// Keyboard.release('w');

}

else if(val1<430 && val1>400 ){

//Send the message

Keyboard.press('s');

// delay(30);

// Keyboard.release('s');

}

else if(val1<390 && val1>330){

//Send the message

Keyboard.press('d');

// delay(30);

// Keyboard.release('d');

}


else if(val2<480 && val2>460){

//press p for enter

Keyboard.press(KEY_RETURN);

// delay(30);

// Keyboard.release(KEY_RETURN);

}

else if(val2<500 && val2>480){

//press l for esc

Keyboard.press(KEY_ESC);

// delay(30);

// Keyboard.release(KEY_ESC);

}

else{

Keyboard.releaseAll();


}

}


Keyboard.end();



}//loop



65 views0 comments

Recent Posts

See All