# Interface 5v digital pulses to keyboard contacts?

I currently have the following bit of kit: Photoplethysmographic sensor for measuring heart rate

It outputs a 5v pulse each time your heart pulses. What I need is to do is interface this pulse output to a keyboard (So each time your heart pulses a key is pressed on the keyboard).

I have stripped an old USB dell keyboard and worked out what contacts on the keyboard PCB need connecting to simulate the key I am after.

I have drawn a circuit on how I think would be the right way to interface the two electronic circuits:

My question(s) are:

Will this circuit work as I intend it to?

Will the relay be able to switch on and off 50-120 times a minute?

Can you offer a better method of interfacing the circuits?

-

Whether a transistor directly across the contact is a good idea or not depends on how the low side of the switch is configured. If that's just an open-drain/open-collector then there's no problem. If it would have a very weak pull-up then the transistor's emitter will be a few volts positive with respect to the base, and though the voltage may not be high enough to damage the transistor, NPN transistors don't like that.

A safe alternative is to use an analog switch,

like the 74LVC1G66, which is an improved single gate version of the good old CD4066 quad switch. The 74LVC1G66 has an on-resistance of less than 10 Ω, but at least a few tens of ohms should be no problem.

Many of these switches have near-zero power supply current (typically 100 nA for the 1G66), and contrary to mechanical relays don't wear out.

If you can't connect the heartbeat monitor's power supply to the keyboard's you'll have to use an SSR (Solid State Relay), like Dave suggests in his answer. These are more expensive though: the Toshiba type Dave mentions costs almost 4 times the 1G66, so I would only use that one if you really need the isolation.

-
Thank you, I've never come across an analogue switch before. So just to confirm: I connect S and D directly to the keyboard terminals and IN directly to the output of the heart rate monitor? –  Brady Sep 22 '12 at 15:15
Also as I need a 8pin DIP through hole package would this be a suitable choice? digikey.co.uk/product-detail/en/TS12A4514P/296-21908-5-ND/… –  Brady Sep 22 '12 at 15:16
@Brady - Two times yes. Make sure you have the TS12A4514, not the 4515, as the latter has a normally-closed contact. –  stevenvh Sep 22 '12 at 15:36
@Brady - The simple analogue switch is the way to go for this project. Make sure that the GND of the sensor, the analogue switch and the keyboard are all interconnected. Also since the sensor runs on 5V, a USB keyboard runs on 5V and the analogue switch can also use 5V you should interconnect all of those as well. –  Michael Karas Sep 22 '12 at 17:35

Your relay solution will work, but there are better options.

The analog switch suggested by @stevenvh is one, but it has the drawback that it requires that the grounds of the sensing circuit and the keyboard to be connected together, and you need to be sure that the voltage swing of the key-scanning signals remains within the power supply rails of the switch.

A small solid-state relay, like this one from Toshiba removes these restrictions, and like the analog switch, doesn't need the transistor driver; it can be driven directly by the output of the sensing circuit through a suitable current-limiting resistor.

-
This seems like a good alternative in case you can't connect your circuit to the keyboard's. (I don't know if that's a problem. Also this is 1.60 at Digikey, while the TS12A4514 analog switch Brady found is 65 cent.) –  stevenvh Sep 22 '12 at 15:54

Many USB enabled microcontrollers have a virtual keyboard as a sample project. They also typically have a virtual serial port. You can even do it with software USB on general purpose micros such as VUSB on the ATTINY85. And then there are boards like the Arduino family which provide a serial channel over USB for applications to communicate.

While this can be higher cost than hacking a keyboard, it may be cheaper and simpler than the relay solution, or figuring out how to more closely integrate into the keyboard circuit. Directly hacking the keyboard is more preferable when you are using a custom physical switch as your new source of input.

-

I suggest you take a step back. Measure the voltage across key contacts, it should be non-zero. That's because a typical keypad looks like this:

In this case, all you need is to connect the transistor's collector to the positive contact, emitter to ground and drive the base. No need for a relay.

-
+1 for posting essentially the very same thing I was about to. A transistor between the appropriate row and column lines should do. –  Alexios Sep 22 '12 at 14:23
A keypad may be connected this way, but a keyboard isn't. It would need more than 100 IO pins on the controller. A keyboard matrix is multiplexed. –  Federico Russo Sep 22 '12 at 14:28
@FedericoRusso, will the solution I posted not work with a multiplexed keyboard? –  Armandas Sep 22 '12 at 14:32
@Armandas as Federico said a keyboard is multiplexed. On the keyboard I'm using it sends out a signal in sequence on 13 pins and looks for a return signal on another 13 pins giving possible number of 169 keys. –  Brady Sep 22 '12 at 14:50
@Armandas - it may or may not :-), see my answer. In the olden days 8048s were often used as keyboard controller, and those don't have real open-drain outputs. Maybe current keyboards aren't based on general-purpose controllers, I don't know. –  stevenvh Sep 22 '12 at 14:58
show 1 more comment

I would go whith a optocoupler, it's a cheap single component that is isolated, fast, without noise, you don't need to worry with feedback current.

And it easily works near a hundred KHz

-
I wouldn't say "easily". Many optocouplers only have tens of kHz bandwidth. –  radagast Nov 28 at 8:08
@radagast would be faster than the keyboard could register anyway –  Vitim.us Nov 28 at 22:10