Recitation 3: Sensors/Workout

For this week’s recitation, you will be also doing some workout! You will use the tilt switch from your kit to build a wearable workout sensor, do a workout exercise, and complete a challenge. You will work in pairs, but each person will need to make your own circuit.

Step 1: Prepare your tilt sensor

Task #1: Soldering

I soldered the sensor to two long wires as instructed, one red line connected to 5V and another black one to the ground. It’s not the first time I’ve used tin solder, so it didn’t add much trouble to my work. I didn’t fix the materials on a cardboard, but I didI wrap the wires together like example picture, so that they wouldn’t depart during soldering. I thought that was stable enough. The soldering also went smoothly with the experience of the last recitation. Most of the tin solidified right on the wires.

 

Task #2: Connect the tilt sensor cables to your Arduino using a capacitor as the circuit below:

tilt-22uF-10k

At first I didn’t really figure out what the sketch meant and connected quite a lot of the wires wrong. Unfortunately, I didn’t realized my mistake at first time, which meant I wasted lots of time on a wrong circuit. The numbers shown on the serial monitor did appear in the form of 010101, but they kept moving and flickering, and they didn’t add gradually, but were already countless in the beginning.

 

What was interesting was that when I lifted my arms, the numbers never stopped changing, but when my arm touched something on the table, the numbers froze. I guess my arm became an earth lead or something, but I can’t really tell the function of the weird mistake. See the video below.

Task #3: Program your Arduino with the following sketch. Confirm that you get an input from your tilt sensor on the the Serial Monitor to check whether it is working correctly.

As is mentioned above, I followed the instructions and tested the circuit. However, I mistook the blinking numbers for a normal condition. So I continued. Of course later I found my mistake and corrected the circuit, but it was later.

Step 2: Refine the code

This was easy. All I needed to do is done with Ctrl, C, and V.

Step 3: Wear your sensor

I tied the sensor to my forearm after several times of failures, since the sensor was made of metal and it was solid, while a human forearm is smooth and full of curves. Finally I made it tight. The price is that a grumpy metal wire kept stinging my skin, but it didn’t matter if the device functioned well, though it didn’t.

Step 4: Bicep Curl Workout!

(Initial Version)

Finally I made up my mind to recheck the circuit after class. It was amazing that I immediately figured out the mistakes with a glance at the sketch, but I had spent hours on that wrong work. Maybe I was just too nervous. 

Task #1: Add a conditional & Task #2: Count the curls

I made this by adding a variable called “count” the “count” will self-add when a full bicep is performed, whose symbol is that “tiltVal” will “== 1” again. I changed the code next to “if (tiltVal == 1) “tiltVal at “Serial.println” was replaced by “count++“.

copiable code here:
int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count = 1;
void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INPUT pin
pinMode(9, OUTPUT);
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 == 1){
Serial.println(count++);
if(count == 9){
Serial.println(“Yay, you’ve done one set of curls”);
digitalWrite(9,LOW);
delay(2000);
digitalWrite(9, HIGH);
count = count – 8;
}else{
digitalWrite(9,HIGH);
}
}
}
prevTiltVal = tiltVal;
delay(10);
}
        1.  

Task #3: Set a limit 

You can see the principle on the screenshot above. The number is 9 because the original self-add starts from 0, instead of 1, so I changed the starting point from 0 to 1 as well, and every number needs to move back one unit. 

Step 5: Exercise Challenge

I added an LED and a buzzer to the device and each time you finish a set of curls, they will respond as a reminder. (Connected to digital pin 9). It appeared in the form below, because I didn’t know why the signal seemed to be the opposite, even if I connected the LED and the buzzer right. I’m sorry I really don’t have more time for this part and I have to catch up for other assignments too. I’ll polish this part if time agrees in the future. Though I made it too simple, all the codes for the LED and the buzzer are written by myself.

Leave a Reply

Your email address will not be published. Required fields are marked *