Blink a Light with Your Brain!

Let’s learn how to connect our brain data using the Serial port by controlling a light with our brain!

Estimated Time 

30 minutes to one hour

Number of People

1- 2 students per materials set

Necessary Supplies

  • One NeuroMaker BCI Unit
  • One Uno Board
  • USB cable 
  • Computer

Necessary Program Files

Please see the code below

Pre Check Items

  • NeuroMaker BCI Unit is fully charged
  • NeuroMaker BCI Connect Software is running properly

Background

In this lesson, we are going to establish communication from our BCI device to an UNO board through the serial port! Our NeuroMaker BCI software is automatically set up to transfer information from our live attention algorithm to any project we wish to control. Once we have mastered this communication, we will be able to power any projects we want to control with our brain!

Table of Contents

Project Instructions

If you haven’t yet done this, please install the Arduino IDE. This is the coding environment you will be using to program the UNO board. Download the IDE via this link below: 

 https://www.arduino.cc/en/Main/Software

You will notice on your UNO board that there is a built in light (called an LED) that we can control at pin 13. The location of this LED is circled in red in the picture to the right. In this exercise we are going to create three different blink states:

  • When our attention score is low (between 0 and 30) this light will blink once every second.
  • When our attention score is moderate (between 30 and 60) this light will blink once every half second.
  • When our attention score is high (above a 60) this light will blink once every tenth of a second.

Please note: directly under the pin 13 LED light are two other lights called TX and RX. These lights will light up when data is sent back and forth so please disregard those for this exercise!

The Code

				
					
char attentionData;
int LEDPin = 13;


void setup() {
  // put your setup code here, to run once:

pinMode(LEDPin, OUTPUT);
Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:

while (Serial.available() > 0){
  attentionData = Serial.read();
}

if (attentionData >= 0 && attentionData < 30){
  digitalWrite(LEDPin, HIGH);
  delay(1000);
  digitalWrite(LEDPin, LOW);
  delay(1000);
}
if (attentionData >= 30 && attentionData < 60){
  digitalWrite(LEDPin, HIGH);
  delay(500);
  digitalWrite(LEDPin, LOW);
  delay(500);
}
if (attentionData >=60 && attentionData <= 100){
  digitalWrite(LEDPin, HIGH);
  delay(100);
  digitalWrite(LEDPin, LOW);
  delay(100);
}

}
				
			

Video Guide