Mind Control 3: EEG Monitor

5,468

53

15

Introduction: Mind Control 3: EEG Monitor

About: 55+ years in electronics, computers, and teaching ... now retired.

An electroencephalogram (EEG) is a test used to evaluate electrical activity in the brain.

This instructables explains how to build an EEG waveform monitor using an Arduino UNO R3, a TFT graphics shield, and a modified AD8232 heart monitor.

The TFT graphics shield is described in my instructable https://www.instructables.com/id/Arduino-TFT-Grap...

Due to its small size the TFT display can only show 4 out of the 32 possible channels at any one time ... but the choice of channels is yours.

Processing software is included for displaying all 32 EEG channels simultaneously on your PC screen.

Arduino EEG software covering each of the following frequency ranges is also presented [1]:

  • DC .. 32Hz
  • DC .. 64Hz
  • DC .. 128Hz
  • DC .. 256Hz
  • DC .. 512Hz
  • DC .. 1024Hz
  • DC .. 2048Hz
  • DC .. 3200Hz

The estimated cost of parts for this project is less than $30.

Photos

  • The cover photo shows the EEG Monitor display
  • Photo 2 shows the completed monitor
  • The video shows the EEG Monitor in operation

Notes

[1]

DC stands for Direct Current which equates to a frequency of 0Hz

Step 1: Parts List

The following parts were obtained from https://www.aliexpress.com/

  • 1 only Arduino Uno R3
  • 1 only AD8232 ECG heart monitor module
  • 1 only 2.2 Inch TFT SPI LCD Display Module 240*320 ILI9341 with SD Card Slot for Arduino Raspberry Pi 51/AVR/STM32/ARM/PIC [1]
  • 1 only Prototype PCB Expansion Board For Arduino ATMEGA328P UNO R3 Shield FR-4 Fiber PCB Breadboard 2mm 2.54mm Pitch

The following parts were obtained locally:

  • 5 only 2K2 ohm 1/8 watt metal film resistors
  • 5 only 3K3 ohm 1/8 watt metal film resistors
  • 2 only 10K ohm 1/8 watt metal film resistors
  • 1 only 1uF tantulam capacitor
  • 1 only 40 pin header terminal strip 0.1"/2.54mm pitch for PCBs
  • 10 amp tinned copper fuse wire

Misc items already on hand:

  • breadboard
  • stranded copper wire
  • solder

The estimated cost of parts is less than $30

Step 2: Circuit

The circuit diagram for my EEG display is shown in photo 1.

Construction details for the matching shield (photo 2) are given in my instructable https://www.instructables.com/id/Arduino-TFT-Grap...

Step 3: AD8232 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 headband details are described in my instructable https://www.instructables.com/id/Wink-Detector/

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 EEG Monitor 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]

https://www.analog.com/media/en/technical-document...

Step 4: Theory

Complex waveforms comprise many sinewaves each with a different frequency, amplitude. and phase. These frequencies may be identified using a fast fourier transform (FFT).

Spectrum analysers, such as my instructable https://www.instructables.com/id/Mind-Control-2-S...and this EEG monitor both use FFT ... the difference is in how they display the FFT output data,

Spectrum analysers display the signal amplitudes against frequency whereas EEG monitors display frequency and amplitude against time.

fix_FFT output

The fix_FFT software used in this EEG Monitor outputs numbers. A large number indicates the presence of a frequency. [1]

  • Photo 1 shows the numbers for a 6Hz sinewave ... there is only one large number
  • Photo 2 shows the numbers for a 6Hz squarewave ... there are three bins with a large number.

Note that the 3rd harmonic at 18Hz has 1/3rd of the fundamental amplitude, and that the fifth harmonic at 30Hz has 1/5th of the fundamental amplitude.

Frequency Bins

The number of frequencies that are assigned to a bin depends on the sampling-frequency and the number of samples.

If the sampling frequency is 64Hz and the number of samples is also 64 then each bin will be 1Hz wide.

If we increase the sampling frequency by a factor of 4 then each bin will be 4Hz wide. For example the number in bin[6] would represent 24Hz, 25Hz, 26Hz, and 27Hz.

The examples shown in the above photos have a bin-width of 1Hz for ease of explanation.

Sampling theory (Nyquist) says that we only need look at the first 32 bins if the number of samples is 64.

Notes

[1]

This Youtube video explains the Fourier transform in a visual manner

Step 5: Design Considerations

The Arduino analog-to-digital convertors have a number of design requirements

Bias

The waveform peaks to your Arduino analog-to-digital (A/D) converters must not go below zero volts or exceed +5volts.

Assuming a 2 volt peak-peak input waveform, then a DC bias of at least 1volt is required.

This may be achieved using:

  • a resistive voltage-divider and a coupling capacitor. The down-side to coupling capacitors is they limit the low frequency response
  • op-amp offset voltages connected to the A/D.

This EEG Monitor uses the 1.5 volt reference voltage from the AD8232 breakout board. Since coupling-capacitors are not required bin[0] of the EEG monitor will respond to changes in DC.

Numbers

The A/D convertor outputs 1023 for a +5 volt input, and 0 for zero volts.

The fix_FFT.ino library expects numbers in the range 0..255.

The following code lines address these requirements:

  • short value = analogRead(adc_input);
  • data[i] = map(value, 0, 1023, 0, 255);

Maximum sampling frequency

“For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz.

That is the maximum possible sampling rate, but the actual sampling rate in your application depends on the interval between successive conversions calls.” [1]

In practice I have found the maximum sample rate to be 8192Hz when sending FFT (fast fourier transform) data to my PC

DC Offset

The DC offset from the input voltage divider only affects bin[0].

My code automatically subtracts the startup reading from all subsequent readings which allows me to track any changes.

Notes

[1]

https://arduino.stackexchange.com/questions/699/ho...

Step 6: Software

Arduino Software:

Software covering each of the following frequency ranges is attached

  • fix_FFT_EEG_DC_32Hz.ino
  • fix_FFT_EEG_DC_64Hz.ino
  • fix_FFT_EEG_DC_128Hz.ino
  • fix_FFT_EEG_DC_256Hz.ino
  • fix_FFT_EEG_DC_512Hz.ino
  • fix_FFT_EEG_DC_1024Hz.ino
  • fix_FFT_EEG_DC_2048Hz.ino
  • fix_FFT_EEG_DC_3200Hz.ino

Copy the contents of your chosen package into a fresh arduino sketch, save it using the same name but without the .ino extension, then upload it to your Arduino.

The bin-widths in Hz may be found by dividing the maximum package frequency by 32.

For example:

  • The bin-width for fix_FFT_EEG_DC_256.ino is 256/32=8Hz
  • The lowest frequency that will appear in say bin[4] of fix_FFT_EEG_DC_256.ino will be 4*8=32Hz
  • Bin[4]will respond to all frequencies between 32Hz and 39Hz since it is 8Hz wide.
  • Bin[5] will respond to all frequencies between 5x8 = 40Hz and 47Hz

Processing Software:

In addition to the above software I have included two Processing sketches for displaying all 32 frequency bins (photo 1) against time:

  • fix_FFT_EEG.pde
  • fix_FFT_EEG_2.pde

Both packages display what is sent to them.

There is, however, a slight difference ... fix_FFT_EEG.pde automatically removes any DC offset regardless of whether the DC offset has already removed.

Use "fix_FFT_EEG_2.pde" if you specifically want to see the offset.

To run these sketches:

  • Download and install Processing 3 from https://processing.org/download/
  • Copy the contents of your chosen package into a fresh Processing sketch, and save it using the same name but without the .pde extension.
  • Connect your Arduino to one of your PC's USB ports
  • Finally, click the top-left button on your processing screen [1]

Note

[1]

You will get a run-time error message if Processing can't find your Arduino. Follow the instructions in the fix_FFT_EEG.pde header if this should happen.

Step 7: Summary

This instructable explains how to make a EEG analyser.

The operation has also been explained with the aid of design notes, videos and photos.

Eight frequency ranges of Arduino software have been provided.

Two sets of Processing software have also been provided.

The processing software allows you to simultaneously view all 32 waveforms

The estimated cost of parts is less than $30.

  Click here   to view my other instructables.

Be the First to Share

    Recommendations

    • Stone, Concrete, Cement Challenge

      Stone, Concrete, Cement Challenge
    • Backyard Contest

      Backyard Contest
    • Water Speed Challenge

      Water Speed Challenge

    15 Comments

    0
    Joe Beaglemister
    Joe Beaglemister

    Question 6 weeks ago

    This is a very fascinating project, and I am in the midst of building this project. I am curious, what power supply do you use for your Arduino?

    0
    lingib
    lingib

    Answer 6 weeks ago

    Thank you for your interest in my project :)
    The project obtains its power from the PC USB port.

    It can also run standalone by connecting the negative lead of a 9 volt battery to the Arduino GND (ground) and the positive lead to the Arduino Vin.

    0
    AfraizT
    AfraizT

    7 months ago

    Great work, Thanks.
    I worked with AD8232 to detect the ECG and EMG and use HC-06 bluetooth module for wireless data transmition and control a game. Next step is EEG monitoring and control.
    This tutorial will help me alot. Thanks

    1
    lingib
    lingib

    Reply 3 months ago

    Thank you for your interest in my project :)

    The connections are detailed in step 3 of my instructable:

    "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"

    You will get strong wink responses if the headband is positioned as shown in https://www.instructables.com/Wink-Detector/.

    Optimum positions for detecting others signals is by trial and error.

    Enter "EEG" in the instructables search window to see what others have done.

    Google "EEG probe positions" to find optimum positions for the frequency bands of interest.

    Be aware that EEG signals are extrememly weak and often slow to respond.

    0
    lingib
    lingib

    Reply 7 months ago

    Thank you for your interest and comment :)
    Good luck with your project.

    0
    guifreibarz
    guifreibarz

    Question 3 months ago

    Hey! Thank you so much for this project!

    I've alredy bought all the parts needed but i have a big question.
    Where, and how should i conect the rest of electrodes?

    I don't understand where should i conect them, since i see you are conecting them to the jack input, and there's only one jack input...

    Again, thank you so much!

    0
    amansinghaljpr
    amansinghaljpr

    7 months ago

    AD8232 is primarily meant for measuring ECG do you think modified AD8232 for EEG will work equally good ?

    0
    lingib
    lingib

    Reply 7 months ago

    Thank you for your interest in my article :)
    If you check the video you will see that a modified AD8232 Heart Monitor definitely detects electrical activity. The usefulness depends on where you connect the probes.
    The following article https://www.instructables.com/EEG-AD8232-Phase-2/ may be of interest as the author is using my modified AD8232

    0
    mari.malta.carifi
    mari.malta.carifi

    7 months ago

    Hello,
    I am from Brazil and I am learning about arduino. I was build the prototype and I had some issues with the program. I think it is not reading the code.
    When I run the program this message error is printed:

    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xa2
    Problema ao carregar para a placa. Veja http://www.arduino.cc/en/Guide/Troubleshooting#up... para sugestões.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xa2
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xa2



    Could you help me?

    0
    lingib
    lingib

    Reply 7 months ago

    Thank you for your interest in my instructable :)
    I don't recognize the error messages that you are getting.
    My code works with the Arduino IDE and the hardware listed in my instructable.

    0
    senrab51
    senrab51

    10 months ago

    This looks great, thank you so much for sharing. I'm ordering parts today and will let you know how I do with it!
    Kevin

    0
    lingib
    lingib

    Reply 10 months ago

    Thank you for your interest in my project :)

    Something that I have since discovered is that you can get some interesting results by combining different frequency "bins" and displaying the result as shown in the attached image.

    The combined trace shown in bin[1] dips when you wink the left eye and rises when you wink the right eye which could eliminate the hardware in my instructable https://www.instructables.com/id/Wink-Detector/

    The time scale at the bottom shows that I was holding each eye closed for a period of time before opening. The reason for using even numbered bins is that saw-tooth waveforms (slopes) comprise even harmonics ... the traces are responding to the changing voltage with each eye movement.

    combined_traces.jpg
    0
    freerpg29
    freerpg29

    11 months ago on Step 7

    very good instructable. I have been trying to get into this field for a while to make some gaming type applications. thank you so much. I need to increase my coding experience soon but am very happy to see this.
    is there any way to read all 32 traces?
    also I see the types of brain waves include infra-low, delta, theta, alpha beta and gamma. is there a way to detect all of these?
    lastly as the brain is one big machine can we use this EEG to pin point where certain waves are coming from in the brain?

    0
    lingib
    lingib

    Reply 10 months ago

    Thank you for your interest in my project ... I too am thinking along these lines :)

    Each of the Arduino programs outputs 32 traces.

    The on-board display is only capable of displaying four bins at any one time ... just select the bins for each frequency band of interest as outlined in code lines 149..161.

    The Processing software allows you to view all 32 bins at once as shown in Photo1 step 6.

    You will need to experiment where to position the probes on your head. When placed across the forehead the probes are mainly responding to eye-muscle activity.