Sensors

In todays recitation we focused on sensors. We  ran an experiment where we used a tilt sensors to count the repetitions and output the information.

The code I used for this task to take place involved a variety of steps. Firstly, the goal of the code was:

 Count the curls, adding one to its value every time that the user does a complete bicep curl. 

Add one to its total every time that a LOW to HIGH transition has happened.

Modify the Serial.print and Serial.println instructions so that the value of this new variable is shown on the Serial Monitor.

 Set a limit to the variable you are using to count the curls, so that the final code has the following behavior.

When the total reaches 8, Print “Yay, you’ve done one set of curls”. Hint: you will need another conditional Reset the count, so that the behavior repeats at 16 curls, 24, etc.

After trial and error as well as receiving assistance from the instructors, I was about able to modify and optimize the code. This the code I used to run the program.

int SENSOR_PIN = 2;
int tiltVal;
int prevTiltVal;
int count;

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 == 0 && tiltVal != prevTiltVal) {
Serial.println(count);
count = count +1;
}
if (count == 8){
Serial.println(“Yay, ..”);
count = 0;
}
prevTiltVal = tiltVal;
delay(10);
}

The image above is a sketch I did to show how this device can be applied when doing exercise. Firstly I optimized the design to make a portable device instead of having cables that are disruptive when working out. There are three major components of the device; a screen display; a tilt sensor and a buzzer. The function of the screen display is to show the count of how many repetitions have been done. It also show the different types of the workouts available. The purpose for the tilt sensor is to sense the state . The purpose of the buzzer is to signal a start and stop depending on the type of workout that is in function. This device can be used for exercises that have up and down movements. I put examples like bicep curls and leg extensions. Down to up represents 1 repetition.

  • At what angle of tilt does it transition between HIGH and LOW?
  • My observation for this was pretty interesting because depending on where the sensor was placed on the arm, the angle between high and low was different. The optimal range would be 180 degrees. The higher the sensor was on the arm the less effective meaning a range of about 130. The range was best when the sensor was closer to the wrist, allowing for more range of movement.
  •  
  • What else did you notice about its behavior?
  • There were no major differences to the general function of the device.
  •  
  • What if you rotate the limb that has the sensor attached to it?
  • If you rotate the limb that has the sensor attached to it it will change only when the movement is finished
  •  
  • What if you shake it?
  • shaking the sensor does not do anything.
  •  
  • Do you think it can be used by any user?
  • This would definitely be a challenge for those who are disabled as they may not be able to rotate their arms or body parts

Leave a Reply

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