Step 4:
Step 5:
Code:
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 != prevTiltVal) { Serial.println(tiltVal); prevTiltVal = tiltVal; if (tiltVal == 0){ Serial.print("Bicep curl:"); repcount +=1 Serial.println(repcount); } } if (repcount == 8){ Serial.println("Yay, you've done one set of curls"); repcount = 0; delay(10); }
Drawing:
4.
After some trial and error, we found out that the angle of tilt that transition between HIGH and LOW is around 45 degrees. I noticed that sometimes the motor doesn’t register went we tilt it too fast. We also discovered that the motor still registers a change even by shaking it, thus making us do the “cowboy whip workout” for step 5. The length of the wires also seems to affect the tilt. When my partner held the motor close to his palm, it seems to register better than when it’s near his elbow.