Introduction: Arduino Pulse Oximeter
Pulse oximeters are standard instruments for hospital settings. Using the relative absorbances of oxygenated and deoxygenated hemoglobin, these devices determine the percentage of a patient's blood that is carrying oxygen (a healthy range being 94-98%). This figure can be lifesaving in a clinical setting, as a sudden drop in blood oxygenation indicates a critical medical problem that needs addressed immediately.
In this project, we attempt to construct a pulse oximeter using parts that are easy to find online/in a local hardware store. The final product is an instrument that can provide enough information for someone to monitor blood oxygenation over time for only $x. The original plan was to make the device fully wearable, but due to factors outside of our control, this wasn't possible in our timescale. Given a few more components and a bit more time, this project could become completely wearable and communicate wirelessly to an external device.
Essential Parts List - Things you probably need to buy (We recommend to have a few spare of each component, especially the surface mount pieces)
Arduino Nano* $1.99 (Banggood.com)
Dual-LED - $1.37 (Mouser.com)
Photodiode - $1.67 (Mouser.com)
150 Ohm Resistor - $0.12 (Mouser.com)
180 Ohm Resistor - $0.12 (Mouser.com)
10 kOhm Resistor - $0.10 (Mouser.com)
100 kOhm Resistor - $0.12 (Mouser.com)
47 nF Capacitor - $0.16 (Mouser.com)
*(Our Nano is stuck in China at the moment, so we used an Uno, but both will work)
Total Cost: $5.55 (But... we had a bunch of things lying around and bought a few spare parts as well)
Secondary Parts List - Things that were lying around for us, but you might need to buy
Copper Clad Board - Fairly cheap (Example). In place of this, you can make and order a PCB.
PVC - Something at least an inch in diameter. The thinner kind works great.
Wires - Including some jumper wires for the breadboard and some longer ones to connect the oximeter to the board. In step 20 I show my solution to this.
Female Pin Header - These are optional, if you just want to solder wires to the boards it will work just fine.
Foam - I used L200, which is pretty specific. You can really use anything you think will be comfortable. Old mousepads are great for this!
LEDs and Resistors - Pretty cheap if you need to buy them. We used 220Ω resistors and had a few colors lying around.
Recommended Tools and Equipment
Soldering Iron with a Fine Tip
Dremel Tool with Routing and Cutting bits (You can get by with a utility knife, but not as quickly)
Pliers, Wire cutters, Wire Strippers, etc.
Step 1: Preparation: Beer-Lambert's Law
In order to understand how to build a pulse oximeter, it is first necessary to understand the theory behind its operation. The principle mathematical equation used is known as Beer-Lambert's Law.
Beer-Lambert's law is a well-used equation that describes the relationship between the concentration of a substance in a solution and the transmittance (or absorbance) of light passed through said solution. In a practical sense, the law says that increasingly greater amounts of light are blocked by increasingly greater particles in a solution. The law and its components are described below.
Absorbance = log10(Io/I) = εbc
Io = Incident light (before added sample)
I = Incident light (after added sample)
ε = Molar absorption coefficient (function of wavelength and substance)
b = Path length of light
c = Concentration of substance in sample
When measuring concentrations using Beer's Law, it's convenient to select a wavelength of light in which the sample absorbs most. For oxygenated hemoglobin, the best wavelength is about 660nm (red). For deoxygenated hemoglobin, the best wavelength is about 940nm (Infrared). Using LEDs of both wavelength, the relative concentration of each can be calculated to find a %O2 for the blood being measured.
Step 2: Preperation: Pulse Oximetry
Our device uses a dual LED (two LEDs on the same chip) for the 660nm and 940nm wavelengths. These are alternated on/off, and the Arduino records the result from the detector on the opposite side of the finger from the LEDs. The detector signal for both LEDs pulses in time with the heartbeat of the patient. The signal can thus be divided into two portions: a DC portion (representing the absorbance at the specified wavelength of everything but the blood), and an AC portion (representing the absorbance at the specified wavelength of the blood). As specified in the Beer-Lambert section, Absorbance is related to both of these values (log10[Io/I]).
%O2 is defined as: Oxygenated Hemoglobin / Total Hemoglobin
Substituting in the Beer Lambert Equations, solved for concentration, the result is a very complex fraction of fractions. This can be simplified in a few ways.
- The path length (b) for both LEDs is the same, causing it to drop out of the equation
- An intermediate ratio (R) is used. R = (AC640nm/DC640nm)/(AC940nm/DC940nm)
- Molar Absorption coefficients are constants. When divided, they can be replaced with a generic fit factor constant. This causes a slight loss in accuracy, but seems to be pretty standard for these devices.
Step 3: Preperation: Arduino
The Arduino Nano required for this project is known as a microprocessor, a class of devices that continuously runs a set of preprogrammed instructions. Microprocessors can read inputs to the device, do any required math, and write a signal to its output pins. This is incredibly useful for any small-scale project that requires math and/or logic.
Step 4: Preperation: GitHub
GitHub is a website that hosts repositories, or spaces for collections of sketches for a project. Ours is currently stored in https://github.com/ThatGuy10000/arduino-pulse-oximeter. This allows us to do several things.
- You can download the code for yourself and run it on your personal Arduino
- We can update the code at any point without changing the link here. If we find bugs or decide to do math differently, we will push out an update that will be accessible here immediately
- You can edit the code yourself. This will not cause an immediate update, but you can create a "pull request" that asks if I want to include your changes in the master code. I can accept or veto these changes.
Step 5: Safety Considerations
As a device, this is about as safe as it can get. There is very little current, and nothing is operating over 5V. In fact, the circuit should be more scared than you are.
In the construction process though, there are some key things to keep in mind.
- Knife safety should be a given, but some of the parts have a very organic shape which can make it tempting to hold them in a spot where your fingers really shouldn't be. Just be careful.
- If you own a soldering iron, heat gun, or a dremel tool, I assume you should know how to use them properly. Regardless, take the necessary precautions. Do not work through frustrations. Take a break, clear your head, and get back to it when you are more stable. (Safety information for the soldering iron, heat gun, and dremel tools can be found in the links)
- As you test any circuits or move things around on a breadboard, it's best to turn everything off. There really isn't a need to test anything with live power, so do not risk causing shorts and potentially damaging the Arduino or other components.
- Be careful when using the electronic components in and around water. Wet skin has a significantly lower resistance than dry skin, which can cause currents that exceed safe levels. Further, electric shorts in board components can cause significant damage to components. Do not operate electrical equipment near liquids.
WARNING: Please do not try to use this as a true medical device. This device is a proof of concept, but it is NOT a perfectly accurate instrument that should be used in the care of potentially sick individuals. There are plenty of cheap alternatives you can buy that provide a much higher level of accuracy.
Step 6: Tips and Tricks
As the project developed, there were a number of lessons learned. Here are a few bits of advice:
- When you're making the circuit boards, more separation between traces is your friends. Better to be on the safe side. Even better is to just order a PCB from a service like Oshpark that will do small boards like these for a reasonable price.
- On a similar note, watch out if you decide to apply power to the circuit boards before covering them. The photodiode is especially touchy, and it's just not fun if it's broken when you get to it. It's better to test the components without power and have faith that it will turn out. The diode and continuity settings are your friends.
- Once you have everything built, it's pretty cut and dry, but one of the most common errors was having the LEDs circuit board connected incorrectly. If your data is weird, check the connection, and potentially try connecting one of the LED connections to the Arduino at a time. Sometimes things become clearer that way.
- If you are still having trouble with the LEDs, you can connect 5V power into their inputs. The red will be quite bright, but the infrared is invisible. If you have a phone camera on you, you can look through it and you'll see the infrared light. The phone's camera sensor shows it as visible light, which is really convenient!
- If you're getting a lot of noise, check that the photodiode board is far away from anything carrying the nasty 60Hz power from the wall. The high value resistor is a magnet for additional noise, so beware.
- Math for calculating SpO2 is a little tricky. Follow the code provided, but make sure to edit the "fitFactor" variable to make the calculations fit your particular device. This requires trial and error.
Step 7: Constructing Circuit Boards
We'll start by making the two circuit boards that go into the design. I used a two-sided copper clad board and Dremel tool to make these by hand, which was not perfect, but it worked. If you have the resources I highly recommend drawing a schematic and having this milled with a machine, but it is do-able without.
Step 8: Board 1 - the Photodetector
Here is the circuit I put on the first board, minus the capacitor. It's best to keep a low profile, since this is going to go around your finger inside of the oximeter. The photodetector, in this case, is a photodiode which means that it is electrically similar to a diode, but will generate current for us based on the light level.
Step 9: Milling the Board
I decided to start by printing and cutting out a scale model of the recommended footprint. Because I'm just eyeballing my cutting, this gave a good reference before I took the photodetector out of its package. This is available at the vendor's sight for the photodetector.
Step 10: Drilling Down
This is the design I went with for the PCB, which I cut out with a small dremel router bit and a utility knife. My first build of this board ended up faulty for a couple of reasons. The lessons I learned for my second build were to cut more than just the minimum and to cut out where I drew a black line on the image above. There is a non-connected pin on the chip that should get its own pad, since it doesn't connect to anything else but still helps to hold the chip to the board. I also added holes for the resistor, which I made by placing the resistor next to it and eyeballing the holes.
Step 11: Placing Components
This part is a bit tricky. I've marked the orientation of the photodetector here in white. I put a tiny bit of solder on the bottom of each pin on the chip, put some solder on the circuit board, and then held the chip in place as I heated the solder on the board. You don't want to heat it up too much, but if the solder on the board is liquid, it should connect with the chip pretty quickly if you have enough solder on. You should also solder the 100kΩ resistor a 3-pin header to the same side of the board.
Step 12: Cleaning and Checking
Then, use the dremel tool to cut out the copper around the resistor leads on the backside of the board (to avoid shorting the resistor). Afterwards, use a multimeter on its continuity mode to check that none of the traces were shorted in the soldering process. As a final check, use the diode measurement of the multimeter (Tutorial if this is new tech for you) across the photodiode to make sure it's fully attached to the board.
Step 13: Board 2 - the LEDs
Here is the schematic for the second board. This one is a bit more difficult, but luckily we are warmed up from doing the last one.
Step 14: Drilling Down Redux
After several attempts that I didn't like so much, I settled on this pattern, which I drilled using the same dremel routing bit as before. From this image, it is hard to tell, but there is a connection between two parts of the board through the other side (ground in the circuit). The most important part of this cutting is the intersection where the LED chip will sit. This crosshair pattern needs to be pretty small because the connections on the LED chip are pretty close together.
Step 15: Soldering Vias
Because two opposite corners of the LED chip both need to be connected, we need to use the backside of the board to connect them. When we electrically connect one side of the board to the other, that's called a "via." To make the vias on the board, I drilled a hole in the two areas I've marked above. From here, I put the leads of the resistor on the previous board into the hole and soldered on both sides. I cut off as much excess wire as I could and did a continuity check to see that there was near-zero resistance between these two areas. Unlike the last board, this vias will not need to be outlined on the backside because we want them to be connected.
Step 16: Soldering the LED Chip
To solder the LED chip, follow the same procedure as the photodiode, adding solder onto each pin and to the surface as well. The orientation of the part is tough to get right, and I recommend following the datasheet to get your bearings. On the underside of the chip, "pin one" has a slightly different pad, and the rest of the numbers continue around the chip. I've marked what numbers attach at which points. Once you've soldered it on, you should again use the diode test setting on the multimeter to see that both sides are attached properly. This will show you which LED is the red one too, since it will light up a little when the multimeter is connected.
Step 17: The Rest of the Components
Next, solder on the resistors and the 3-pin header. If you happened to have the LED chip flipped 180° in the previous step, you are actually still fine to continue. When you put on the resistors, make sure the 150Ω resistor goes on the red side, and the other side has the 180Ω.
Step 18: Finishing and Checking
On the backside, cut around the resistors like before to avoid them shorting with the via. Cut out the board, and do one last sweep over with the continuity tester on the multimeter, just to double check that nothing became shorted accidentally.
Step 19: "Potting" the Boards
After all of the fine soldering work I did, I wanted to make sure nothing would knock the components off while the oximeter was being used, so I decided to "pot" the boards. By adding a layer of something non-conductive, all the components will stay in place better and will provide a flatter surface for the oximeter. I tested out a few things I had lying around, and this industrial strength adhesive worked well. I started by covering the backside and letting it sit for a few hours.
Step 20: Potting Continued
After the bottom is solidified, flip over the boards and coat the top. Even though it's a nearly clear adhesive, I wanted to keep the photodetector and LEDs uncovered, so before covering everything, I covered both with tiny pieces of electrical tape and after a few hours, I used a knife to carefully remove the adhesive on top of these and took the tape off. It might not be necessary to keep them uncovered, but if you decide to just cover them, just make sure to avoid air bubbles. It's fine to put as much adhesive as you want on (within reason), since a flatter surface will sit more comfortably and add more protection to the components, just make sure to let it sit for a while so it can dry throughout.
Step 21: Constructing Wires
I only had stranded wire on hand, so I decided to use some male 3-pin header to create some cables. If you have it on hand, it's much simpler to just use solid gauge wire for this without soldering. It does help to twist the wires together though, since that prevents snagging and just generally looks neater. Just solder each wire to a pin on the header, and if you have it I would coat each strand with some heat-shrink. Make sure you have the wires in the same order when you connect the header on the other side.
Step 22: Idiot-Proofing the Wiring
Because of the way I connected these boards to cables, I wanted to make sure I never connected them wrong, so I color coded the connection with paint markers. You can see here which pin is which connection and how my color coding works.
Step 23: Making an Enclosure
The enclosure for the oximeter I made with L200 foam and a piece of PVC pipe, but you can certainly use whatever foams and/or plastics you have lying around. The PVC works great because it is already nearly in the shape we want.
Step 24: PVC and Heat Guns
Using a heat gun on PVC for shaping is simple, but can take some practice. All you need to do is apply heat to the PVC until it starts to bend freely. While it's hot, you can bend it into just about any shape you want. Start out with a section of PVC pipe just wider than the boards. Cut one of the sides, and then just put some heat on it. You'll want some gloves or some wood blocks to be able to maneuver the PVC while it's hot.
Step 25: Shaping the Plastic
As you bend the loop in, cut off some any excess PVC. Before you have it completely bent in, use a knife or dremel tool to carve out a notch on one side and the edges of the opposing side. This forked shape allows you to close the loop further. It also gives you somewhere to grab in order to open the oximeter to put it on your finger. Don't worry about the tightness for now, since you'll want to see how it feels once the foam and boards are in.
Step 26: Something a Bit Softer
Next, cut a piece of foam to the width of your PVC, and to a length that will fully wrap around the inside loop.
Step 27: A Place for the Boards
To keep the board from digging into your finger, it's important to recess them into the foam. Trace the shape of the boards into the foam and use a pair of scissors to excavate the material. Instead of clearing the entire area around the headers, add some slits on the side connectors can pop out but still be slightly under the foam. At this point, you can put the boards and foam into the PVC and test out the fit in the actual PVC and then on your finger. If you do this start to lose circulation, you will want to use the heat gun again to open up the enclosure a little bit more.
Step 28: Boards Into Foam
We're going to start putting it all together now! To start, just throw some epoxy/adhesive into the holes you just made in the foam and put the boards into their little homes. I used the same adhesive I used to pot the boards earlier, which seemed to work just fine. Make sure you let this sit for a few hours before moving on.
Step 29: Foam Into Plastic
Next, I lined the inside of the PVC with the same glue and carefully put the foam inside. Wipe the excess and put something inside for the foam to chomp on. My utility knife worked well, and it really helps to push the foam against the PVC to get a strong seal.
Step 30: The Arduino Connection
At this point the actual sensor is completed, but of course we want to use it for something. There isn't much to connect to the Arduino, but it's incredibly important not to wire anything backwards or you will very likely damage things on the circuit boards. Make sure power is turned off when you are connecting the circuits (It really is the safest way to avoid problems).
Step 31: The Remaining Resistor and Capacitor
A few notes on wiring into the Arduino:
- The capacitor from the signal to ground does wonders on the noise. I didn't have a wide selection, so I used the "dad's junk bin special," but if you have variety then go for something around 47nF or less. Otherwise you might not be able to have a fast switching speed between the red and IR LEDs.
- The resistor going into the photodetector cable is a safety thing. It isn't necessary, but I was scared that while handling the breadboard circuit I might accidentally short something and botch the whole project. It won't cover every accident, but it just helps to have a little more piece of mind.
Step 32: Testing LED Current
Once I had these in, test the current going through the red and IR LEDs using a multimeter on the ammeter mode. The goal here is to just check that they are similar. Mine were at around 17mA.
Step 33: The Code
As stated in the preparation step, the code for this device can be found in our GitHub repository. Simply:
- Download this code by clicking "Clone or download"/"Download Zip".
- Unzip this file using 7zip or a similar program, and open this file in Arduino IDE.
- Upload it to your Arduino and connect the pins as described in the pin assignments (or change them in the code, but realize you'll have to do this every time you redownload from GitHub).
- If you want to see a Serial output on the serial monitor, change the serialDisplay boolean to True. The other input variables are described in the code; the current values worked well for us, but you can experiment with others to achieve the optimum performance for your setup.
Step 34: Circuit Diagram
Step 35: Further Ideas
We would like to add (or one of our many followers might think about adding)
- Bluetooth connection for exchanging data with a computer
- Connection to a Google Home/Amazon device to request SpO2 information
- More flushed out math for calculating SpO2, as currently we have no reference for comparison. We are simply using math that we found online.
- Code for calculating and reporting the heartbeat of the patient, along with SpO2
- Using an Integrated Circuit for our measurements and math, eliminating much of the variability for our output.