Control a Motor with Your Brain!

Let’s learn how to control simple movements of a servo motor with your brain by creating a dial that shows your real time attention score!

Estimated Time 

Approximately one hour for students familiar with a servo motor and about 2 hours for those learning this for the first time.

Number of People

1- 2 students per materials set

Necessary Supplies

  • One NeuroMaker BCI Unit
  • One Uno Board
  • One Servo Motor: This demo uses a SG90 servo motor but other models also work
  • Three male to male jumper wires
  • A background for a display: a paper plate, piece of paper or anything else you can think of!
  • Drawing materials like markers or pencils
  • 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 build our own physical attention score display! This visual dial will act like a clock and tell us what our attention score is on a physical device.

Table of Contents

Project Instructions

This project will require us to set up a Servo motor. Our code set up below connects the digital control of our motor to pin 3 as shown in the picture to the side.

If you are brand new to the wild world of servo motors, we highly recommend viewing the following links:

  • General servo motor and Arduino board introduction: https://www.instructables.com/Arduino-Servo-Motors/
  • Video walkthrough of setting up a servo motor and defining an object: https://youtu.be/aFHu65LiFok

In this project, you will need to design your own background for a reading. This is where we can put our creativity and STEAM skills to work. Here are a few items to consider when building your project:

  • What should you use for the backboard of your dial? Is it sturdy enough to stay still and is it delicate enough to break a hole to install a servo motor?
  • Should you add the hand of a clock to your dial? In the video above, we only use the plastic arm of the servo motor but this would be much better looking with something attached on top of it!
  • Should you add color to your dial? Maybe we should color in areas that are important in our attention reading so that we can see them at a glance.

Grab your markers, pencils and whatever else you can to make this look gourgeous!

The Code

				
					
#include <Servo.h>
Servo servo;

int attentionData;
int servoPin = 3;


void setup() {

Serial.begin(115200);
servo.attach(servoPin);

}

void loop() {

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

  //servo.write(0);
  if (attentionData > 0){
  servo.write(getAngle(attentionData));
  }

}

int getAngle(int attentionData){
  return (attentionData * 180) / 100;
}