1. Recordings Of Steps 4,5
step4:
step5:
2.My Code and Schematic for Step5:
int sensorPin = 2; int tiltVal; int number = 1; int actualNumber = 0; void setup() { Serial.begin(9600); Serial.println("Let's do this!"); pinMode(sensorPin, INPUT); } int pretiltVal; void loop() { int tiltVal = digitalRead(sensorPin); if (tiltVal != pretiltVal && tiltVal != HIGH) { Serial.println(number); number++; actualNumber++; } pretiltVal = tiltVal; if (number == 9) { Serial.println("yay,nail one set!"); tone(8, 300); delay(1000); noTone(8); number = 1; } if (actualNumber > 32) { Serial.println("Now u should rest!"); } delay(5); }
Challenges: I added a buzzer to “celebrate” each completion of each set of exercise, so the Tone will last for 1 second everytime the user finishes one set. Also, we give the user instructions to follow using the “Serial.println”. So, when the sketch starts, it prints “Let’s do this!”. And it prints “Now u should rest!” when the user finishes 4 sets.
3.illustration sketches:
4.Reflections:
(1) The mechanism behind:
The sensor is using the gravity as it transforms the position of the small steel ball into the digital outputs (HIGH or LOW). So, if you shake the sensor or rotate your limb, the signal will be very unstable, causing the counting go wrong.
(2)Restriction of the device:
If a person uses the dumbell up and down like shown in the gragh, the sensor won’t be able to work, for the gravity won’t be able to make the steel ball change its position.
(3)mistakes made during coding:
- error1: Tone
There is no delay after the “Tone”, making the beep too short to be heard.
The right way to do, is to add a “delay(1000)”after the beep and add “noTone” after.
- error2: actualNumber
In this conditional, the value of the actualNumber will increase only when the value of the actualNumber is greater than 15. Thus, the value of the actualNumber will never increase.
The right way to do, is to put “actualNumber++” out of the “if” conditional.