2022/10/06/Recitation 3: Workout

step 4:

task1:

the code for task 1:

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;

void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
Serial.begin(9600);
}

void loop() {
// read the state of the sensor
tiltVal = digitalRead(SENSOR_PIN);
// if the tilt sensor value changed, print the new value
if (tiltVal = 1){
Serial.print("You've done a curl\n");
}
delay(10);
}

task2:

the code of task 2:

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count;
void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
Serial.begin(9600);
}
void loop() {
// read the state of the sensor
tiltVal = digitalRead(SENSOR_PIN);
// if the tilt sensor value changed, print the new value
if(tiltVal != prevTiltVal){
prevTiltVal = tiltVal;
if(tiltVal == 0){
Serial.println(count++);
}
}
delay(10);
}
 

task3:

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count;
void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
Serial.begin(9600);
}
void loop() {
// read the state of the sensor
tiltVal = digitalRead(SENSOR_PIN);
// if the tilt sensor value changed, print the new value
if(tiltVal != prevTiltVal){
prevTiltVal = tiltVal;
if(tiltVal == 0){
Serial.println(count++);
}
if(count == 8){
Serial.print("Yay, you've done a set of curls");
count = 0;
}
}
delay(10);
}
 
step 5:
When you are doing sit-up, the computer will record how many you did
 
illustration sketches:
 
 

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

I think it’s 80 degrees.

What else did you notice about its behavior?

You must make your arm totally vertical, so the sensor will sense the signal of low. And if you take it out of your arm and shake it, the number will 

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

I didn’t do that, so i don’t know what will happen.

What if you shake it?

The number will go up very fast. And you just shake once, they will count as three or four.

What if you hold the wires several centimeters away and tilt it?

I didn’t do that, so i don’t know what will happen.

Do you think it can be used by any user?

Yes i think so, but maybe we should improve the accuracy of the sensor. Also, we need to use something to fix the wires to much sure it won’t get loosen.

Leave a Reply

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