Pressure Sensor Value Reset

I am a high school senior in a Project Lead the Way, engineering program, class. I am in a group of three and we are currently designing an alarm clock that is pressure sensitive. The device will look and function similar to a normal alarm except that there is no snooze or “alarm off” button. There is a pressure sensor that is placed under the mattress; this will act as the toggle on and off switch. We want the alarm to turn on when the time the alarm is set to go off is reach, as long as the pressure sensor senses that someone is on the bed. The alarm must remain on until the pressure sensor value senses that there is no one on the bed. The current problem we are having is that we need to “zero out” the pressure sensor value after the pressure sensor is placed under the mattress. We plan to “zero out” the pressure sensor value with the toggle/press and release of a button. The best way I can explain what I mean by “zero out” is by using a scale as an example. When you use a scale, digital or analog, you must first set the scales value to zero before weighing anything; in my case the pressure sensor is the scale and I need to zero it out before our design will work. In terms of programming I guess I am looking for a way to set an input value after a button PRESS.

Incorporated is my current code, in place of the alarm is the LED. Please disregard anything regarding a potentiometer; I copied various parts of various codes to make this one.


In terms of programming I guess I am looking for a way to set an input value after a button PRESS.

I don't understand what you mean by "an input value". The pressure sensor is an output device. Scales have a "TARE" button. It means "read the scale value and subtract that value from all future readings".

In your case, you want a switch that, when pressed, will cause the value of the sensor to mean "no one's home". Or, it determines the threshold that means some is, or is not, in bed.

Which pin is that switch connected to? Where do you want to store the reading when the switch is pressed?

How will you stop someone from getting into bed and then pressing the switch?

The pseudocode for that:

if button is pressed
  { remembered_pressure := read(pressure) }
// later...
calibrated_pressure := read(pressure) - remembered_pressure