Go Down

Topic: How to rotate 3 servo motors when 6 led lights are lit using EMG signals (Read 604 times) previous topic - next topic

miraj

Hi,
I am completely new to arduino and trying to do a school project where i will be able to more 3 fingers with the help of a servo motor using EMG signals.
Right now i am able to read the signals. I just want to modify the code in such a way that when all 6 lights are lit on my emg reading device the servo with rotate by 90 degree. And when all leds are off the servo motor will go back to its initial position, that is will rotate back by 90 degree.
I badly need help over here. Here is the code:
Code: [Select]

#define NUM_LED 6  //sets the maximum numbers of LEDs
#define MAX 45     //maximum posible reading. TWEAK THIS VALUE!!
int reading[10];
int finalReading;
byte litLeds = 0;
byte multiplier = 1;
byte leds[] = {8, 9, 10, 11, 12, 13};

void setup(){
  Serial.begin(9600); //begin serial communications
  for(int i = 0; i < NUM_LED; i++){ //initialize LEDs as outputs
    pinMode(leds[i], OUTPUT);
  }
}

void loop(){
  for(int i = 0; i < 10; i++){    //take ten readings in ~0.02 seconds
    reading[i] = analogRead(A0) * multiplier;
    delay(2);
  }
  for(int i = 0; i < 10; i++){   //average the ten readings
    finalReading += reading[i];
  }
  finalReading /= 10;
  for(int j = 0; j < NUM_LED; j++){  //write all LEDs low
    digitalWrite(leds[j], LOW);
  }
  Serial.print(finalReading);
  Serial.print("\t");
  finalReading = constrain(finalReading, 0, MAX);
  litLeds = map(finalReading, 0, MAX, 0, NUM_LED);
  Serial.println(litLeds);
  for(int k = 0; k < litLeds; k++){
    digitalWrite(leds[k], HIGH);
  }
  //for serial debugging, uncomment the next two lines.
  //Serial.println(finalReading);
  //delay(100);
}
   

Thanks :)

vinceherman

You have code. (good job using the code tags on your first post!)
You need help.

Help us help you. 
What does your code do that you do not want it to do?
What does your code not do that you want it to do?

If you are trying to make servos work, I recommend trying out one of the servo tutorials.  Sweep is a good one.   Get it to make a servo move.  This will confirm that you have it wired properly and are familiar with the code that moves a servo.

Then try putting the servo movement in to your sketch.

If you run into problems, we will be glad to help.  But you write the code.

jdolecki

Look at this

the code is here too

https://backyardbrains.com/experiments/MuscleSpikerShield_GripperHand

Go Up