Motion sensing keyboard emulator



Eranda Tennakoon

Create Your Badge
by Eranda tennakoon

Introduction

The project undertook was a motion sensing keyboard emulator and as the name suggests, motion is detected and a certain key on the keyboard is emulated. The idea is to emulate chosen keys (page up and page down) from a keyboard using motion detectors as triggers. There are various types of motion sensing equipment in the general market. Among them are video capturing motion detectors, laser detectors and PIR’s. The ST1KLA photo transistor is a versatile sensor that enables easy use and good accuracy and thus used in this project.

The PIC16F877A microcontroller was used in this project to generate bit patterns of the respective keys. The generated bit patterns are fed into the ps2 keyboard port of a PC. Any microcontroller capable of high speed signal transmission can be used.

The result of this project is a valuable device that enables easy use of the PC. With one sweep of the hand you can move through a page or a presentation slide giving you much more freedom.

High level design

This device runs on a simple mechanism which is triggered by the motion of the hand and sends a signal to the PC. The PS2 keyboard communicates bidirectionally with the PC. A unique set of codes known as the scan codes are sent to the PC when a key is pressed and also another set of scan codes are sent when the key is released. The scan codes for the keys to be emulated, should be known. The scan codes used in this device can be found at the sites provided in the references.

As mentioned before, the PC’s keyboard implements a bi-directional protocol. The keyboard can send data to the Host and the Host can send data to the Keyboard. The Host has the ultimate priority over direction. It can at anytime (although not recommended) send a command to the keyboard.

The keyboard is free to send data to the host when both the KBD Data and KBD Clock lines are high (Idle). The KBD Clock line can be used as a Clear to Send line. If the host takes the KBD Clock line low, the keyboard will buffer any data until the KBD Clock is released, ie goes high. Should the Host take the KBD Data line low, then the keyboard will prepare to accept a command from the host.

The transmission of data in the forward direction, ie Keyboard to Host is done with a frame of 11 bits. The first bit is a Start Bit (Logic 0) followed by 8 data bits (LSB First), one Parity Bit (Odd Parity) and a Stop Bit (Logic 1). Each bit should be read on the falling edge of the clock.

Additional information regarding device to host communication can be found at the site http://retired.beyondlogic.org/keyboard/keybrd.htm

The clock pulse and the data pulse were created using the delay command and sending the respective out put of the port pins to logic high and logic low as needed. Copy of the code used is given in the files below. Also the schematic would provide a better idea of the device’s functions.

The motion sensor was created using the ST1KLA photo transistor as a detector. It has an area of sensitivity that is similar to that of in LED. This was much useful since it allowed an IR LED to be placed adjacent to it without effecting it.

(image taken from http://www.datasheetcatalog.com )

When sliding the hand over the IR LED the infra red radiation reflected off the hand arrives at the photo transistor allowing it to saturate. The transistor is kept in the emitter follower configuration allowing an electrical signal to be sent to the comparator of the PIC microcontroller.

The PIC is coded to send the signal for the page up or page down keys depending on which photo transistor sent the signal.

Program / Hardware

Hardware description

The hardware of the circuit is rather simple since all the hard part lies in the coding. Motion detector was made by keeping the photo transistor and the IR LED adjacent to each other. The photo transistor was connected in emitter follower configuration and the output was fed in to the comparator unit of the PIC. The schematic diagram is given in the Appendix A and Appendix B. The circuit was made into two parts (two layers). The bottom layer consists of the basic components needed to run the PIC16F877A along with the resistors needed to put the transistors in emitter follower configuration and also the resistors for the IR LED s. The top layer consists only the LED s and the photo transistors. This allowed the transistors and LED s to be soldered  into the same height level.
Two- way toggle switches were used to toggle between the keyboard and the motion sensor. The keyboard can be connected through a PS2 female jack whose data and clock lines were connected to one toggle switch and the power and ground lines were connected to another toggle switch. The circuit’s data and clock along with power and ground were connected likewise to the respective switches. The common line was then connected to a PS2 male jack (which goes to the PC).
Pull up resistors were used to connect the data and clock lines to the PC. It is necessary that those lines must be kept at high voltage when idle. Else the PS2 port will freeze and you will have to reboot the PC to get the the keyboard to work again.
The photo transistor in the emitter follower configuration is given above.
The bottom layer

The top layer

Finished work.

Software description

Software to the device was programmed into the PIC microcontroller. The language used was HI-TECH C. The code consists of a loop that constantly checks the outputs of the comparators of the microcontroller and then executes a function that sends the signal for either page up or page down through to the PC.
The clock pulse was created using the delay command. RD2 pin of the port D was used for this. The pin was coded to be set for 35 us and then reset for 35 us. This gives the desired square pulse needed for the clock input. The data pulse was created in a similar manner. The data signal consists of hex E0,7D for make code of page up and E0,F0,7D for break code. The page down key consists of hex E0, 7A make code and E0,F0,7A break code. For additional information on make codes and break codes refer the site http://retired.beyondlogic.org/keyboard/keybrd.htm .
The code used for this device is given in the attachments.

Results

The device was tested for a real time presentation and it worked without any apparent glitches. The presenter was able to move through the slides of his presentation with ease. Motions from the height of 3 – 5 cm above the sensor were detected with good accuracy.

testing

Conclusions

In conclusion, the device worked successfully. It is possible to program the PIC microcontroller to emulate desired keys of a PS2 keyboard. Since the device acts as a stand alone device power is taken from the PC itself letting the user handle the device with ease.

Further enhancements

World of electronics holds many possibilities for the creative mind. Thus it is possible to enhance this device with many other added features. Or it could also be used for some other project as a basic component.

One idea is to enhance this to have more sensors that could detect many other hand gestures. For example you could implement it to detect the hand making a circular motion. The direction of the motion could also be used to implement other function keys of the keyboard.

A wireless hub can be used to communicate between the PC and the device. This would let the user move freely. Of course a receiver must be placed to relay the signal to PS2 port.

The theory of this can be used in other projects as well. For example a floating keyboard can be made using a laser array. Lasers are set to shoot in the fashion of square grid. Detectors are placed to constantly scan the laser signal. When a certain point of the grid is disturbed a signal is set to send through to the PS2 port with a bit pattern that resembles a certain key in the keyboard.

Appendix A

Schematic view of the Bottom layer

Appendix B

Schematic view of the Top layer

Appendix C

                                        Component                   

Description

R1 1 K  0.5 W resistor
R2,R3,R7,R8,R11 5 K 0.5 W resistor
R4,R6 47 Ohms 0.5 W resistor
R8 3 K 0.5 W resistor
R5, R9 100 K 0.5 resistor
R10 4.0 MHz Crystal oscillator
C1,C2 22 pF 16 V Ceramic capacitors
Q1,Q2 N/A
J1 6 Pin connector
J2 4 Pin connector
D1 Green LED
D2,D3 ST1KLA photo transistor
D4,D5 IR LED
list of components

References