Sei sulla pagina 1di 5

/

Trevor

Nong

 

I

received

assistance

from

August

Dailey

in

designing

the

program .

 

Group

Partners :

 

Maddie Mosscrop

Brandi StocktonFresso

 

BE201 Biomedical

I n s t r um e n t a ti o n

 

Final

Project

 

Due : 5/17/2017

 

Final

Revision :

5/16/2017

 

A portion

of

t h i s

code

was

provided

public

domain

at

h t t p s : / / l e a r n . a d a f r u i t . com/tmp36temperature s e n s o r ? embeds=all ow&view=a l l #usingatemps e n s o r

/

 
 

//

TMP36 Pin

V a ri a bl e s

 

int

sensorPin = 0;

 
 

//

the

an al o g

pin

the TMP36 ’ s

Vout

( s e n s e )

pin

i

s

c onnec ted

 

// the

resolution

i s

10

mV

/

degree

centigrade

with

a

500 mV

t o o f f s e t

to

 

allow

for

negative

temperatures

 

/

setup ( )

t h i s

f u n c ti o n

runs

once

when

you

turn

your

Arduino

on

We

i n i t i a l i z e

the

s

e r i a l

c o n n e c ti o n

with

the

computer

 

/

 

void

setup ()

 
 

{

// Start

the

connection

with

the

computer

to

view

the

r e s u l t

open

the

s e r i a l

s e r i a l monitor

 

S e r i a l .

begin (9600) ;

 

}

//

run

over

and

over

again

 

void

loop ()

 
 

{

//

I

wanted

to

analyze

the

data

that

was

being

c o l l e c t e d

,

 

//

so

I

i n i t i a l i z e d

an

array

to

store

the

temperature

readings

from

the

sensor .

1

f l o a t

tempArray

[ 2 0 0 ] ;

int

i

=

0;

f o r

(

i

=

0 ;

i

<

2 0 0;

i++) {

 

// getting

the

voltage

reading

from

the

temperature

sensor

i n t

r e a di n g = analogRead (A0) ;

//

converting

that

reading

to

voltage

f

l o a t

voltage =

reading

5 . 0 ;

v

ol t a g e

/=

1 0 2 4 . 0 ;

 

//

print

out

the

voltage

S

e r i a l . print

( voltage ) ;

S e r i a l .

println (

volts ”) ;

//

now

p r i n t

out

the

tempera tu re

 

// c o n v e r ti n g

from

10 mv

pe r

d e g r e e

with

500 mV

o f f s e t

t o

d e g r e e s

( ( v ol t a g e

 

500mV)

times

100)

 

f l o a t

temperatureC = ( voltage

0.5)

100

;

//

S e r i a l . print ( temperatureC ) ;

S e r i a l . println (”

degrees C”)

;

//

now

c o n v e r t

to

F a h r e n h ei t

f

l o a t

temperatureF = ( temperatureC

9.0

/

5.0) +

32 .0;

S

e r i a l . print ( temperatureF ) ;

S e r i a l

. println (

S e r i a l . println ( ”

degrees

F”) ;

tempArray [ i ] = temperatureF ; // waiting .1 seconds delay (100) ;

}

//

Stores

points

points

of

i n t e r e s t

in

the

data

that

can

be

thought

of

as

pseudo

c r i t i c a l

 

int

c r i t i c a l P o i n t [ 7 ] ;

 

//

Set

a

conditon

that

describes

the

behavior

of

the

data

boolean

i s I n c r e a s i n g ;

 

// An

a l t e r n a t e

inde x

f o r

the

c r i t i c a l

p oi n t

a r r a y

int

k ;

//

The

temperature

i n

a i

r f

l o w

past

the

temperature

s e n s o r

c o r r e s p o n d s

to

the

respiratory

cycle .

 

//

For

each

inhale ,

a i r

w i l l

rush

over

the

sensor ,

cooling

i t

off ,

while

for

each

exhale ,

a i r

2

//

that

has

been

warmed by

the

body

w i l l

 

flow

over

the

sensor ,

c a u si n g

i t

to

warm up .

We would

 

//

expect

t h i s

data

to

act

roughly

l i k e

a

s i n e

or

c o s i n e

wave .

So ,

in

order

to

analyze

the

amount

 

//

of

breath

taken

in

a

given

 

period

 

of

time ,

I

thought

that

i t

would

be

clever

to

find

the

peaks

//

and

troughs

of

each

of

the

 

” sine ”

 

waves

catalogue

 

the

index

at

where

t h i s

data

point

occurs .

 

//

Then ,

I

would

c o n si d e r

every

o th er

p oi n t

at

which

 

t

h i

s

o c c u r s

so

as

to

only

consider

peaks

or

//

troughs ,

two

of

which

c o n s t i t u t e

a

period ,

or

a

f u l l

breath

cycle .

 

Because

the

data

were

 

//

taken

a

regular

intervals ,

 

i t

i s

easy

 

to

convert

the

d i f f e r e n c e

in

indices

to

a

d i f f e r e n c e

 

//

in

time .

This

i s

the

s e c t i o n

of

code

 

that

I

had

help

with .

I

did

not

know

any C++

u n t i l

//

about

a

week

before

p ro jec t

and

I

hadn ’ t

had

to

do

any

intense

 

programming

in

about

t h i s a

year .

 

//

Here ,

I

a

condition

to

f i n d

i f

the

” s i n e ”

wave

was

increasing ,

and

i f

i t

was ,

s e t to

break

loop

and

 

//

out

of

the

proceed

to

the

next

step

 

while

( true )

 

{

i f ( tempArray [ i ]

<

tempArray [

i

+

1 ] )

{

 

s I n c r e a s i n g break ;

i

=

true ;

}

i f ( tempArray [ i ]

>

tempArray [

i

+

1 ] )

{

 

s I n c r e a s i n g break ;

i

=

f a l s e ;

 

}

i f ( tempArray [ i ] == tempArray [ i

+

1 ] ) {

 
 

i

=

i

+

1;

}

}

//

Here ,

I

started

a

loop

 

to

proceed

 

through

each

 

data

point

and

 

//

decide

whether

or

f o r not

i t

was

a

” c r i t i c a l

point ”

 

f o r

( i n t

i

=

1 ;

i

<

2 0 0;

i++)

 

{

 

//

An

i n i t i a l

approach

t h a t

did

not

prove

f r u i t f u l .

 
 

//

i f

( i

=

1)

//

{

//

//

i f

( tempArray [ i

 

1] < tempArray [

i

] )

{

3

// i s I n c r e a s i n g = true
//
i s I n c r e a s i n g
= true ;}
//
//
i
f
( tempArray [ i −
i s I n c r e a s i n g
1]
> tempArray [
i
] )
{
//
=
f a l s e ;}
//
//
i
f
( tempArray [ i
i s I n c r e a s i n g
+
1]
< tempArray [
i
] )
{
//
=
f a l s e ;}
//
//
i
f
( tempArray [ i
i s I n c r e a s i n g
}
+
1]
> tempArray [
i
] )
{
//
=
true ;
//
//
}
//
Here
’ s
the
p r o c e s s
good
s t u f f .
//
This
tu rned
out
t o
be
a
b i t
sim pl e r
than my
f i r s t
attempt
above .
//
So ,
in
order
to
f i n d
a
” c r i t i c a
l
point , ”
there
are
two
c o n d i t i o n s
that
must
apply
//
Is
the
data
increasing / decreasing ?
//
and
//
Do we
e x p e c t
the
data
i n c r e a s e
//
For
example
,
i f
the
t o
” s i n e
wave”
i n
/ d e c r e a s e ?
i n c r e a si n g ,
and we
e x p e c t
the
next
data
//
to
point
d e c r e a s e ,
then
we
have
found
one
o f
our
p oi n t s
o f
i n t e r e s t
.
i f
( i
!=
0)
{
i
f
(
i s I n c r e a s i n g
=
t r u e && tempArray [ i
] < tempArray [
i
+
1 ] )
{
c
r i t i c a l P o i n t
[ k ]
=
i
;
k
=
k
+
1;
i
s I n c r e a s i n g
=
f a l s e
;
S
e r i a l . println
(k) ;
}
i
f
( i s I n c r e a s i n g
=
f a l s e && tempArray [
i
] > tempArray
[
i
+
1 ] )
{
c
r i t i c a l P o i n t [ k ]
=
i
;
k
=
k
+
1;
i
s I n c r e a s i n g
= true
;
S
e r i a l . println
(k) ;
}
//
I
decided
that
I
al so
wanted
to
smooth
the
data
I
was
getting ,
to
an
extent .
//
So
I
decided
to
c o l l e c t
7
points
of
i n t e r e s t
to
3
and
//
a v e r a g e
the
3
p e ri o d s .
This
h o p e f u l l y
so
i n s u r e s
as
t h a t
we
get
g e t
periods ,
a c c u r a t e
data
//
and
c u t s
down
on
i r r e g u l a r i t y
one
//
Though ,
I t
may be
i n
the
u s e r
i n
i n t e r e s t
c y c l e
t o
o f
f i n d
breath .
i r r e g u l a r i t y
i n
b re a th .
i f (k
>=
7)

4

 

//

i f

(

c r i t i c a l P o i n t . s i z e

==

7 )

 

break ;

 

}

}

 

//

Averaging

the

periods .

 

f

l o a t

period1

=

c r i t i c a l P o i n t

[ 3 ]

c r i t i c a l P o i n t [

1 ]

;

f

l o a t

period2

=

c r i t i c a l P o i n t [ 5 ]

 

c r i t i c a l P o i n t [

3 ]

;

f

l o a t

period3 =

c r i t i c a l P o i n t [ 7 ]

c r i t i c a l P o i n t [

5 ]

;

//

I

used

absolute

value

function

because

I

kept

getting

negative

 

numbers

the f o r

some

reason

 

f

l o a t

avgPeriod = ( abs ( period1 ) + abs ( period2 ) + abs ( period3 ) )

/

3 . 0 ;

S

e r i a l . println ( avgPeriod ) ;

 

//

Converting

to

time !

f

l o a t

timePeriod = avgPeriod

 

. 1

;

S

e r i a l . println ( timePeriod ) ;

 

//

Converting

period

to

frequency !

 

f

l o a t frequency = (1.0

/

timePeriod )

1000;

//

Report

frequency

to

user !

 

S

e r i a l . print ( frequency ,

10) ;

 

S e r i a l

. println (

. println ( ”

breaths

S e r i a l . print ( frequency , 10) ;   S e

per

per

second”) ;

 

//

Aaaaaand we ’ r e

done .

 

//

Again

s p e c i a l

thanks

to

August

Dailey

for

helping

out

with

the

l o g i c .

return ;

}

5