Advice on EMG sensor as Controllers

Hello. I am making a project where Electromyograph(EMG) muscle sensor is used as a substitute for traditional joystick controllers such as PS3. Currently using MyoWare2.0 EMG sensor and connected to ESP32 as the microcontroller.

At first I was thinking of using fingers to differentiate the the joystick movements for example, folding thumb as right stick Y axis, folding middle finger as right stick X axis etc. However, it seems like it is hard to detect the finger muscle movement as they overlap each other and I only own 2 of these sensors.

For now, I have done the part where forearm muscle is flexed, and the EMG value is more than 1000, it will act as the left stick Y+ axis.
Note that in the code it is written to press 'W' because I am connecting it to BLE keyboard and it is input to control the Y+ of virtual joystick. I just found out about the BLEJoystick and will look onto it later but for now I am using the BLE keyboard.

#include <BleKeyboard.h>

BleKeyboard bleKeyboard;

#define EMG_PIN 27
int emgValue = 0; 
int Mmode =0;


//track movemnet
bool isMoving = false;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleKeyboard.begin();
  
 
//SerialBT.connect();
pinMode(EMG_PIN, INPUT); // Initialize the EMG sensor pin as input
  
  Serial.println("program start");
  delay(500);

}


 void readEMG() {
  emgValue = analogRead(EMG_PIN);
  //unsigned long currentMillis = millis(); //current millis is read in milli second
  
  //add if the EMG value crosses the limit emg(4095) + debounce time=500ms
// if(emgValue >=4095 && (currentMillis - lastDebounceTime) > 500){ 
  //if(emgValue >=3000){
 // isMoving = !isMoving;
 // lastDebounceTime = currentMillis; //update debounce time
 /* Serial.print("EMG value: ");
  Serial.print(emgValue);
   Serial.print(" - State changed to: ");
   Serial.println(isMoving ? "Moving" : "Not Moving");
*/}

void loop() 
{
 readEMG();
  
  if(emgValue >= 4095){
  Mmode =4;//  bila 0 aka stop
    } 
    else if  (emgValue >= 3000 && emgValue <=4094 ){  // 1:(前進)
     Mmode = 3;
      bleKeyboard.press('W');
     
    }
    else if  (emgValue >= 2000 && emgValue <=2999 ){  // 1:(前進)
     Mmode = 2;
     bleKeyboard.release('W');
    }
    else if  (emgValue >= 1000 && emgValue <=2999 ){  // 1:(前進)
     Mmode = 1;
      bleKeyboard.release('W');
    }else if  (emgValue <=1000 ){  // 1:(前進)
     Mmode = 0;
    }   


 Serial.print("Mmode: ");
   Serial.println( Mmode);
   Serial.println(emgValue);

   delay(100);
   
  // interval += intervalPeriod;

    }

Current hardware setup is something like this:


My main concern is what other sensor or what else can I add to the system to complete the controller(right and left stick only)? I am open to any suggestions and if there are other projects which I can look into to get inspired from, please feel free to comment your ideas.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.