Arduino as a keyboard for reaction time experiments

Hello

I'm trying to develop a device for psychology reaction time experiments. Basicaly, it needs to have a few buttons on it, perhaps a few LED diods, and most importantly - it needs to measure key press and key release events with at least 10ms accuracy, preferably better. It will be used with various software for psychology experiments, by psychologists (so it should be plug and play).

The most similar device I found is this one: http://www.empirisoft.com/DirectIN.aspx It mimics a keyboard, but somehow manages to be more accurate.

I have found a number of project that use arduino as a keyboard, but I haven't seen the data on the accuracy, since they are developed for different purposes.

I'm new to arduino, and electronics in general for that matter. I would appreciate any help.

There is a brief description of DirectIN technology on their forum: http://support.empirisoft.com/showthread.php?p=186#post186

I guess those would be some general guidelines for creating a similar device.

I don't see any issue here, you attach your button to input that support hardware interrupt routine, there are 2 or 6 (depends on board) of them available with arduino library, service time 0.25 microsec. How many buttons do you need?

Your biggest problem may be switch bounce with your keys/buttons. That may take much longer than 10ms to settle. If you go too quick then transients will give you false positives.

You can use light beam interrupt or other technique to get your data, possibly capacitive sensing with the right caps between sensor and ground. I’ve messed with CapSense and was able to be -sure- of when a finger struck the insulated sensor. The waits changed by definite wide margins, 5,000 digital reads in a loop at the most. There’s another cap sense version that uses just bare wires and is even quicker and also definite. IIRC, 16 digital reads per sense maximum. That’s reads per millisecond instead of milliseconds per read. And… no button to wear or slow finger movement.

I haven’t seen it here but a tap-the-piezo-disc-circuit might be a real winner. The generated pulses are solid-state instant and just enough to flash a led.

Be aware that a part of the reaction time is finding the right key (I found out in my thesis-time) which varies quite a lot from person to person. Depending on the experiment other layouts may be more suitable.

Also the delay in the stimilus is real. If your PC has a refresh frequency of 60 Hz it takes on average 1/120 second before stimulus is visible . If you are talking about 10 ms This is a serious bias.

can you tell more aboutthe experiment?

You can flash a led for stimulus.. how fast is a led and how fast is the human eye? Difference between press and release, how much is that affected by the trigger stimulus?

But this is dangerous intellectual talk, using the word stimulus in any kind of positive sense.

GoForSmoke: Your biggest problem may be switch bounce with your keys/buttons. That may take much longer than 10ms to settle. If you go too quick then transients will give you false positives.

A technique that works quite well is to record the start time (e.g. initial 'key down' event after a suitable period of 'key up') and then wait for the debounce logic to conclude that it was a button click, or a click-and-hold, or a double-click, or whatever you're trying to sense. But then associate that event with the time that the overall sequence started, not the time at which you recognised it.

Magician: I don't see any issue here, you attach your button to input that support hardware interrupt routine, there are 2 or 6 (depends on board) of them available with arduino library, service time 0.25 microsec. How many buttons do you need?

As GoForSmoke mentioned, one of the problems is debouncing. I've seen it solved in hardware, with short-cylce capacitor-resistor scheme, or in firmare/software with debouncing routines, or both - such as here: http://lobes.usc.edu/Journals/BRM10.pdf [.pdf]

I don't understand what hardware interrupt routine means. Is that compatibile with a device that would simulate a keyboard? It's important that the box simulates a keyboard, since it would be used by various people not familiar with computers that much (psychologists :) ). They should be able to simply plug it in and do their experiments.

Do you have an example arduino project that does what you mention?

I would need 4 to 6 buttons, not yet sure. Possibly more versions of response boxes with different button configurations or number of buttons.

@robtillaart Yes, the low monitor frequency is a problem. A part of the problem is solved in professional software such as E-prime or Superlab, but I'm not sure how much could be done in that respect. All we can do is to make the response part as accurate as possible.

@GoForSmoke The LED's would also be used on the box, but they are usefull only for a limited number of experiments. Many use pictures or text as stimuly and require a screen of some kind.

I've found this arduino project: http://www.practicalarduino.com/projects/virtual-usb-keyboard It's a virtual usb keyboard. I'm not sure how I could go about finding out it's timing accuracy.

I recently did some searching on debounce and software debounce. There's a lot of variance in views out there, depending on the goals and determination of the people with them.

Here's someone not satisfied with just making a reasonable product and reporting success: http://www.ganssle.com/debouncing.htm

If you get the right switches/buttons instead of a randomly chosen array and you can come up with reasonable debouncing but the time period I've seen shown for mechanical contact switches is more than 1/100th of a second. Sometimes it's more like 150 ms.

The thing is that 100 msec is reasonable in most all cases. I never before had reason to time any closer than gross human perception. As long as I didn't get false returns and it wasn't too slow.

Yes you -can get- buttons and switches capable of much faster debounce and they're not special order items. My keyboard is probably way better than 100 ms but at my age, I'm not fast enough to hard-test it.

AFAICT the best debouncing is done in hardware.

My best cap sense results were 'fuzzy' logic but I was getting definite ranges for touch, finger close, finger away in under 5000 usecs without actually calculating RC time. That was using a 1 uF cap and 330 ohm resistor in parallel between a digital pin and ground. I actually got good repeatable responses under 3000 usecs maximum with that RC combo but I know since I could do better because I finally read up on RC time constants instead of going by intuition and trial. Fun part to me is when my home-made paper and foil elements fuzz over the speed of a really fast setup.

But with more than a couple-three hours I am sure I could do better, and I am no pro. I bet Nick or Mike or any of dozens of others here could do better in under 5 minutes including time to warm the iron and hunt for materials.

And then I ran Mario Becker's demo, holy crud it's fast! That was 3 days ago and I'm still thinking. Only problem I have is in bare wire contact straight into my pins. One time static and that's probably it for my UNO.

It's still amazing to me: http://arduino.cc/playground/Code/CapacitiveSensor

I look inside my keyboard and what's under the buttons? A cap sense membrane and a logic chip.

Now compare that to what an engineer found using a varied array of buttons and how big is the ballpark?

BTW, since I started buying my own keyboards the most important attribute to me is "the feel". I want a nice definite sensation as the keys go down and bottom out, it's very hard to even begin to describe. A slight give at the bottom that tells my fingers I've made contact. How fast that happens, the fastest I've ever typed is about 90 wpm and in a good keyboard it's faster than that. I might even spend up to $20 to get a comfortable keyboard.....