Control Three LED Lights with your Brain!

Now that we have controlled one light on our UNO controller, let’s control three lights at the same time!

Estimated Time 

Approximately One Hour

Number of People

1- 2 students per materials set

Necessary Supplies

  • One NeuroMaker BCI Unit
  • One Uno Board
  • USB cable 
  • Computer
  • At least four Male to Male Jumper Wires
  • Three current limiting resistors (This above video uses 250 Ohm resistors)
  • Three LED lights: One red, one yellow and one blue
  • One Breadboard

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 the last lesson, we learned how to control the LED light included on our UNO board. Now it’s time to break out our other electronics and build our very first BCI enabled circuit! We are going to hook up three different LED lights to our circuit that will act very similar to the project we worked on last time. Each one will indicate different levels of our attention state. 

By completing this project, you will have created your first multi-actuator BCI project! In non-nerd speak, this means you will have controlled multiple devices, in this case 3 LED lights, with your brain.

Table of Contents

Project Instructions

We are going to need to set up a circuit for this project! We are going to set up three different LED lights that will turn on if the attention value we want is reached. The code for this project is provided below, but first let’s set up our simple circuit. In our circuit, we must do the following things:

  • Connect digital pin 10 to a resistor and then that resistor to a red LED
  • Connect digital pin 9 to a resistor and then that resistor to a yellow LED
  • Connect digital pin 8 to a resistor and then that resistor to a blue LED
  • Finally, we need to connect our LED lights all together to the ground pin on our board

To the right of this text, you can see a simple circuit diagram of the project we need to create!

If this is your first time using an LED with an UNO board, keep in mind the following points:

  • Each LED has two “legs”. The long side is called the anode and needs to be connected to the resistor side. The short side is called the cathode and must be connected to the side of the wiring going to ground. 
  • An UNO board will supply 5 volts to our circuit. This is too much for most LEDs, so please make sure you include the resistors inside of the diagram to make sure they don’t burn out!

Once your circuit is ready, now we need to code! The code below will complete the following actions

  • When our attention score is low (between 0 and 30) the blue LED will turn on, the yellow LED will turn off and the red LED will turn off.
  • When our attention score is moderate (between 30 and 60) the yellow light will turn on, the red light will turn off and the blue light will turn off.
  • When our attention score is high (above a 60) the red LED will turn on, the yellow LED will turn off and the blue LED will turn off.

The Code

				
					char attentionData;
int redLED = 10;
int yellowLED = 9;
int blueLED = 8;

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

pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(blueLED, 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(redLED, LOW);
  digitalWrite(yellowLED, LOW);
  digitalWrite(blueLED, HIGH);
}
if (attentionData >= 30 && attentionData < 60){
  digitalWrite(redLED, LOW);
  digitalWrite(yellowLED, HIGH);
  digitalWrite(blueLED, LOW);
}
  if (attentionData >= 60 && attentionData < 100){
  digitalWrite(redLED, HIGH);
  digitalWrite(yellowLED, LOW);
  digitalWrite(blueLED, LOW);
  }
}
				
			

If you can successfully run this project, what else could you create with this knowledge? Could you connect 5 different LED lights to display more attention states? What about groups of LEDs that power on at the same time?