Neurosky mindwave and 4wd Arduino car

I am having trouble controlling my 4wd Arduino car jam using a Neurosky Mindwave EEG headset in-order to get attention levels. so far the motors do rotate but I find it hard to control. I would like to know if there is a function that can be used in-oder to get an range of attention levels to do a specific action for example when the attention levels are between 50 and 80 I would like for it to move forward, if the attention levels are between 90 and 100 turn right etc.
the attention levels have a range of 0 to 100
aim using a H bridge for to control the motors.

thank you for the help

arduino_code_1.4.2.ino (1.59 KB)

https://forum.arduino.cc/index.php?topic=598194.0

?

dear sir I have tried out the code you have written me but it wasn’t functing I send a PM I guess you haven’t recieved it.

the code looked promissing ones I uploaded it and tried it out I wouldn’t get any reading on y serial port also the car motors wouldn’t function.

I loved the way the cases wear written and tried to use that part with my own code but I would keep receiving error so I gave up.

one again thank you for you help.

Samim21: dear sir I have tried out the code you have written me but it wasn't functing I send a PM I guess you haven't recieved it.

the code looked promissing ones I uploaded it and tried it out I wouldn't get any reading on y serial port also the car motors wouldn't function.

I loved the way the cases wear written and tried to use that part with my own code but I would keep receiving error so I gave up.

one again thank you for you help.

Would have made more sense to continue with that thread.

You said you couldn't get any reading on the serial port and then later that you kept "receiving error." What is actually happening?

Found an error in my original response. Is this any better?

//code trial 1
#include <Mindwave.h> 

#define NUM_ATTNS       5
//
//
#define FWD_LOW         85
#define FWD_HIGH        100
//
#define RIGHT_LOW       60
#define RIGHT_HIGH      75
//
#define LEFT_LOW        40
#define LEFT_HIGH       55
//
#define BACK_LOW        20
#define BACK_HIGH       35
//
#define STOP_LOW        0
#define STOP_HIGH       15

//int constrainedInput = constrain(input, minimumValue, maximumValue);
const int left_motor_f = 13;
const int left_motor_r = 12;
const int right_motor_f = 11;
const int right_motor_r = 10;

bool
    bmwNewData;
int 
    attention = 0;

Mindwave mindwave;

typedef struct 
{
    byte    Command;
    byte    Low;
    byte    High;
    
}struct_MwAttentions;

struct_MwAttentions MwAttentions[NUM_ATTNS] = 
{
    {
        .Command = 'F',
        .Low = FWD_LOW,
        .High = FWD_HIGH        
    },
    {
        .Command = 'R',
        .Low = RIGHT_LOW,
        .High = RIGHT_HIGH        
    },
    {
        .Command = 'L',
        .Low = LEFT_LOW,
        .High = LEFT_HIGH        
    },
    {
        .Command = 'B',
        .Low = BACK_LOW,
        .High = BACK_HIGH        
    },
    {
        .Command = 'S',
        .Low = STOP_LOW,
        .High = STOP_HIGH        
    }
};

void setup()
{
    Serial.begin( MINDWAVE_BAUDRATE );
    //mindwave.setDebug(true);
  
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(10, OUTPUT);
    //Serial.begin(57600);
    bmwNewData = false;

}//setup

void MindwaveCallback( void )
{
    attention = mindwave.attention();
    bmwNewData = true;
    
}//MindWaveCallback;

void loop()
{    
    mindwave.update( Serial, MindwaveCallback );
    if( bmwNewData )
    {
        bmwNewData = false;
        
        switch( AssignAttentionLevel() )
        {
            case    'F':
                // ALL MOTORS GO FORWARTS
                //Serial.print(attention);
                digitalWrite(13, HIGH);
                digitalWrite(12, LOW);
                digitalWrite(11, HIGH);
                digitalWrite(10, LOW); 
            break;

            case    'B':
                // ALL MOTORS GO BACKWORDS
                //Serial.print(attention);
                digitalWrite(13, LOW);
                digitalWrite(12, HIGH);
                digitalWrite(11, LOW);
                digitalWrite(10, HIGH);  
            break;

            case    'L':
                // TURNS RIGHT 
                //Serial.print(attention);
                digitalWrite(13, LOW);
                digitalWrite(12, LOW);
                digitalWrite(11, HIGH);
                digitalWrite(10, LOW);  
            break;

            case    'R':
                // TURNS RIGHT 
                //Serial.print(attention);
                digitalWrite(13, HIGH);
                digitalWrite(12, LOW);
                digitalWrite(11, LOW);
                digitalWrite(10, LOW);
            break;

            case    'S':
                // STOPS CAR 
                //Serial.print(attention);
                digitalWrite(13, LOW);
                digitalWrite(12, LOW);
                digitalWrite(11, LOW);
                digitalWrite(10, LOW);
            break;
                
        }//switch
        
    }//if
        
}//loop

byte AssignAttentionLevel( void )
{
    for( int i=0; i<NUM_ATTNS; i++ )
    {
        if( (attention >= MwAttentions[i].Low) && (attention <= MwAttentions[i].High) )
             return( MwAttentions[i].Command );
             
    }//for

    //if no match found, command a stop
    return ('S');

}//AssignAttentionLevel[code]

Thank you I will have a look

I keep receiving this error massage Arduino: 1.8.7 (Mac OS X), Board: "Arduino/Genuino Uno"

In file included from /Users/Sadaf/Desktop/arduino_code_1.6.1/arduino_code_1.6.1.ino:2:0: /Users/Sadaf/Documents/Arduino/libraries/ArduinoMindwave-master/Mindwave.h: In function 'void MindwaveCallback()': /Users/Sadaf/Documents/Arduino/libraries/ArduinoMindwave-master/Mindwave.h:41:8: error: 'byte Mindwave::attention' is private byte attention; ^ arduino_code_1.6.1:88:26: error: within this context attention = mindwave.attention(); ^ arduino_code_1.6.1:88:36: error: expression cannot be used as a function attention = mindwave.attention(); ^ /Users/Sadaf/Desktop/arduino_code_1.6.1/arduino_code_1.6.1.ino: In function 'void loop()': arduino_code_1.6.1:95:47: error: no matching function for call to 'Mindwave::update(HardwareSerial&, void (&)())' mindwave.update( Serial, MindwaveCallback ); ^ In file included from /Users/Sadaf/Desktop/arduino_code_1.6.1/arduino_code_1.6.1.ino:2:0: /Users/Sadaf/Documents/Arduino/libraries/ArduinoMindwave-master/Mindwave.h:23:8: note: candidate: void Mindwave::update() void update(); ^ /Users/Sadaf/Documents/Arduino/libraries/ArduinoMindwave-master/Mindwave.h:23:8: note: candidate expects 0 arguments, 2 provided exit status 1 within this context

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

ones again thank you for the help

It seems like we have different versions of the mindwave library. I downloaded from here:

https://github.com/orgicus/Mindwave

and the code compiles without error on a Mega 2560.

Where did you get your library from? What version of IDE are you using?

https://github.com/redpaperheart/ArduinoMindwave this is where I got my library from. I am using a Arduino Uno board.

Would you recommend using the same fursion of the arduino libraries you have used or stick to my one. Thank you

It wouldn't hurt to try the lib I used. I can try re-writing mine to use the original lib if that doesn't work.

I will try that I won’t be able to do that today will do it first thing in the morning. Thank you so mush for helping me sir I really appreciate it. Goodnight

dear mr/ms Blackfin

thank you so mush I have tried using the library you have provided me and the code works like a charm now. thank you so much for the help your a life saver.

Hello brother, can you share your code? Please