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.