EMG Sensor with Firgelli L16 and Arduino Uno Question

So, I have a question. I'm building an electromechanical prosthesis for a child who lost both of his arms in a high voltage accident. So I'm planning to move the fingers of the hand with two Firgelli L16-P-100mm, capturing the signals from the Sparkfun EMG muscle sensor MyoWare 2.0 Muscle Sensor - DEV-21265 - SparkFun Electronics and two of the LAC control boards provided by Firgelli. I have the following code.

int pwmPin = 9; // output pin supporting PWM
int inPin = 3; // voltage connected to analog pin 3, e.g. a potentiometer
int val = 0; // variable to store the read value
float volt = 0; // variable to hold the voltage read
void setup()
{
pinMode(pwmPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(inPin); // read the input pin
volt =(5.0 * val) / 1023;
val = 255 * (volt / 5);
analogWrite(pwmPin, val);
}

So what this code basically does is convert the input voltage to a percentage with respect to 255. The output is a percentage of the input in terms of 255. The problem is that the EMG muscle sensor's output is way too low. The range is from about 0.4 to 0.7 maximum muscle tension. This PCB has a pot for gain adjustment which helps very little in increasing the range of the output voltage. The problem is that this range is too little and I'm not getting enough distance change from the actuator. If I print the values of val in the serial monitor they go in increments of 51. The voltage range is obviously from 0-5V, so I first multiply the desired voltage (5) with the value of the analog input which is the signal coming from the muscle sensor and then dividing it by 1023, this is assuming that the Vcc of the Arduino is 5V. Then I take that value and convert it to a percentage with respect to 255 knowing that 0 is full stroke length in and 255 is full stroke length out.

So basically the signal goes from 0-5, but the problem is I am only getting increments with the muscle sensor of 0-1, if I change the desired voltage on the first equation to, say, 100, then my range just moves from 1-2, the problem is that I cannot increase that range, I can only move it up 1 value of voltage. Is there a way to change the program in a way that if the voltage is 1 then for the final value to be like a desired value for example 153, or any preset desired value for that matter, like using if and else? I'm just not familiar with the C++ language because I started using Arduino with this project.

Basically what I would like to know if there is a way to assign a value to that increment given the fact that I can't really amplify the range of the signal obtained with the muscle sensor as it is very weak and we don't want too much of a muscle stressing movement to activate the actuator to an acceptable stroke length.

void loop()
{
val = analogRead(inPin); // read the input pin
volt =(5.0 * val) / 1023;
val = 255 * (volt / 5);
analogWrite(pwmPin, val);
}

Nonsense. There is no reason to convert the inPin reading to voltage and then convert the voltage back to a ratio. Simply divide the input reading by 4.

The problem is that the EMG muscle sensor's output is way too low.

Then, you need an op-amp to boost the signal to a meaningful range. That is NOT a programming issue.

Well, that's precisely my point. I can't really include an op-amp circuit before the Arduino input because this circuit is to be included in a prosthesis where space is very limited. I would like to anchor the reading to another value ranging from 0 to 255, e.g. an input value of a 200mV coming from the EMG signal detector would give me a value of about 51 on the scale of 0 to 255; what I want to do is tell the Arduino that the 200mV voltage is actually a 0 and when the voltage goes up to 400mV, I would like to assign that voltage a value of, say, 221, on the range of 0 to 255. What I can't get right is the C++ syntax to get this effect as I would like it to be executed.
That's also the reason why I convert the voltage value on a range from 0 to 255, because I was thinking instead of getting those small mV readings I could get whole number readings ranging from 0 to 255 so that the interpretation could be friendlier and perhaps play with these values establishing ranges for example when the input value would vary between 0 - 52, I would like a PWM output of about 153, so I don't know if you understand where I'm getting at, it's more about the association of a value to another and, then again, this sounds simple and might be incredibly easy to program but I would like some help due to the fact that I'm new to the C++ language. :sweat_smile: