Servo Controle usando Ondas Cerebrais (Parte 12/13)

Servo Control using Brain Waves (Part 12/13)

Servo control using brain waves

SUMMARY

After applying brainwaves to RGB LEDs, now it's time to check the extensions in some more real-time applications and determine the efficiency and flexibility that can be achieved using this module. Now I'm planning to use it in some robotic field.
In this article, I plan to use Brain Wave for some healthcare applications along with robotics. When studying robotic arms, I discovered that they are controlled by a servo motor. What if we can control the servo motor using our Brainwave? I wasn't sure about this as Brainwave results are often random and I wanted to check if we can control the angle with our thoughts. So to check the accuracy I tried it.
Imagem mostrando um usuário usando o Brainwave para controlar o servo motor
Fig. 1: Image showing a user using brain waves to control the servo motor
DESCRIPTION
To control any robotic arm, we need to control the servo motor . The mechanism of robotic arm is that there is a servo motor fixed on the edge of the arm. The movement of the robotic arms completely depends on the angle of the Servo motor. You can read more about Servo motor (here) to know how it works. In short, servo motor I is basically used where we need a precise angle. Thus, to control the servo angle, a PWM wave is produced. The PWM wave decides the angle of the servo motor by varying the Duty Cycle, in a very similar way to what we did in motor speed control. Here, we are controlling the angle of the motor. The motor can rotate 180 degrees depending on the duty cycle. We will use the alpha wave again as it can be used to see real-time results based on our thoughts. So, let's transform the alpha wave values ​​and constrain them to be between 0.255, which will turn into an angle of 0 to 180. Find the Block Diagram attached below.
Diagrama de blocos do servo controlado por ondas cerebrais baseado em Arduino e sensor Mindflex
Fig. 2: Block diagram of Arduino and brainwave controlled servo based on Mindflex sensor
Hardware: Please find the attached circuit diagram of the connections that must be made. We take a pin from the T pin of the mindflex sensor and connect this pin to the Rx pin of our Arduino UNO. Additionally, we short-circuited the sensor and UNO ground by a wire. Please take special care when soldering anything to the Mindflex sensor as the pins are very close to each other. For servo connections, we connect the servo VCC and GND to the 3.3V and GND of the arduino. We connect the 9th pin of Arduino to the servo for angle control.
Programs: Let's go to the software part. We have been receiving the values ​​from the sensor to our arduino via T-pin. Once we receive the value at any specific point, we just need to convert that value level to the servo angle.
We are using Arduino's built-in servo library here to control the servo motor.
Here is a small section of the code.
Serial.print(“alpha = “);
Serial.println(num1);
output = map(num1,0,999999,0,180);
myservo.write(output);
First, we extract the alpha values ​​from the string and store them in a variable called num1. After that, we just map the alpha values ​​in the range 0 to 180 using the arduino's map function.
And then we send the values ​​stored in the “output” variable here to the servo using myservo.write , a built-in Arduino function.
Some points to note:
The sensor usually provides 60 to 80% resistance due to its orientation and the place where we locate it. Try to keep the metal sensor exactly above your left eye. I also applied salt water to my forehead for better connectivity with the sensor. If you don't find 100%, then it's normal.
The signal strength also messes with how we solder the wire to the T pin. Try shielding this wire and also make sure the reference probes are connected correctly. If you have any wires connected to the sensor's EEG pin, disconnect that wire as this will create a lot of noise in the sensor values.
Try this experiment and stay tuned to the series of brain waves. In the next part, we will deal with the experiment in hyper terminal .

Project source code

 //Program to


 // Arduino Brain Library - Brain Serial Test

 // Description: Grabs brain data from the serial RX pin and sends CSV out over the TX pin (Half duplex.)
 //More info:
 // Author: Eric Mika, 2010 revised in 2014

 #include
 #include

 // Set up the brain parser, pass it the hardware serial object you want to listen on.
 Brain brain(Serial);
 Servo myservo; // create servo object to control a servo
 //char a(400);
 String a,a1;
 int v = 0;
 int z=0,output;
 uint32_t num=0;
 uint32_t num1=0;
 void setup { 
// Start the serial hardware.
 Serial.begin(9600);
 myservo.attach(9); // attaches the servo on pin 9 to the servo object
 pinMode(12, OUTPUT);
 pinMode(11, OUTPUT);
 }

 void loop {
 // Expect packets about once per second.
 // The .readCSV function returns a string (well, char*) listing the most recent brain data, in the following format:
 // "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
 if (brain.update ) {
 // Serial.println(brain.readErrors );
 // Serial.println(brain.readCSV );
 //sprintf(a, "%c",brain.readCSV );
 a = brain.readCSV;
 v = a.indexOf(',');
 v = a.indexOf(',',v+1);
 v = a.indexOf(',',v+1);
 v = a.indexOf(',',v+1);
 z = a.indexOf(',',v+1);

 a1 = a.substring(v+1,z);
 num = a1.toInt ;

 v = a.indexOf(',',z+1);


 a = a.substring(z+1,v);

 num1 = a.toInt; 
Serial.print("alpha = ");
 Serial.println(num1);

 output = map(num,0.999999,0.180);


 myservo.write(output); // tell servo to go to position in variable 'pos'
 delay(15);

 // analogWrite(12,output)

 //brain.readCSV .toCharArray(a,200);
 }
 }

Circuit diagrams

servant

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.