This post is the last in a series aimed at documenting the process behind making a functional BCI at low-cost and with minimal experience. If you haven’t done so, I’d recommend first reading my introductory post about this series that details the materials and costs for the project. The other posts in the series can be found here.

So, we’ve made our headset. We’ve collected data. We’ve trained a Neural network with that Data. All that remains now is to make our device!

The Agenda

  1. Set-up the hardware
    • What you need:
      • Arduino Uno
      • Breadboard (tiny)
      • Buzzer
      • 100 ohm resistor
      • EEG headset
  2. Implement the software
    • What you need:
      • Arduino IDE
  3. Put it all together.
    • What you need:
      • Zip-ties
      • 9 V battery
      • Battery cable

Step 1: The hardware set-up

Let’s first get our hardware circuitry set-up. Our actual device is pretty simple: it is the headset with an Arduino to process data and a buzzer to warn in the case of Mind-Wandering.

  1. Let’s first get our buzzer set-up. We’re going to use pretty much the same configuration as our data-collection module. Place the buzzer, 100 ohm resistor and wires as show below. The red wire (connected to +ve terminal of buzzer) will go to pin 10 on the Arduino. The black goes to the GND pin.

2. Now, let’s connect to the headset. Attach the T-pin extension to the Rx pin (temporarily – remember to detach it when uploading the code to the Arduino), and the Ground extension to the GND pin.

Step 2: Implement the Software

This was probably the most frustrating part of my journey creating this device just because the Arduino’s memory limits made running a Neural Network super tedious. It took hours of memory optimization to get a NN to run including pruning down the network to its final architecture: 7x6x5 hidden layers.

After getting the Network to run, I had to be able to read in the inputs in such a way that they could be passed into the network. This meant removing teh first 3 data points, concatenating 3 samples of 8 elements data points to 1 sample of 24 elements, and scaling the final sample by the same scaling factor used in training the Neural Network.

Once I performed some more memory optimization and pruning and got my network to take in real-time inputs and return expected outputs, I coded the logic behind the buzzer. Given that the accuracy of the trained network was on the lower end of ‘good’ – i.e. closer to 70% – it wouldn’t make sense to beep every-time the output is above 0.5. I decided to have the circuit beep only if 3 consecutive outputs were above 0.5 (Mind-Wandering detected), hoping that tit would average out the finicky nature of the network and also have good enough latency(9 seconds) (i.e. quick enough to alert mind-wandering to be reliably called a ‘real-time’ BCI).

The final version of my code to do all this can be found here: https://github.com/JoshetaSrinivasan/DistractedDrivingDetect/blob/main/MindWanderRealTime.ino

The code does require an additional library installation – I used the BasicLinearAlgebra library to perform all the matrix computations. You can download the library as I demonstrated in my first post.

Again, I believe the code to be decently documented but I’ve also recorded a walkthrough:

Step 3: Putting it all together!

And now, we have the hardware and software part of teh device working as it should be. All that remains to be done is putting it all together in a wearable fashion and making sure it works offline – i.e. without being connected to the laptop.

To do so, I first connected a 9V battery to the Arduino using a battery cable as shown below to power the device untethered from the laptop:

Now, place everything we have neatly on the EEG headset, and tie it to the headset using zipties!

I didn’t get a picture of this, but I ended up turning the zip-ties so that the pointy ends were facing up and not in a treacherous position of scalping me.

And we are done! All that remains is to give her a whirl!

Final Thought and Next Steps

Overall, building the device proved to be a really fun learning experience for me and an engaging way to get my feet wet with several topics including signal processing (though this project didn’t need much of it), Neural Networks, Memory optimization on Microcontrollers, as well as the general work-flow in BCI creation. The latter of which served super useful in the short-term (as I was concurrently working with a university research team building BCIs) as well as, I’m sure, will serve useful in the long-term – seeing to the fact that Brain-interfacing is a field I may establish a career in.

However, I suspect that I’m not quite done with the whole project. There are several improvements I’m considering. Much of them are performance related:

  • Seeing if I can extract raw signals from the electrode and perform my own signal analysis and increase the sampling rate.
  • Would a different Neural Network structure increase accuracy ?
  • More data!
  • Exchanging the EEG device for a less rudimentary one – the Muse 2 headset.

But others are aesthetic:

  • 3D printing a custom case to conceal the electronics
  • Making a custom PCB circuit to make the connections less flimsy and also reduce the size of the electronic addition to the headset.

However, the main purpose of this series was to propose a low-cost, minimal-experience, gentle introduction into BCIs by making a relatively-well functioning Neuro-feedback device. And I believe, the goal has been met.

Comments are closed