User Manual
if get EMG singal,number++ and print
*/
if (threshold > 0)
{
if (getEMGCount(envelope))
{
EMG_num++;
Serial.print("EMG_num: ");
Serial.println(EMG_num);
}
}
else {
Serial.println(envelope);
}
delayMicroseconds(500);
}
/*
if get EMG signal,return 1;
*/
int getEMGCount(int gforce_envelope)
{
static long integralData = 0;
static long integralDataEve = 0;
static bool remainFlag = false;
static unsigned long timeMillis = 0;
static unsigned long timeBeginzero = 0;
static long fistNum = 0;
static int TimeStandard = 200;
/*
The integral is processed to continuously add the signal value
and compare the integral value of the previous sampling to determine whether the signal is continuous
*/
integralDataEve = integralData;
integralData += gforce_envelope;
/*
If the integral is constant, and it doesn't equal 0, then the time is recorded;
If the value of the integral starts to change again, the remainflag is true, and the time record will be re-entered next time
*/
if ((integralDataEve == integralData) && (integralDataEve != 0))
{
timeMillis = millis();
if (remainFlag)
{
timeBeginzero = timeMillis;
remainFlag = false;
return 0;
}
/* If the integral value exceeds 200 ms, the integral value is clear 0,return that get EMG signal */
if ((timeMillis - timeBeginzero) > TimeStandard)
{
integralDataEve = integralData = 0;
return 1;
}
return 0;
}
else {
remainFlag = true;
return 0;
}
}
Calibration is recommended for every time you use it, for the EMG signal is different in different position even of the same
person.
1. In this code, the default variable threshold is 0, which means in the calibration mode. Modify threshold to nonzero means exit the calibration mode. So if you want to
re-calibrate the sensor,you just need to modify threshold value to 0, namely, unsigned long threshold = 0;
2. Upload the code to Arduino control board and open serial plotter of Arduino IDE to check the maximum Y-axis value.
3. Make a fist gently and loose it gently, repeatedly. Then observing and recording the maximum Y-axis value. As shown in the following picture,the result of the maximum
should be around 400.
(/wiki/index.php/File:Warning_yellow.png)