Step 4: Bicep curls
int SENSOR_PIN = 2; int tiltVal; int prevTiltVal; int count = 0; 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 (tiltVal != prevTiltVal) { if (tiltVal == 1) { count = count + 1; Serial.println(count); tone(8, 440, 100); } if (count == 8) { tone(8, 440, 100); count = 0; Serial.println("Yay, you have done one set of curls"); } prevTiltVal = tiltVal; delay(100); } }
Step 5: Challenge
int SENSOR_PIN = 2; int tiltVal; int prevTiltVal; int count = 0; 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 (tiltVal != prevTiltVal) { if (tiltVal == HIGH) { count = count + 1; Serial.println(count); } if (count == 8) { tone(8, 440, 100); count = 0; } } prevTiltVal = tiltVal; delay(100); }
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count = 0;
void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
Serial.begin(9600);
}
void loop() {
tiltVal = digitalRead(SENSOR_PIN);
if (tiltVal != prevTiltVal) {
if (tiltVal == HIGH) {
tone(8, 440, 100);
}
prevTiltVal = tiltVal;
}
delay(10);
The video and the code above is an experiment I made to test out at what angle of tilt it transitions between HIGH and LOW. And as it is shown, when it transitions to HIGH, the buzzer makes a sound. And it turned out that the angle is very small which means the tilt switch is very sensitive to small changes in angles, and maybe too sensitive that sometimes one full bicep curl or jumping jack counts for two or even more. Reflecting on the whole process, I think the jumping jack challenge we chose doesn’t fit well with the character of this relatively “fragile” training equipment, since the wires can and did actually easily come off from the ports with my “big move”-jumping with my arms up and down. Looking back, I think I have to thank Professor Rudi and Professor Gottfried for reminding us to bind the two wires connecting the tilt switch together, otherwise the switch must have been more “fragile” and “incorrect”, I suppose.
https://www.instructables.com/TILT-SWITCH-USING-ARDUINO-UNO-R3/
Actually, I was a little curious about how the tilt switch works inside and what makes it so sensitive to change in angles. So I searched for “tilt switch, arduino” and found the answer to my question on the website instructables circuits, as the screenshot shown above. And I think the reason why the tilt sensor in our arduino kit is so sensitive is because the metal ball inside is light and the tube of the tilt switch isn’t long enough for the workout process we designed. Perhaps a tilt switch with a longer tube can allow for a wider range of workout types?