Description
Many people sit for too much time. This FSR and DC motor combo will fight that! When sitting on the FSR for more than 10 seconds, the vibrating alarm (DC motor with pebble taped to it) will alert you to your sedentary stint.
The most difficult part of this is keeping the vibrating alarm setup together. the taped pebble comes loose from time to time. Also, I need longer wires to make this viable for real people to sit on. In a perfect world, the chair would have the vibration incorporated into its structure.
For demonstration, the alarm goes off after 10 seconds, however, in practice, this would be 45 minutes or so.
Code
The code is simple. It checks the FSR every second for a value, and if 10 seconds elapse with values from the FSR then it triggers a burst of vibration by sending a value of 200 to the DC motor for just .25 seconds. This is enough to get a jolt and get out of your seat.
If the FSR detects no force, then it resets the timer.
/*
This code uses a FSR to determine if the user is seated.
If there is a value for the FSR then it is assumed the user
is seated. If the FSR detects 10 straight seconds of sitting
then it triggers an vibrating alarm. The vibrating alarm is
a DC motor with a small rock taped to it. It vibrates when
sending an "analogWrite" of value 1-255. The alarm stops when
the FSR detects 0 force.
*/
int fsrPin = 0; // select the input pin for the FSR
int motorPin = 9; // select the pin for the Motor / vibrating alarm
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
int time_since_break=0; //this time is kept in seconds for convenience
int alarm_secs = 10;
void loop() {
val = analogRead(fsrPin); // read the value from the sensor
Serial.println(val);
if (val>0){ //when FSR detects sitting...
delay(1000);//miliseconds - delay for next reading
time_since_break=time_since_break+1;//seconds - keep track of how much contiguous sitting
if(time_since_break>=alarm_secs){
analogWrite(motorPin, 200);//make it vibrate for a second
delay(250);
analogWrite(motorPin, 0);
}
}
else{//when val of fsr is 0 then reset
time_since_break=0;
}
}
- Login to post comments