Brainwaves Fly a Drone

by Tony--K in Circuits > Arduino

15895 Views, 207 Favorites, 0 Comments

Brainwaves Fly a Drone

drone 0, flying drone.jpg

Drones are fun to fly, and it’s possible to do limited flying using brainwaves. The headset senses my brainwaves and transmits them to a small computer. When I increase my attention level, the computer converts the signals and passes them to the drone’s controller, which I have connected to the computer. When I relax my mind, the drone lands.

The headset is a NeuroSky MindWave Mobile 2, the computer is an Arduino Uno microcontroller, and the Bluetooth module is an HC-05.

For some reason (?) the YouTube video will not embed into this instructable. Here is the link:

https://www.youtube.com/watch?v=bp1CeDSWQAg

There are 6 main steps in this project:

  1. Wire the HC-05 to the Arduino.
  2. Configure the HC-05 and pair it with the MindWave.
  3. Connect the servo to the drone's controller.
  4. Wire the Arduino.
  5. The Arduino Sketch (The Code)
  6. Upload the Arduino sketch and use it.

If you’re not familiar with these devices, the following links may be useful:

Getting started with Arduino: https://www.arduino.cc/en/Guide

https://www.instructables.com/A-Beginners-Guide-to-Arduino/

Online Arduino class: https://www.instructables.com/Arduino-Class/

NeuroSky’s website: https://store.neurosky.com/pages/mindwave

http://developer.neurosky.com/docs/doku.php?id=start

Differences between the 4 models of MindWave: http://support.neurosky.com/kb/mindwave-mobile-2/whats-the-difference-between-mwm2-mwm-and-original-mwm

NeuroSky’s Arduino project (it uses a BlueSMiRF Blluetooth module instead of the HC-05 I used. The sample code (which runs on an Arduino) should work okay regardless of the type of Bluetooth module.):

http://developer.neurosky.com/docs/doku.php?id=mindwave_mobile_and_arduino

Supplies

PARTS for the electronics:

  1. NeuroSky MindWave Mobile 2 headset and 1 AAA battery
  2. A computer (I used an Apple iMac)
  3. Arduino Uno or another model and its USB cable
  4. HC-05 Bluetooth module
  5. Servo motor (I used a Solarbotics HXT900 Micro Servo)
  6. Breadboard and breadboard wires
  7. Green LED and yellow LED
  8. 2 x 330 ohm resistors
  9. 2 x 1K ohm resistors
  10. 2 x 2K ohm resistors
  11. 10K ohm potentiometer
  12. Power source, about 5 volts, such as 3 AA batteries in a holder

PARTS for the servo connection to the drone’s controller:

  1. 2 elastics
  2. a few toothpicks
  3. small piece of thin cardboard
  4. scissors
  5. glue
  6. tape

Wire the HC-05 to the Arduino

Fork 1A.jpg
Fork 1B.jpg
Fork 3.jpg

A few websites describe how to set up an HC-05 Bluetooth module for the NeuroSky MindWave, but none of the methods worked for me. Maybe the reason was that my HC-05 has a newer version of firmware? Or my MindWave is a newer model? Anyway, I researched other Internet websites for info about configuring and pairing an HC-05, and eventually figured out how to do it.

Photos of the front and back of an HC-05 are shown.

Plug the HC-05 into the breadboard and connect it to the Arduino as described below and shown in the photo.

  1. HC-05‘s RXD to pin 11 via a voltage divider made from 2 resistors,
  2. TXD to pin 10,
  3. GND to GND,
  4. EN to pin 9 via a voltage divider made from 2 resistors.
  5. Do not connect HC-05’s VCC yet.

The reason for using voltage dividers is that HC-05‘s RXD and EN tend to die after getting 5 volts for some time, and the voltage should be reduced to 3.3 volts. The voltage divider consists of a 1K ohm resistor with one end connected to Arduino’s 5 volts and the other end to a 2K ohm resistor with its other end connected to GND. Two voltage dividers are needed, one for RXD and the other for EN.

Configure and Pair the HC-05

Fork 2.jpg
Fork 6.jpg

Find the sticker on the MindWave showing the Bluetooth address. This will be needed in one of the HC-05 commands. If your MindWave doesn’t have a sticker, NeuroSky’s Arduino project describes how to determine it, under the title “Determining the MAC address of your MindWave Mobile” in this website: http://developer.neurosky.com/docs/doku.php?id=mi...

1. Start the Arduino app on the computer.

2. Connect the Arduino’s USB cable to the computer. The green light on the Arduino should be on.

3. Download the sketch .ino file located at the end of this step, or copy the following code, which relays data between Arduino’s Serial Monitor and the Bluetooth module, and paste it into a new Arduino sketch. (When writing these instructions, the instructables system sometimes dropped part of the #include statement located at the beginning of the code. It should be #include followed by a left arrow < followed by SoftwareSerial.h followed by a right arrow >).

I found the code in the following YouTube video: https://www.youtube.com/watch?v=lTvYbnr6aBo

#includeSoftwareSerial BT(10,11);
void setup() { pinMode(9,OUTPUT); digitalWrite(9,HIGH); Serial.begin(38400); BT.begin(38400); Serial.println("Bluetooth AT command mode"); } void loop() { if(BT.available()) Serial.write(BT.read()); if(Serial.available()) BT.write(Serial.read()); }

4. Upload the sketch to the Arduino.

5. While pressing the small button over the EN pin on the HC-05, connect HC-05‘s VCC to Arduino’s +5v and keep the button pressed for a few seconds until the red light on the HC-05 begins to blink on for 2 seconds and off for 2 seconds.

6. Open the Arduino’s Serial Monitor (top right corner in the Arduino app window) on the computer and set the options in the lower right corner to “Both NL & CR” and “38400” baud rate.

7. Click inside the input line of the Serial Monitor window. Type AT on the computer’s keyboard and press Return. If the response is “OK” then continue. If it’s not “OK” then try again. It sometimes doesn’t work the first time.

8. Power-on the MindWave. The light beside the switch is steady blue on the MindWave Mobile 2. Earlier models of the MindWave behave differently.

9. Type AT commands as shown below. The response should be “OK” after each command.

AT+UART=57600,0,0 Defines the baud rate used by the MindWave.

AT+ROLE=1 Sets the HC-05 as Master rather than Slave.

AT+PSWD=0000 Sets the password used by the MindWave.

AT+CMODE=0 To connect the HC-05 to a specific device.

AT+CLASS=0 Specifies the Class of Device.

AT+INQM=1,9,48 Sets parameters for pairing.

AT+INQ to see if the HC-05 recognizes the MindWave. This may take 15-20 seconds to find the MindWave. One of the displayed devices should have the same address as on the MindWave sticker, in the format xxxx:xx:xxxxxx. This address is used in the next 3 commands (shown as addr) except the colons must be replaced by commas.

AT+PAIR=addr,30 (Strangely, there was no “OK” response here.)

AT+BIND=addr (The red light on HC-05 still blinks on for 2 seconds and off for 2.)

AT+LINK=addr

10. The red light on the HC-05 should make 2 quick blinks every 3-4 seconds. The first time I did the LINK command, the red light didn’t change. So I double-checked the wire pins were pushed down properly on the Arduino and breadboard, pulled out the +5v wire from the HC-05, did step #5, and typed the PAIR, BIND and LINK commands. This time, the red light changed to 2 quick blinks every 3-4 seconds. This means the devices are paired. Next time you use the devices, they will pair automatically within a few seconds.

11. Disconnect the HC-05’s TXD wire from the Arduino’s pin 10 and connect it to the Arduino’s RX (pin 0), disconnect the HC-05‘s wires from the voltage dividers and remove them, and remove the resistors used as the voltage dividers. The wiring should now be as shown in the photo.

12. Close the Serial Monitor.

13. Power-off the MindWave.

14. Disconnect the USB cable from the Arduino or the computer.

15. Quit the Arduino app.

Connect the Servo to the Drone's Controller

drone 1, controller.jpg
drone 2, H-shape.jpg
drone 3, servo.jpg
drone 4, servo &amp; controller.jpg

There are two ways of connecting to the drone controller:

  1. The controller could be hacked as follows: Remove the potentiometers that the joysticks are attached to, and connect the Arduino to the controller’s circuit board where the middle pins of the potentiometers had been connected. The following website has excellent instructions for this hack: https://www.hackster.io/WesleyCMD/mind-control-drone-c8b28a The project uses only the Attention level signal from the brainwave headset.
  2. My drone controller is so small that I thought the potentiometers would be tiny and too difficult to extract. So, I decided to use a servo to move the joystick for the drone’s throttle, based on the Attention level signal.

The Attention level is easy to obtain and work with. When I researched NeuroSky projects on the Internet, I found that most projects used only Attention. Meditation is also easy to use, but it is related to Attention. Generally, if Attention is high then Meditation is low and vice versa. Some people may be able to set their Attention and Meditation levels independently, but based on my research on the Internet, this is unusual.

Eye-blinking can also be detected by the MindWave headset, but from what I have read, obtaining the Blinking signals and making use of them seems much more complicated than the Attention and Meditation signals.

The first photo shows how the servo is attached to my controller by two elastics. As you can see, there is a gap between the servo arm and the joystick. The second photo shows an H-shape made from pieces of toothpicks glued together and glued to a small piece of thin cardboard. One end is then taped to the servo arm and the other end fits the joystick, as shown in the third and fourth photos.

If you decide to do something similar, the connection between the servo arm and joystick could be very different, depending on the size and shape of your drone controller.

Wire the Arduino

drone 6, Arduino wiring 2.jpg
drone 5, Arduino wiring 1.jpg

Starting with the circuit after step #11 in Configuring and Pairing the HC-05 (above) the additional wiring should be as described and shown in the photo.

  1. One wire of a 330 ohm resistor to pin 2 and the other wire to the long wire of the green LED. The short wire of the green LED goes to minus on the breadboard.
  2. One wire of a 330 ohm resistor to pin 4 and the other wire to the long wire of the yellow LED. The short wire of the yellow LED goes to minus on the breadboard.
  3. Pin 9 goes to the signal wire of the servo. It’s the yellow one.
  4. Orange wire of the servo goes to plus of the separate power source.
  5. Brown wire of the servo goes to minus on the breadboard.
  6. The minus of the separate power source goes to minus on the breadboard.
  7. 10K potentiometer to breadboard plus and minus, with middle pin to analog pin 0

To double-check, the following 7 wires should be connected to the breadboard’s minus: the Arduino’s GND, the short wires of both LEDs, the servo, the separate power source, the HC-05 and the potentiometer. And the following 3 wires should be connected to the breadboard’s plus: the Arduino’s +5V, the HC-05 and the potentiometer.

The Arduino Sketch (The Code)

When Attention is high, the code will turn on 2 LEDs and move a servo arm attached to the throttle joystick of a drone controller.

The code has the following main functions:

  1. Read data from the MindWave.
  2. Obtain Attention data and display it in the Serial Monitor on the computer.
  3. Turn on the yellow LED when Attention is more than 50 and off if lower, and turn on the green LED when Attention is more than 70 and off if lower.
  4. Move the servo arm when Attention is more than 50. The movement has a maximum of 30 degrees because my throttle joystick doesn’t allow any more than that. The potentiometer adjusts the maximum (no higher than 30 degrees). With a fully charged drone battery, the potentiometer should be at its mid-point. As the drone’s battery is being used up, the potentiometer should be turned higher.
  5. The code makes the drone lift gradually by increasing the throttle to 30% of the maximum set by the potentiometer for 0.3 seconds, to 50% for another 0.3 seconds, to 70% for 0.3 seconds, and finally to 100%. Before including this feature, the drone would lift very quickly and become unstable when it suddenly reached the end of the string. And the reason for the string is to keep the drone from flying away upwards or sideways.

The Arduino sketch (the code) may be downloaded as the .ino file located at the end of this step, or the following code could be copied and pasted into a new Arduino sketch. (When writing these instructions, the instructables system sometimes dropped part of the #include statement located at the beginning of the code. It should be #include followed by a left arrow < followed by Servo.h followed by a right arrow >).

/*
When Attention is high, this code will turn on 2 LEDs and move a servo arm

attached to the throttle joystick of a drone controller. December 26, 2020.

Yellow LED on when Attention is more than 50

Green LED on when Attention is more than 70

Servo moves to position set by potentiometer (between 0 and 30 degrees)

Hardware: Arduino with HC-05 Bluetooth and NeuroSky MindWave Mobile 2

*/

#include<Servo.h>

#define BAUDRATE 57600

#define YLED 4

#define GLED 2

////////// Variables

Servo myservo;

byte payloadData[32] = {0};

byte Attention=0;

byte checksum=0;

byte generatedchecksum=0;

int Plength;

int val; // variable to read the value from the analog pin

int val2; // variable to hold temporary value for gradual ascent

int countup = 0; // counter for steps in gradual ascent

int potpin = 0; // analog pin used to connect the potentiometer

////////// Arduino setup

void setup() {

Serial.begin(BAUDRATE); // baud rate for the MindWave

pinMode(YLED, OUTPUT); // initialize the LED pins as output

pinMode(GLED, OUTPUT);

Serial.println("Attention Values"); // display title in Serial Monitor

myservo.attach(9); // attach the servo on pin 9 to the servo object

myservo.write(0); // move the servo to 0 degrees

delay(15); // give the servo time to move there

}

////////// Read data from the MindWave

byte ReadOneByte()

{

int ByteRead;

while(!Serial.available());

ByteRead = Serial.read();

return ByteRead;

}

////////// Main program

void loop()

{

////// Look for sync bytes and read data from the MindWave

while (1)

{

if(ReadOneByte() == 170)

{

if(ReadOneByte() == 170)

{

Plength = ReadOneByte();

if(Plength == 32)

{

generatedchecksum = 0;

for(int i = 0; i < Plength; i++)

{

payloadData[i] = ReadOneByte(); //Read payload into memory

generatedchecksum += payloadData[i] ;

}

generatedchecksum = 255 - generatedchecksum;

checksum = ReadOneByte();

////// Obtain Attention data and display it in the Serial Monitor

if(checksum == generatedchecksum)

{

if (payloadData[28]==4)

{

Attention = payloadData[29];

Serial.println(Attention, DEC);

////// Light the LEDs and move the servo

if (Attention>50)

{

digitalWrite(YLED, HIGH); // turn yellow LED on

val = analogRead(potpin); // read the value of the potentiometer

// (value between 0 and 1023)

// The potentiometer adjusts the maximum throttle. With a fully

// charged drone battery, the potentiometer should be at its

// mid-point. As the drone’s battery is being used up, the

// potentiometer should be turned higher.

val = map(val, 0, 1023, 0, 30); // scale it to use it with the servo

// (value between 0 and 30)

// This makes the servo move a maximum of 30 degrees. My

// throttle joystick doesn’t allow any more movement than that.

//// gradual ascent, slowly increasing the throttle

if (countup == 0) {

countup = 1; // First, set throttle to 30% for 0.3 seconds

val2 = val*0.3;

myservo.write(val2);

delay(300);

}

else {

if (countup == 1) {

countup = 2; // Now, set throttle to 50% for 0.3 seconds

val2 = val*0.5;

myservo.write(val2);

delay(300);

}

else {

if (countup == 2) {

countup = 3; // Then, set throttle to 70% for 0.3 seconds

val2 = val*0.7;

myservo.write(val2);

delay(300);

}

else {

if (countup == 3) {

myservo.write(val); // Finally, set throttle to 100%

delay(15);

}

else{

}

}

}

}

}

else {

digitalWrite(YLED, LOW); // turn yellow LED off if Attention is 50 or lower

countup = 0; // reset the counter

myservo.write(0); // set throttle to 0

delay(15);

}

if(Attention>70) // turn green LED on if Attention is over 70

{

digitalWrite(GLED, HIGH);

}

else // turn green LED off if Attention is 70 or lower

{

digitalWrite(GLED, LOW);

}

}

}

}

}

}

}

}

Downloads

Upload the Arduino Sketch and Use It

drone 7, sync.jpg
  1. Start the Arduino app on the computer.
  2. Connect the Arduino’s USB cable to the computer. The HC-05 should make rapid blinks.
  3. Connect the servo’s power wires to a separate power source, and connect the minus of that power source to the Arduino’s or breadboard’s GND.
  4. Disconnect the HC-05’s TXD wire from the Arduino’s RX (pin 0), upload the sketch, and reconnect this RX wire.
  5. Open the Serial Monitor. Check that the baud rate is 57600.
  6. Connect the drone’s battery and set the drone on a flat surface.
  7. Power-on the drone’s controller.
  8. Sync the drone and controller. The instructions for mine are to pull the throttle all the way down and then all the way up. To do this, the servo must be pulled away from the controller (with the elastics still in place) and the throttle joystick may then be moved down and up with one finger. After this syncing, the throttle should be just below the middle in order to put the servo arm back in its place.
  9. Power-on the MindWave. After a few seconds the HC-05 should make 2 quick blinks every 3-4 seconds, indicating the devices are paired.
  10. Put the MindWave on your head and attach the earclip. It should now send data to the Arduino. The Serial Monitor should show the Attention level, the yellow LED should turn on and the drone lift off when Attention is more than 50, and the green LED turn on when Attention is more than 70.
  11. When finished, power-off the drone’s controller.
  12. Disconnect the drone’s battery.
  13. Close the Serial Monitor.
  14. Power-off the MindWave.
  15. Disconnect the USB cable from the Arduino or the computer.
  16. Quit the Arduino app.
  17. Disconnect the servo’s power wires from the separate power source.

The Arduino could be used with separate power instead of the USB connection to the computer. The only difference would be that there is no Serial Monitor to display data.

MAXIMIZING THE ATTENTION LEVEL

Ways to maximize the Attention level vary for different people. Here are some suggestions:

  1. Concentrate on reading the list of ingredients on a food container.
  2. Memorize some nutrition facts on a food container.
  3. Count backwards.
  4. Do arithmetic operations in your head.
  5. Listen to a rap song and try to understand the words.
  6. Read something in a language you’re not fluent in.

IMPORTANT NOTES

  1. If your HC-05’s firmware is version 2 or 3, my understanding is that the command AT+INIT is needed before the AT+INQ command. My HC-05’s firmware is version 4.0-20190815, and the AT+INIT command was not recognized. To check your HC-05’s version, type this command: AT+VERSION
  2. If you press Arduino’s Reset button, this restores the HC-05‘s settings to the factory defaults. All the pairing steps will have to be repeated.
  3. If the HC-05’s TXD is not disconnected from the Arduino’s RX before a sketch is uploaded, an error message will appear at the bottom of the Arduino app’s window on the computer screen. The following error message is repeated 10 times:avrdude: stk500_recv(): programmer is not respondingavrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
  4. If using a servo, it needs a separate power source such as 3 1.5 volt batteries. The GND of the Arduino must be connected to the minus of the external power source. Without external power, there seems to be insufficient power from the USB source and the HC-05 loses its pairing when the servo activates. It pairs after a few seconds and then unpairs next time the servo activates.

FUTURE ENHANCEMENTS

When I researched NeuroSky projects on the Internet, it was interesting to see which signals the developers chose to use in their projects. Most projects used only Attention and a few also utilized Meditation and/or Blinking.

I plan to experiment with these other signals to control a robot vehicle or to enhance this drone project. Obtaining the Blinking signals and making use of them seems much more complicated than the Attention and Meditation signals.