#include <Servo.h>
const int emgPin = A0; // Analog pin where the EMG sensor is connected
Servo servo1, servo2, servo3, servo4, servo5;
void setup() {
servo1.attach(9); // Attach servo1 to pin 9
servo2.attach(10); // Attach servo2 to pin 10
servo3.attach(11); // Attach servo3 to pin 11
servo4.attach(12); // Attach servo4 to pin 12
servo5.attach(13); // Attach servo5 to pin 13
}
void loop() {
int emgValue1 = analogRead(emgPin); // Read the EMG value for servo1
int emgValue2 = analogRead(emgPin); // Read the EMG value for servo2
int emgValue3 = analogRead(emgPin); // Read the EMG value for servo3
int emgValue4 = analogRead(emgPin); // Read the EMG value for servo4
int emgValue5 = analogRead(emgPin); // Read the EMG value for servo5
// Map the EMG values to servo positions
int servoPosition1 = map(emgValue1, 0, 1023, 0, 180);
int servoPosition2 = map(emgValue2, 0, 1023, 0, 180);
int servoPosition3 = map(emgValue3, 0, 1023, 0, 180);
int servoPosition4 = map(emgValue4, 0, 1023, 0, 180);
int servoPosition5 = map(emgValue5, 0, 1023, 0, 180);
// Set the positions for each servo
servo1.write(servoPosition1);
servo2.write(servoPosition2);
servo3.write(servoPosition3);
servo4.write(servoPosition4);
servo5.write(servoPosition5);
delay(15); // Add a short delay for stability
}