Step 6 - Programming

Programming Arduino: In this step we program the Arduino (a basic controller) with a set of instructions so that it knows what to do when it received a signal either from the potentiometer or muscle signal

NOTE: These instructions are for the Arduino-based version like the potentiometer (Option 1), flex sensor (Option2) or muscle sensor version (Option 3) pick whichever one you wired up in step 5. We are still having significant issues with the more advanced version that uses pattern recognition, multiple sensors and uses weak muscle sensors as the control signal for the arm brace: If you can help with that click here: Help Needed.

Arduino + Potentiometer (option 1)

Using something like a potentiometer may be an easy way to get a usable device working really quickly. A Potentiometer is a Radio-dial-like knob that you can turn and which can simulate the type of signal we could get from a muscle. You turn it one way and the arm will pull up, you turn it the other way and the arm will go down again.

To program the Arduino we used the same site that we found the wiring diagram from: http://www.silvinopresa.com/how-to/arduino/control-a-servo-with-arduino-and-a-potentiometer/

#include <Servo.h> //include the servo library

//variables for the servo motor

int pos; //declare variable for servo position

int servoPin = 9; //declare the pin where the servo is connected

int servoDelay =15; //delay to allow the servo to reach position and settle down

int potRead; //declare variable for the value read from the potentiometer

int potPin = A0; //declare the pin where the potentiometer is connected

Servo myServo; // create a servo object calle pointer

void setup() {

myServo.attach(servoPin); //declare to which pin is the servo connected

}

void loop() {

potRead = analogRead(potPin); //read the potentiometer

pos = (170./1023.)*potRead+5; // calcuate the position from the potentiometer reading

myServo.write(pos); //write the position on the servo

delay(servoDelay);

}


Arduino + Flex sensor (Option 2)

Using something like a flex sensor may also be an easy way to get a usable device working really quickly. As you flex the sensor the arm brace will flex with it. You can, therefore, attach the sensor to a wrist, finger or thumb and control the arm that way.

To program the Arduino we used the code we found on this page, but modified it a little, by changing the "servoPosition = map(flexValue, 85, 280, 0, 180);" values to work with our flex sensor and adding the Serial.print lines of code so that you can monitor what's happening from your computer using the Arduino serial monitor.

#include <Servo.h>

Servo myServo;

const int flexPin = A0;

void setup()

{

Serial.begin(9600);

myServo.attach(11);

}

void loop()

{

int flexValue;

int servoPosition;

flexValue = analogRead(flexPin);

servoPosition = map(flexValue, 85, 280, 0, 180);

servoPosition = constrain(servoPosition, 0, 180);



Arduino + Muscle Sensor (Option 3)

Like mentioned in the previous step, If you have a strong muscle signal to use then you could try the using a MyoWare muscle sensor to control the actuator. In our case, this only really worked for me and not my daughter as her signals were just too weak. However, if you want to test this out, here is a video we used to figure out how to do that: https://youtu.be/-JYi08WKe6c

myServo.write(servoPosition);

Serial.print("Value - ");

Serial.print(flexValue);

Serial.print(" Servo Position - ");

Serial.print(servoPosition);

Serial.println();

delay(2);

}

#include <Servo.h> Servo myservo; const int threshValue = 250; void setup() { myservo.attach(9); } void loop() { int value = analogRead(A3); if(value < threshValue) { myservo.writeMicroseconds(800); } else { myservo.writeMicroseconds(2250); } }

Optional - Help build next version

The next version of the assistive arm that we are currently working on will not use the Arduino, potentiometer or the MyoWare muscle sensor but rather a series of electrodes that will provide a Raspberry Pi up to 8 separate raw signals from the limb. The onboard software will learn to recognize the unique signals being produced by the limb and use those to control the assistive device.

With this approach, we were able to consistently pick up my daughter's muscle signals! If you want to help us with this challenge please go to this page: Help Needed.