I'm working on a pulse oximeter and with some success everything seems to be fine until my arduino acts weirdly when processing double and float data types. I'm calculating some ratios(100 values!) and printing them. Now when i set the base value types to double or float, half the serial.prints i give do not execute, in addition the led i'm glowing glows at a rapid pace. however if i change the base value type to int everything seems to work fine. I presume that the size of the double variable (i have an array of 100) must have some effect on this. Here is the code(beware no comments! its a bare draft to ensure working!) what else could be the possible causes for this weird behaviour? i used an Atmega168 on a hand built serial board(the board works grt with a lot of other programs)
[ch12381][ch12428][ch12399][ch12385][ch12423][ch12387][ch12392]... (It's a bit, um, ...)
Complicated.
All of the global variables, all of the values that initialize them, all of the string constants, each consume RAM from the bottom up. As you call functions, each call and any local variables used inside the function are added to the stack, which consumes RAM from the top down. If you use malloc() routines, these consume RAM between the two. Only the bottom RAM can easily be accounted for by looking at the source code. A small trick can measure the stack usage at a given instant, but that can vary with other paths your program takes. And computing free malloc() heap is harder still.
halley, now I understood how difficult the calculation. If I were a compiler, I could done that job.
There seem to be only a way with trial-and-error method.
I've been working towards this goal too - with success in receiving values for incident light and working up toward Pulse Oximeter.
I have an idea for an interactive artform that will hopefully be installed in a children's hospital.
I then found your code (thanks for posting) and have it printing out values like this:
IR Value: 254
LED Value: 245
72.34 %
IR Value: 254
LED Value: 242
71.46 %
IR Value: 255
LED Value: 241
70.88 %
Seems good, however the readings don't vary much with application or removal of the paired LEDs (not more than a few percent).
Did you manage to obtain similar readings? - or was there greater variance?
Hoping you're able to help (I feel like I'm 95% there!)
Thanks!
Rich.
What type of IR LEDs are you using? Are you using a commercial disposable/ reusable sensor, or are you building your own? What wavelengths are you using?
You need two IR LEDs in different parts of the spectrum to get an 02 saturation. at the moment I cannot remember which part but it might be just a normal red LED and a normal IR LED that you get get at Radio Shack. You would also want to have filters on the sensor so that it only detects red/IR light. Otherwise you would get noise from the environmental light.
thanks for the code. Now I´m working in a pulseoximeter with arduino and a Nellcor probe, but the results aren´t good.
The Nellcor probe has the following configuration:
Pin 1, 4, 6, 8 - no connection
Pin 2 - anode of the IR LED, cathode of the red LED - usually red wire
Pin 3 - cathode of the IR LED, anode of the red LED - usually black wire
Pin 5 - photodiode anode - usually white wire
Pin 7 - shield, connects to copper shield over the photodiode
Pin 9 - photodiode cathode - usually green wire
Pins 2/3 are connected to D3* and D5* (analog).
Pin 5 (photodiode anode) is connected to A7 in order to read the values.
Pin 9 and 7 are connected to GND.
Those values are correct. The annode of the probe produces a signal of ~.40v (Red) or ~.35v (IR) depending on lighting conditions. This signal only varies by a few millivolts. Since the defaults ADC assigns a value from 0 to 1023 for values of 0v - 5v, a reading of '80' would be 0.39v, which is what is expected. The problem is that the signal only varies by a few mV, but the step size for the ADC is ~5mV! That means the values read will only range from ~75-85!
You have to do 1 (or both) of 2 things.
Set the AnalogReference to EXTERNAL and apply ~.75v to the ARef pin.
Amplify the signal's AC components before feeding to the to analog input.
Please explain the connection of your LED (IR and RED) to the arduino and the photosensor to the arduino.
About the reading from the digital pin, i think it was not correct.