Pages: [1]   Go Down
Author Topic: Infant Respiratory Monitor Flex Sensor  (Read 1231 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 = ");
  Serial.print(fsrReading);

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.
Thanks.
« Last Edit: October 01, 2012, 08:16:09 pm by Spyko » Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 15
Posts: 348
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Edison Member
*
Karma: 23
Posts: 1171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:
Quote
...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.

Logged

Pages: [1]   Go Up
Jump to: