Step 1: Prepare your tilt sensor
Task #1: We need to connect the wires with the sensor. At first we followed the picture given and just twined the iron wires together, but we found they could not connect tightly. So we used tape to fix the wires and soldered the sensor to two long wires carefully.
Task #2: To connect the tile sensor cables to the Arduino, we followed the circuit. One side of the tilt was connected to GND, another side was connected to a resistor, which linked to the 5V.
Task #3: I programmed the Arduino with the sketch, it worked correctly. When monitoring the tilt, I found that every time I shook the tilt, it would send the information “0” or “1”.
Step 2: Refine the code
To let the program only print 1 when the tilt sensor changes from 0 to 1, and 0 when from 1 to 0. I uploaded the sketch, added
if (tiltVal != prevTiltVal) { Serial.println(tiltVal); prevTiltVal = tiltVal;
As a result, I got a chain of “0” and “1” in the monitor page.
Step 3: Wear your sensor
We stuck the tilts with tape to our arms, and held the tape as hand weights. By moving our arms, the tilts can sense the movement and send the information constantly.
Step 4: Bicep Curl Workout!
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);
}
My partner wore the sensor on his leg, and every time he kicked, the serial monitor added a number to the output. And after every 8 kicks, the buzzer that was newly added by us would make a sound and the serial screen would 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);
}
My own illustration sketches:
Experience and Learning:
Actually, I didn’t notice at what angle the tilt will transition between HIGH and LOW, but I think if I lean it to the right, the tilt will transition to HIGH or LOW, and then I lean it to the other side, it will transition to the opposite information. If I shake the tilt, it will send a constant piece of information like: 0101010101010101… If I hold the wires several centimeters away and tilt, it still work. I think this device can be used by any user, it is interactive because it includes listening and thinking, and the output of the information “Yay, you’ve done one set of curls” also influence the thought of the user so that the user can decide whether continue doing another set of curl or stop exercising.