The project revolves around creating a brain-computer interface (BCI) for home automation using Seeed Studio Wio Terminal, an EEG sensor, TinyML powered by Edge Impulse, allowing users to control smart devices with their thoughts. The motivation behind the project stems from the desire to explore innovative ways of human-machine interaction and enhance the accessibility of home automation.
Why:
The idea originated from the intersection of emerging technologies like TinyML and the potential applications of EEG in user interfaces. The aim is to offer a unique and intuitive method of controlling smart devices, promoting a seamless integration of technology into daily life.
How it works:
1. Hardware Setup:The Wio Terminal and EEG sensor are connected, creating a wearable device.
2. Data Acquisition: EEG signals are collected, processed, and fed into the Edge Impulse platform for training a TinyML model.
3. Model Training: Edge Impulse is utilized to train a model capable of interpreting brain signals and generating corresponding commands for home automation.
4. Integration with Home Automation: The trained model is deployed on the Wio Terminal, allowing users to control smart devices by simply thinking about specific actions.
Connect Wio TerminalIn this step, we will set up the SeeedStudio Wio Terminal as our edge device to collect datasets and run machine learning inference.
For a comprehensive guide on using Edge Impulse with Wio Terminal, refer to the Wio Terminal Edge Impulse Getting Started.
Connecting the Wio Terminal:
1. Upload EdgeImpulse UF2 Firmware:
- An external drive named "Arduino" should appear on your PC.
- Drag and drop the downloaded Edge Impulse UF2 firmware files onto the Arduino drive.
- Edge Impulse is now successfully loaded onto Seeeduino Wio Terminal!
This process ensures that your Wio Terminal is ready for data collection and running machine learning models as part of your brain-computer interface projec
Connecting EEG Sensor and TestingIn this step, we will set up the EEG sensor to record brainwaves from the prefrontal cortex using an Wioterminal and the BioAmp EXG Pill.
Electrophysiology
Brains do operate with electrical signals, but not at all in the same way our electronic devices operate. There's a heck of a lot more going on in the brain than just electrical signalling, but let's stay focused on that aspect. The human brain contains 86 billion neurons, with each of those neurons receiving input from multiple other neurons in a network.
Each neuron acts like a signal-processor on these inputs; when a neuron has decided that it has received enough inputs within a certain time-frame, it 'fires' an electrical pulse to neurons further down the network. This is an all-or-nothing response - downstream neurons only know that a neuron has fired, they don't get any other information. The action potential is pretty fast too; the peak voltage pulse is over in about a millisecond.
The brain doesn't have a centralized 'core' like the CPU of a computer. The neurons of the brain operate in parallel, giving it huge compute and bandwidth. But each neuron needs to do signal-processing on multiple inputs simultaneously, so it would be better to have the inputs be coordinated. The brain orchestrates this by operating in cycles, with neurons all firing in bursts to maintain synchronization (if they need to fire at all).
Action potentials into Brain waves
We can't detect these fast and teeny-tiny action potentials though skull, flesh, and skin, but in aggregate, we can measure the local field potential reflecting their summed activity. The fields are of course damped and smeared by all the meat and bone between our sensor electrodes and the brain, so it's hard to get a localized or even very accurate signal, but amazingly, we can still measure our brain activity!
During alert states, the brain operates at higher frequencies than when relaxed or various sleep phases. You can't directly detect these internal states consciously, but by recording and processing them, we have a 'biofeedback' loop that lets you actively learn to control your brain state!
What is Electroencephalography (EEG)?
Electroencephalography (EEG) is a test used to evaluate the electrical activity in the brain, detecting potential issues with brain cell communication.
About BioAmp EXG Pill:
The BioAmp EXG Pill is a unique, pill-sized chip capable of recording publication-grade biopotential signals from various body parts, including the heart (ECG), brain (EEG), eyes (EOG), and muscles (EMG).
Step 1: Assembly
Step 2: Skin Preparation
- Apply Nuprep Skin Preparation Gel to the skin surface where electrodes will be placed, removing dead skin cells and ensuring a clean skin surface.
Step 3: Connecting Electrode Cable
Step 4: Electrode Placements
Options to Measure EEG
Option 1 - Gel Electrodes:
- Connect BioAmp Cable to gel electrodes.
- Apply IN+ and IN- cables on the forehead and REF (reference) at the bony part behind the earlobe.
Option 2 - Dry Electrode Band:
- Connect BioAmp Cable to Brain BioAmp Band, placing IN+ and IN- on the forehead.
- Connect REF using a gel electrode behind the earlobe.
- Apply a small drop of electrode gel on dry electrodes for optimal results.
Step 5: Connections
Note:Ensure precise connections, especially for GND and VCC, to prevent sensor damage.
Step 6: Download Arduino IDE
- Download Arduino IDE [here](https://www.arduino.cc/en/software) (version 1.8.19 was used for this project).
- Connect Arduino Uno to your laptop via USB cable.
Note:Maintain a 5m distance from AC appliances for optimal signal acquisition, and avoid laptop charging during testing.
These steps set up the EEG sensor for data acquisition, laying the foundation for the brain-computer interface project.
now copy the following code to get readings from the sensor and plot it on arduino ide serial plotter
#define SAMPLE_RATE 256
#define BAUD_RATE 115200
#define INPUT_PIN A0
void setup() {
// Serial connection begin
Serial.begin(BAUD_RATE);
}
void loop() {
// Calculate elapsed time
static unsigned long past = 0;
unsigned long present = micros();
unsigned long interval = present - past;
past = present;
// Run timer
static long timer = 0;
timer -= interval;
// Sample
if(timer < 0){
timer += 1000000 / SAMPLE_RATE;
float sensor_value = analogRead(INPUT_PIN);
float signal = EEGFilter(sensor_value);
Serial.println(signal);
}
}
float EEGFilter(float input) {
float output = input;
{
static float z1, z2; // filter section state
float x = output - -0.95391350*z1 - 0.25311356*z2;
output = 0.00735282*x + 0.01470564*z1 + 0.00735282*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - -1.20596630*z1 - 0.60558332*z2;
output = 1.00000000*x + 2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - -1.97690645*z1 - 0.97706395*z2;
output = 1.00000000*x + -2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - -1.99071687*z1 - 0.99086813*z2;
output = 1.00000000*x + -2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
return output;
}Now you will be able to visualise the brain signals on Serial plotter window, it will be looking like
Thanks to the Tiny Machine Learning platform, Edge Impulse Studio, and Seeed Studio's Wio Terminal, creating this brain-computer interface project is made accessible. The project combines machine learning and embedded electronics, and I'll guide you step by step to help you build it.
Step 1: Data Collection 📚
Since this is a machine learning project, the initial setup involves collecting sufficient data to create a dataset. In this scenario, we'll be collecting EEG sensor data from the Wio Terminal.
Step 1.1: Create Edge Impulse Account
1. Go to [Edge Impulse Studio](https://studio.edgeimpulse.com/login).
2. Sign up for an account or log in if you already have one.
Step 1.2: Create Edge Impulse Project
1. After logging in, click on your profile and select "Create a new project" or use [this URL](https://studio.edgeimpulse.com/).
2. Provide a project name and click "Create new project."
Now you're on the Edge Impulse Studio page, indicating that you've successfully created an Edge Impulse project
Connect Wio Terminal using WebUSB:
- Choose "Connect using WebUSB."
- Select the Wio Terminal Port and click "Connect."
- Connected successfully 🎉
Start Collecting Data for Light Bulb ON:
- Choose the right sensor.
- Label data as "ON."
- Set the sample length to 10000 milliseconds (10 seconds).
- Provide the frequency of incoming data.
- Click "Sample" to start collecting 10-sec accelerometer data for turning the light bulb ON.
- Start Collecting Data for Light Bulb ON:Choose the right sensor.Label data as "ON."Set the sample length to 10000 milliseconds (10 seconds).Provide the frequency of incoming data.Click "Sample" to start collecting 10-sec accelerometer data for turning the light bulb ON.
Repeat for Light Bulb OFF:
- Follow the same process, labeling data as "OFF."
- Repeat for Light Bulb OFF:Follow the same process, labeling data as "OFF."
Collect 18 Samples for ON and OFF:
- Ensure a balanced dataset for better model performance.
- Collect 18 Samples for ON and OFF:Ensure a balanced dataset for better model performance.
- Randomly split the collected data into training and testing datasets using Edge Impulse Studio's "Rebalance dataset" feature.
- Select parameters, including window size, processing block (Spectral Analysis), and learning block (Neural Network).
- Set Output features (labels) as "ON" and "OFF."
- Use Spectral Analysis for accelerometer data.
- Configure signal processing for accurate light bulb control.
- Adapt neural network architecture for binary classification (ON/OFF).
- Test live classification with accelerometer actions for turning the light bulb ON and OFF.
- Classify test data to assess model accuracy for light bulb control.
- Download the modified Impulse model using the Arduino Library from Edge Impulse Studio.
- Update the Arduino sketch to interpret model output as commands for turning the light bulb ON and OFF.
- Select the right port and board; click upload.








Comments