Recitation 3: Workout

In this recitation, we built an interactive device that simulates biceps bending. 

Step 1:

Firstly, we made an artifact by soldering the sensor with two long wires.

Then, following the guidelines, we built up the circuits quickly. The circuits could read the status of the sensor as input and transmits them into my laptop.

Step 2:

We modified the code provided in the guideline to ensure that it only displays the status of the sensor when there is a change of it, by adding another condition into the if conditional.

Step 3&4&5:

In task one, we first put on the sensor. I taped it on my arm. Then we modified the code so that the computer would print “A FULL BICEPS CURL” when I complete a full biceps curl. 

Here is the code.  We use Serial.println() to print the sentence.

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;


void setup() {
  pinMode(SENSOR_PIN, INPUT); 
  Serial.begin(9600);
}

void loop() {
  tiltVal = digitalRead(SENSOR_PIN);
   if (tiltVal != prevTiltVal && tiltVal == 1) {
    Serial.println("A FULL BICEPS CURL"); 
  }
  if (tiltVal != prevTiltVal) {
    prevTiltVal = tiltVal; 
  }
  delay(10);
}

In task two, we upgraded our code so that it could count how many times the user has successfully done a full bicep curl. In order to achieve that, we declared a global variable which add one to itself during every iteration.

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int x = 0;


void setup() {
  pinMode(SENSOR_PIN, INPUT);
  Serial.begin(9600);
}

void loop() {
  tiltVal = digitalRead(SENSOR_PIN);
   if (tiltVal != prevTiltVal && tiltVal == 1) {
    Serial.println("A FULL BICEPS CURL"); 
    Serial.println(x);
    x = x+1;
  }
  if (tiltVal != prevTiltVal) {
    prevTiltVal = tiltVal; 
  }
  delay(10);
}

The next progress we made was to set a limit to the variable we declared in the previous task. As long as the variable reach the limit, the computer would print “You have made a set!!!”, indicating that the user has successfully made a set of bicep curls.

Shortly after that, we upgraded the artifact again. This time we changed the way the artifact reacts when the user reaches the limit. We added an LED into the circuit which would light up for five seconds when the user complete 10 bicep curls.

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int x = 0;
int ledPin = 9;

void setup() {
  pinMode(SENSOR_PIN, INPUT); 
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  tiltVal = digitalRead(SENSOR_PIN);
   if (tiltVal != prevTiltVal && tiltVal == 1) {
    Serial.println("A FULL BICEPS CURL"); 
    Serial.println(x);
    x = x+1;
  }
  if (tiltVal != prevTiltVal) {
    prevTiltVal = tiltVal; 
  }
  if (x == 8){
    Serial.println("Yay, you’ve done one set of curls!");
    digitalWrite(ledPin, HIGH);
    delay(5000);
    digitalWrite(ledPin, LOW);
    delay(1000);
    x = 0;
  }
  delay(10);
}

At what angle of tilt does it transition between HIGH and LOW?

When the sensor is posed horizontally to the ground, it is LOW. When it is posed vertically to the ground, it is HIGH. When it is mover from horizontal to vertical, it transitions from LOW to HIGH.

What else did you notice about its behavior?

This behavior contains interaction. Our bicep curls provide the input, and the artifact process the input, lighting up LED as the output.

What if you rotate the limb that has the sensor attached to it?

The counting variable will add one value to itself every time when the sensor changes its position from horizontal to vertical.

Leave a Reply

Your email address will not be published. Required fields are marked *