Wink Detector
Intro: Wink Detector
This instructable explains how to make a “wink-detector” from a modified AD8232 ECG (electrocardiogram) sensor, an LM324-N quad op-amp, an Arduino Uno R3, and a home-made head-band.
The detector has two outputs ... one for when you wink your left-eye ... and one for when you wink your right.
Normal blinks, which involve both eyes, are ignored.
Applications for this circuit include:
- game interfaces
- assistive technology
Few tools are required ... just a soldering iron and a sharp knife.
The sensor modifications, which can be reversed, require that you:
- cut two tracks
- add two solder bridges/shorts
- add a short wire link
The estimated cost of components is $15.00
Images
- The cover photo shows a closeup view of the wink-detector
- Photo 2 shows the approximate position for the headband.
- The video shows the wink-detector in operation. Three successive winks are made with each eye.
STEP 1: Parts List
The following parts were obtained from https://www.aliexpress.com/
- 1 only AD8232 ECG heart monitor module
- 1 only Arduino Uno R3
The following parts were obtained locally:
- 1 only LM324 quad-op-amp
- 1 only 220K ohm resistor 1/8 watt
- 2 only 120K ohm resistors 1/8 watt
- 1 only 15K ohm resistor 1/8 watt
- 2 only 10K ohm resistors 1/8 watt
- 1 only 1200 ohm resistor 1/8 watt
Misc items already on hand:
- breadboard
- stranded copper wire
- solder
The estimated cost of components is $15
STEP 2: Circuit
The “wink detector” circuit diagram is shown in photo 1
The circuit comprises a modified AD8232 ECG heart sensor module, an LM324 quad-op-amp, an Arduino Uno R3, a few resistors , and two LEDs.
The output waveform from the AD8232 hovers about 1.5 volts DC.
When the left-eye winks the AD8232 output wave form rises towards 3.3 volts. When the waveform exceeds 2.8 volts the left-wink comparator output changes from zero to 5 volts as shown in photo 2.
When the right-eye winks the AD8232 output wave form falls towards zero volts. When the waveform falls below 0.2 volts the right-wink comparator output changes from zero to 5 volts as shown in photo 3.
Normal blinks have no effect on the output as they are the equivalent of two simulataneous winks and it’s not possible for the AD8232 output to go in two opposite directions at the same time.
The AD8232 is supplied with a set of gel-coated ECG pads and leads. After a few uses the pads tend to fall off. To counter this I attached some tinned-steel pads to a headband made from an old lanyard and Velcro. Details on how to construct this head-band are described elsewhere in this article.
STEP 3: AD8232 Circuit Modifications
An unmodified circuit board is shown in photo 1
When used as a heart monitor the ECG leads are connected as follows:
- Right arm is connected to RA
- Left arm is connected to LA
- Right leg is connected to RL
A modified circuit board is shown in photo 2
After the modifications the leads become:
- Right eyebrow is connected to RA
- Left eyebrow is connected to LA
- Forehead is connected to RL
The original circuit
A simplified block diagram of the original heart monitor is shown in photo 3.
This diagram was created by matching the component values in the Sparkfun “Heart Monitor” schematic [1] to the AD8232 “Functional Block Diagram” [2]
When used as a heart monitor, both inputs to the AD8232 instrumentation amplifier are tied to the 3.3 volt supply rail via 10M resistors. The instrumentation amplifier, however, can’t operate unless the two input leads are around mid-rail potential.
Mid-rail potential is obtained by injecting a tiny (10uA) current from the RLD (right leg drive) lead into your leg. We have effectively created a voltage divider using your body as one of the resistors.
The actual purpose of the RLD lead is explained in the AD8232 data sheet ... I’m just looking at it from a different viewpoint.
The modified circuit
A block schematic of the circuit modifications is shown in photo 3.
Instead of looking for heart beats, the wink detector is looking for differences in electrical potential. As such it needs to be fully operational at all times ... both inputs of the instrumentation amplifier must be tied to a mid-rail potential such as Vref (1.5 volts)
This is achieved by cutting the track that connects both 10M resistors to the 3.3 volt supply and joining the cut end to Vref by means of a small wire link. Both inputs of the instrumentation amplifier are now at mid-rail potential which means the AD8232 output hovers about 1.5 volts DC.
We also don’t need the RLD lead ... let’s use this lead to improve the CMRR (common mode rejection ratio) of the system by raising your body to midrail potential. This is achieved by cutting the track to the AD8232 RLD pin and joining the cut end to Vref.
The AD8232 data sheet recommends that the RLD and RLDF (right leg drive feedback) pins be shorted when using a two-lead circuit. This is achieved by shorting the capacitor joining these two pins.
References
[1]
https://cdn.sparkfun.com/datasheets/Sensors/Biomet...
[2]
STEP 4: The Headband
The headband was fashioned from an old lanyard, a length of Velcro, and some Velcro hooks. Construction details are shown in photos 1..4
The pads are made from thin tin plate ... I used the bottom of an old paint can ... and are attached to the lanyard by narrow tabs cut from the same tin plate. This allows the pads to slide around the headband.
Dull the edges of the metal pads with a file and lightly sand the contact surfaces. Solder the heart monitor leads to the exposed metal tabs.
It is important that the pads make good skin contact ... medical contact gel is recommended but I have found that hand moisturiser also works.
The pad size is not critical ... I have since reduced the width while experimenting with closer pad-spacing ... halving the size made no difference.
STEP 5: Software
Instructions
Upload the attached file “wink_detector_4.ino” to your Arduino and run.
Notes
The code is remarkably simple ... it simply polls each of the two wink-detector outputs and flashes the appropriate LED whenever a comparator changes state.
But there is a catch ... strong winks can cause the opposite LED to flash.
The top trace in photo 1 shows the AD8232 output dipping down to zero volts following a strong left-eye wink. The right-eye comparator (lower trace) sees this as a right-wink and generates a false output.
Photo 2 shows both comparator outputs for a strong left-wink. The right-comparator is still generating a false output 800mS after the left-wink starts.
A software solution is used to get around this ... the first detector to see a wink disables the other detector for 1 second. This period is adjustable in the code header,
STEP 6: Summary
This instructable explains how to convert a Sparkfun AD8232 “Heart Monitor” to a “Wink Detector”.
Construction details for an adjustable head-band are also provided.
The Arduino code eliminates false triggers due to overshoot from the AD8232 output in the presence of strong winks.
Applications for this circuit include:
- game interfaces
- assistive technology
The estimated cost of components is $15.00
Click here to view my other instructables.
7 Comments
StrangerIV 3 years ago
Interesting work. Gonna make it too.
I have a question, how much time it takes for ECG board output to recover to it's mid-rail state? Step 2 pictures shows that after wink plateau output signal flows slowly to different state.
And I wonder why didn't you use one of Arduino ADC inputs? No need for external comparator, you could analyse signal level right by firmware. I'm going to make some experiments on this.
lingib 3 years ago
(1)
The recovery time depends on how hard you wink.
Looking at the two attached screen grabs made at the time my guess would be just over a second. (Each oscilloscope trace is 200mS per division.)
The strong right-wink was obtained using considerable strain and clenching my teeth.
In normal operation this does not happen.
Codes lines 65-68 (below) prevent false triggers due to overshoot
// ----- Wink detection logic
unsigned long LeftStopTime;
unsigned long RightStopTime;
unsigned long StopTime = 1000000UL; // 1000000 uS = 1 second
A StopTime of 1 second allows succesive rapid winks to be detected.
Adjust this time to suit.
(2)
The reason for not using the Arduino ADCs is that they cannot resolve microvolt signals.
The resolution of an Arduino ADC is 5/1023 = 4.9 millivolts
The signal voltages across skin resistance are far less than this and need to be amplified. We also need to remove stray voltage pickup from the surroundings. To achieve this a differential amplifier is required.
Assuming the signal of interest is say 1uV and the differential amplifier has an open-loop gain of 60dB (1000000 times) then the output of the differential amplifier will be 1 volt which is easy to detect and process.
StrangerIV 3 years ago
Sorry, English is not my native, so please forgive me some possible uncertain sayings.
For my first question, if the recovery time after 'strong wink' is about 1 sec, does it mean that recovery time after 'light wink' is roughly the same?
And for my second question, I see your other project 'Mind Control 3' does not uses LM324. Are EEG signals have more voltage than muscular?
lingib 3 years ago
Yes ... it should be possible to directly connect the output of the modified AD8232 to one of the Arduino analog inputs.
Can't remember why I didn't ... I think I was trying to make the LEDs flash using a standalone circuit that would operate from two 1.5 AA batteries. The Arduino was added to eliminate the false triggers.
Regarding the recovery time ... the time taken for the modified AD8232 output to return to the midrail voltage from the onset of either a natural wink, or a forced wink, appears to be around 800mS to 1000mS (one second).
I think the reason that the recovery times are similar is that a forced wink has a greater rate-of-change. You can see this in the strong right_eye wink screen-shot that I sent you in my previous reply.
The attached screen shot from an experimental circuit shows the output spectrums from two frequency bands of interest when using the AD8232 head-band and winking multiple times. It is interesting to note that the waveforms don't have to fully recover to detect a second wink
As for the EEG versus muscular signal strength ... the EEG signals are much weaker.
StrangerIV 3 years ago
Interesting screenshot. It was another question for me, is AD8232 able to detect double winks. Now I see it's potentially possible to emulate mouse buttons by eye winks. Didn't you think in that direction?
lingib 3 years ago
Good luck with your project :)
StrangerIV 3 years ago