Go Down

Topic: Infant Respiratory Monitor Flex Sensor (Read 2795 times) previous topic - next topic


Oct 02, 2012, 03:14 am Last Edit: Oct 02, 2012, 03:16 am by Spyko Reason: 1
Hello, I am making an infant respiratory monitor using a flex sensor (Force sensitive resistor = FSR). I have very little experience programming and with arduino.
As of right now I have my sensor hooked up to an arduino and able to output analogread from it and am able to output a buzzer signal.

My device has to set off a buzzer after 20 seconds of sensing low or no voltage change on my sensor. I am stuck on this part.

Some code I am using:

int fsrPin = 0;  // FSR on Pin 0
int fsrReading; // Analog reading from FSR voltage divider

void loop(void) {
 fsrReading = analogRead(fsrPin);  

 Serial.print("Analog reading = ");

What I would like to do is:
if (fsrReading changes by < 20 over 20 seconds)
then analogWrite(5,50);  output on pin 5 which I have a buzzer attached to 50
I am not sure how do this.


Here's what popped into my head. Someone probably has a better idea.

I would establish a distinct sampling interval, say 1 second. This would give twenty samples every twenty seconds. To hold sampled values I'd declare an array. Right before each sample I'd discard the oldest sample and shift all the array's values over one. Now you have samples twenty seconds apart to compare and all the samples in between. Basically the first and last items in the array are twenty seconds apart. You could change the sampling rate and array size if needed.

Make sense? You'll need to understand blink without delay and arrays.


Right before each sample I'd discard the oldest sample and shift all the array's values over one

Do some research on circular buffers, and there will be no need to shift the elements in the array around. You'd maintain an index to the oldest value. Then, just replace the oldest value with the newest value, and the next element in the array is now the oldest. When the oldest index is beyond the end of the array, the oldest index gets reset to 0.

After each reading, a simple pass through the array to find the minimum and maximum values will give you the amount of change over the period of time. It won't matter that the array is not in increasing order by time.
The art of getting good answers lies in asking good questions.


I have very little experience programming and with arduino.
I don't recommend building anything medically critical yourself. 

Something like this needs to be very reliable and it needs to be designed so that it can monitor itself and set-off an alarm if anything goes wrong.  And you might want redundancy, so if any one component or connection fails the system does not fail.    The circuitry that monitors the the respiratory monitor needs its own separate power supply, so if the batteries (or power supply) to the respiratory-monitor fails the system-monitor can still detect a failure and make an alarm.   And, there has to be a way to periodically test the system-monitor & alarm to make sure it's still monitoring the respiratory-monitor and detecting failures.

If you wanted to build a heart or respiratory monitor for "casual use" while you exercise, that wouldn't worry me.   But if you are monitoring someone because they might have a heart attack, or stop breathing, that's best left to medical equipment manufacturers.

You'll find this disclaimer in the ATmega datasheet, and on most datasheets:
...Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.

Of course, people do build medical devices with chips that are not authorized for medical use, but the disclaimer limits the chip manufacturer's liability.

Go Up