Step 1: Prepare your tilt sensor
Task #1: Solder
The first task in this recitation was to solder 2 long cables into a tilt sensor. In this case, the tilt sensor did not have polarity.
Task #2: Connect
We were then asked to wire the following schematic. The schematic was fairly simple, and did not produce major problems.
Task #3: Program
For the Initial code, we used the sketch provided in the instructions. This code allowed us to confirm if the sensor was working properly when tilting it.
int SENSOR_PIN = 2;
int tiltVal;
void setup() {
pinMode(SENSOR_PIN, INPUT); // Set sensor pin as an INP
Serial.begin(9600);
}
void loop() {
// read the state of the sensor
tiltVal = digitalRead(SENSOR_PIN);
Serial.println(tiltVal);
delay(10);
}
Video for Initial code:
Step 2: Refine the code
Task #1: Upload
For this task, we uploaded the following code provided to us. This code allowed for the sensor to display 0 or 1 intermittently depending on its position.
int SENSOR_PIN = 2;int tiltVal;
int prevTiltVal;
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 the tilt sensor value changed, print the new value
if (tiltVal != prevTiltVal) {
Serial.println(tiltVal);
prevTiltVal = tiltVal;
} delay(10);
}
Video code:
Step 3 & 4: Wear your sensor and Bicep Curl
This step was very straightforward, I just taped the sensor to my forearm in a way that would allow it to be activated when moving my arm up and down.
Video:
Task 1: add a conditional
The coding part proved a bit challenging for me. I needed some help from the professors. The code in red is the one for prompts 1 and 2.
- int SENSOR_PIN = 2;
- int tiltVal;
- int prevTiltVal;
- int curlnumber = 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 the tilt sensor value changed, print the new value
- if (tiltVal != prevTiltVal) {
- curlnumber++;
- Serial.println(curlnumber);
- prevTiltVal = tiltVal;
- }
- delay(10);
- }
Video:
Task #2: Count the curls
This task was a bit easier, and the steps were more clear. The red part of the code answers prompts 1, 2 , and 3.
- int SENSOR_PIN = 2;
- int tiltVal;
- int prevTiltVal;
- int curlnumber = 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 the tilt sensor value changed, print the new value
- if (tiltVal != prevTiltVal) {
- curlnumber++;
- Serial.println(curlnumber);
- prevTiltVal = tiltVal;
- }
- delay(10);
- }
Video:
Task #3: Set a limit
For task 3 I went back to the code and added the part highlighted in red by creating a “if” conditional.
- int SENSOR_PIN = 2;
- int tiltVal;
- int prevTiltVal;
- int curlnumber = 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 the tilt sensor value changed, print the new value
- if (tiltVal != prevTiltVal) {
- curlnumber++;
- Serial.println(curlnumber);
- prevTiltVal = tiltVal;
- if (curlnumber == 8) {
- Serial.println(“Good job”);
- curlnumber = 0;
- }
- }
- delay(10);
- }
Video:
Step 5: Exercise Challenge
For the exercise challenge I figured out that an easy one would be doing jumping jacks, since the arm motion was similar to bicep curls.
Video:
Documentation:
- Draw your own illustration sketches that showcase how a person would use this interactive training device.
The sensor would actually keep count of how many repetitions of jumping jacks a person has done.
Reflect on your experiments
Reflecting back on this recitation, it appears that the sensor transitions from “HIGH” to “LOW’ at exactly 180 degrees. I also noticed that if you do a short curl its would trigger it faster. If you rotated a limb, the sensor would not trigger because it only reads motion on 2 axis. On the other hand, I noticed that if you shake the sensor, it would cause it to have inaccurate readings, and would make it trigger in quick succession. Also when I grabbed the wires from a few centimeters apart, I noticed it would make the sensor more sensitive. One of the constraints of this sensor is that if a user does not have limbs, it will actually be quite hard for them to use it. Since sticking it to their bodies would prove inconvenient, and would cause inaccurate readings.
Leave a Reply