Recitation 3 Documentation
In this week’s recitation, I, collaborating with Siwei Chen, made a workout gadget with circuits and Aruduino that can record the number of times the user lifts his or her arm. The circuit was quite easy and straightforward for us to build, and we finished building the circuit quickly. What is difficult turns out to be the coding. I struggled a lot to comprehend the given Arduino codes. Thanks to my mate, my instructor and my former experience of learning C++, I eventually finished my project and helped Siwei finish as well.
Here is the recording of Step 4 and 5 of the recitation project:
The coding of Step 4 is as followings:
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int num=0;
int a=0;
void setup() {
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) {
if(tiltVal==HIGH){
num=num+1;
a=a+1;
Serial.println(num);
}
if(a==8){
a=0;
Serial.println("Yay, you’ve done one set of curls");
delay(100);
}
prevTiltVal = tiltVal;
}
delay(10);
}
In Step 5, I wore the sensor on the leg, and everytime I kicked, the serior monitor added a number to the output. And after every 8 kicks, the buzzer that was newly added by us would make sound and the serial screen will print “Yay, you’ve done one set of curls”.
The coding of Step 5 is like:
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int num=0;
int a=0;
void setup() {
pinMode(8, 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) {
if(tiltVal==HIGH){
num=num+1;
a=a+1;
Serial.println(num);
}
if(a==8){
a=0;
Serial.println("Yay, you’ve done one set of curls");
tone(8,440,1000);
delay(100);
}
prevTiltVal = tiltVal;
}
delay(10);
}