programming problem pleas help

how can I drive servo motor or any other type of motor with emg sensor or muscle sensor hint : emg sensor is like variable resistance on analog port and when the muscle extarct as max the motor drive with max volt and when contract the motor move slow pleas I need the code of it help me fast

If you want complete code you should be advertising in Gigs and Collaborations.

Meantime, this should get you going. Replace the LDR with your muscle wire thing, and instead of an led, use that pwm output to control the speed of the motor (through some appropriate electronics: a transistor at minimum, maybe a driver chip.)

i get the output value from the EMG sensor i found it read 5 volt on compres my hand and 10 volt when i releas my hand so i need code to make the motor drive on this condution depend on the action on the hand if the hand need more power the motor give it to the hand and else the motor will stop i make this code i need to know is it right for what i say or not :
int motor =11; // motor pin PWM PIN
int sensor = 0; // sensor pin
int val=0;
int i=0;
void setup(){
pinMode(motor,OUTPUT);
// sensor automaticly read input 0 mean that on the A0
}
void loop(){
val= analogRead(sensor);
if(val>5){
for(i=0;i<255;i++){
analogWrite(motor,i);
delay(10);}
}
if(val<10){
for(i=0;i>0;i++){
analogWrite(motor,i);
delay(10);
}
}
}

An analog pin reads 0 for 0v and 1023 for 5v. So first, you don’t actually read the voltage straight at the pin (the >5 or <10 that you’re checking) but rather a value from 0 to 1023.

Second, you can’t put more than 5v in. You need a voltage divider to take the 10v down to 5v so it doesn’t pop the Arduino.

i can put less volt but the sensor don't read acurat just give me the code to drive this motor on the EMG signal

(deleted)

 for(i=0;i>0;i++){

You sure about that?

Please use code tags when posting code.

torky91991: how can I drive servo motor or any other type of motor with emg sensor or muscle sensor

There are three parts to the problem:

Reading an input value from the sensor. Converting the sensor input value to a speed. Making the motor move in the required direction at the required speed.

Which part are you asking for help with?

now i will tell more detailed on my sensor : i have 3 condition

  1. to make the sensor read fist one if i put the Vin to the sensor = 5 volt it will read in release my hand 4 volt and when i compressed my hand give me 2 volt
  2. second if i put the sensor on 15 volt it will read in release my hand will give 13 volt and compresse my hand will give 5 volt
  3. third one when i put on 30 volt it will make gain / vin and i don’t need this contion i just need 2 contion becouse the range is more and more accurate
    what i need to do :
    i need to read the measure of this sensor from arduino and make motor move on specific volt when the arm release need to be 125 duty cycle and when compress give me 255 duty cycle
    so i try to make this another code let it work on the first condtion of the sensor on 5 volt
int motor =11; // motor pin PWM PIN
int sensor = 0; // sensor pin
int val=0;
int i=0;
void setup(){
  pinMode(motor,OUTPUT);
  // sensor automaticly read input 0 mean that on the A0
}
void loop(){
  val= analogRead(sensor);
  if(val>800)// this mean 4 volt {
    for(i=0;i<255;i++)//this mean full duty cycle{
      analogWrite(motor,i);
      delay(10);}
  }
  if(val<800)// i compare with the same no. {
    for(i=0;i>124;i++)//this mean half duty cycle{
      analogWrite(motor,i);
      delay(10);
    }
  }
}

so this the code i write it so is it right or wrong and if it is wrong tell me which line is wrong and correct it for me pleas and i need fast help pleas

for(i=0;i>124;i++)/

Not really that different from the code I pointed out already.
Certainly the outcome is the same.

so what is wrong on this line is line is right by the way i try it any many project and it's work

Set a variable to zero. Test to see if the variable is greater than 124, and if it is, execute the body of the loop, otherwise execute the next command. What do you think might be wrong?

if(val>800)// this mean 4 volt {
    for(i=0;i<255;i++)//this mean full duty cycle{
      analogWrite(motor,i);
      delay(10);}
  }

Do you understand what the “//” comment does?

yes it’s mean comment to understand who read the code

AWOL:

if(val>800)// this mean 4 volt {

for(i=0;i<255;i++)//this mean full duty cycle{
      analogWrite(motor,i);
      delay(10);}
  }



Do you understand what the "//" comment does?

torky91991:
yes it’s mean comment to understand who read the code

But have a more careful look at that lines with the comment.

Hint: where is the “{” ?

it’s mean comment to understand who read the code

That’s what it is meant to do.
What it is not supposed to do is obscure code from the compiler, specifically the braces.
In your case, this may be intentional, but I suspect it isn’t

if(val>800)// this mean 4 volt {
    for(i=0;i<255;i++)//this mean full duty cycle{
      analogWrite(motor,i);