Recently, I’ve been thinking about exercising, but I neither want to buy a gym membership nor a sports wristband, so I decided to make one myself.
Vital sign monitoring refers to the method of observing and studying data such as body temperature, heart rate, respiratory status, and blood pressure using various sensors and devices. Different combinations of devices yield different data sets with varying reference significance, reflecting different information. I chose heart rate, blood oxygen saturation, and body temperature as the observation targets because these three data points are intuitive and easy to measure non-contact. After a thorough search on Taobao, I found that there are very few usable sensors, with only the MAX30102 and MAX30205 from Maxim being suitable, which is actually the solution used in most smart wristbands. To simplify things, I chose the LGT8F328P as the main controller, which is a domestic 8-bit microcontroller that is fully compatible with Arduino Uno, Nano, etc., and can easily pretend to be an original product after burning the BootLoader. For power supply, I chose a 602035 lithium battery that I bought for 10 yuan, rated at 3.7V and 400mAh. It is certainly overrated, but fortunately, it comes with overcharge and over-discharge protection.
When making a wearable device, there should be human-computer interaction, right? This has been a headache for me, but since it’s for personal use, it doesn’t matter if the device looks ugly. I just need a 12864 LCD, and of course, some necessary cool features are still required, like a color screen, preferably a long strip shape. Then I ran into trouble with the screen, which I’ll discuss later.
Of course, the most important thing about making a device is that it can light up, so I also prepared a 4×4 WS2812 LED board, making me the most eye-catching person in the entire sports field.
The overall framework of the solution is shown in Figure 1.
Figure 1 Overall Framework of the Solution
· Hardware Design
Since the sensor module and LCD12864 both use I2C interface communication, the hardware circuit design is relatively simple. I used the TP4056 to connect the lithium battery for power supply, then extended the I2C interface to connect the MAX30102 and MAX30205, and finally extended a serial port to drive the WS2812. To minimize costs, the entire system runs on battery voltage without a 5V boost, so the WS2812 has some color deviation, but it does not affect usage. I reserved an ISP interface, allowing the BootLoader to be burned after soldering the chip, eliminating the need to buy a burning seat. The overall circuit is shown in Figure 2, where I took a shortcut by directly using the ATmega328P package to represent the MCU.
Figure 2 Overall Circuit Diagram
· Sensor Introduction
1. MAX30205
The MAX30205 temperature sensor can measure human body temperature in a non-contact manner and provides overheat alarms, interrupts, and stop output. The MAX30205 uses a high-resolution Δ analog-to-digital converter (ADC) to convert temperature measurement data into digital quantities, communicating with the microcontroller via an I2C/serial compatible bus interface to read temperature data and configure the behavior of the overheat shutdown output.
The MAX30205 has three address selection lines, allowing for 32 available addresses. The power supply voltage range for this sensor is 2.7~3.3V, with a working current of only 600µA, and it comes with a locked protection I2C compatible interface, making it very suitable for portable fitness and medical applications.
2. MAX30102
The MAX30102 is an integrated heart rate and blood oxygen saturation monitoring sensor module with very low power consumption, suitable for smartphones and portable devices. The MAX30102 provides a 1.8V power supply for internal LEDs and an independent 5V power supply, as well as a standard I2C compatible communication interface.
· Program Design
After powering on the device, it will automatically initialize all devices, first clearing the contents on the WS2812 and LCD12864, then calibrating the MAX30102 and MAX30205. The calibration method is mean filtering, with a sample size of 1500. After calibration, the display will show heart rate (HeartRate), blood oxygen saturation (SPO2), and body temperature (Temperature), as shown in Figure 3.
Figure 3 Display Effect
The conversion relationship between the data obtained from the MAX30102 sensor and the actual data is as follows:
Blood oxygen saturation: SpO2=-45.060*X^2+ 30.354*X+94.845
Heart rate: HR=60/(Times/1000)
The conversion relationship between the data obtained from the MAX30205 sensor and the actual data is as follows:
TEMPERATURE= readData*0.00390625
During the program’s operation, the main controller continuously requests data from the sensors via I2C, but the data does not refresh in real-time because optical principle components are usually easily affected by external interference. We cache 90 sets of data at once, divided into 3 groups of 30 data points each. The first data block is averaged to serve as the baseline; then, the average of the second data block is compared against it, primarily to reduce the impact of environmental noise, avoiding large-scale data drift; the third data block is for verification, ensuring the correlation between the previous two data sets, meaning that the last 30 data points of the first sampling of 90 data points are the same as the first 30 data points of the second sampling, ensuring continuity between any adjacent data points, avoiding data jumps.
In the program, heart rate, blood oxygen saturation, and body temperature are converted into PWM values ranging from 0 to 255 to drive the WS2812. Overall, the closer the vital signs are to normal, the more blue the color; the more active the signs, the more red the color, which also serves to remind users to pay attention to their physical condition. I did not calibrate strictly, so the colors do not precisely correspond to specific vital signs.
· PCB Production
I designed the PCB in Altium Designer 2018. Since each module uses 2.54mm pin headers, I used 2.54mm female headers for module connection. The PCB appearance and wiring are shown in Figures 4 and 5.
The physical system is shown in Figure 6. To facilitate photography, I plugged all the sensors in the front. The actual usage effect is shown in Figure 7, and the test data is shown in Figure 8.
Figure 4 PCB Appearance
Figure 5 PCB Wiring
Figure 6 Physical System
Figure 7 Actual Usage Effect Figure 8 Test Data
· Precautions
Here, I will discuss a few “pits” of this project.
First, there is the sensor issue. The MAX30102 is available in two versions: one is green and relatively cheap (see Figure 9); the other is black and more expensive (see Figure 10). Both are fundamentally the same in principle, and the green version may even be more thoughtfully designed in terms of components and is cheaper. However, the green version has a very serious design flaw, and I suspect the parameters are not accurate.
Figure 9 Green Version of MAX30102
Figure 10 Black Version of MAX30102
This flaw primarily stems from the PCB design. On this PCB, the designer has used the main power supply of the sensor as the pull-up voltage for I2C, so on the green version of the MAX30102, its I2C high level is 1.8V, making it usable only on microcontrollers that operate at 1.8V (most of the STM32 series).
Next, let’s discuss the simple, straightforward, and non-troublesome solution: buy a black MAX30102. Now let’s talk about a simple, straightforward but troublesome solution.
Remove the three 4.7kΩ resistors marked in Figure 11 with a soldering iron, and then solder two 4.7kΩ resistors at the SDA and SCL pins to connect to the VIN pin, and that will work. If you need to use the INT pin, you will also need to solder a 4.7kΩ resistor to the INT pin and connect it to the VIN pin.
Figure 11 These 3 Resistors
Next, there’s an even more straightforward method: directly cut the output pin wire of the “65K9” chip on the right, and fly a wire from the right end of the 4.7kΩ resistor to the VIN pin. However, if you don’t cut the wire completely, it may damage the sensor; don’t ask me how I know.
Next, there are PCB rule issues, which mainly stem from my lack of experience. I opened slots on the PCB and noted them when ordering, but the board factory still gave me boards without slots. When I received them, I was overwhelmed and learned from customer service that Jialichuang requires the slots to be on the same layer as the board shape (Jiepei can directly open board slots). Remember this in the future, or else it will be a small cost of 5 yuan, but a big waste of time.
Then there’s the screen issue. Initially, I chose a 0.96-inch TFT color screen (see Figure 12), and the product description said it worked great. After buying it, the seller provided a U8G2 driver library, but it was for the ST7735 chip, which U8G2 does not support. The seller insisted it could work normally. In the end, I found the datasheet and wrote a driver program, only to discover the screen did not support area refresh and could only do full-screen refresh, with a very slow refresh speed. I gave up and switched back to the classic 12864 LCD.
Figure 12 0.96-inch TFT Color Screen
Finally, I want to say that I now sympathize with the engineers of wristband manufacturers. Non-contact measurement under such cost and volume constraints is likely to yield results, and I feel grateful for that. Whether it’s accurate or not… I’ve given up. The trend may be accurate, but the actual data without “special” processing can be very awkward, with a stationary person indoors showing a heart rate of 32, blood oxygen saturation of 100%, and a surface temperature of 25.7℃…
To summarize, excluding the cost of mistakes, the board and components cost a total of 132 yuan, which is enough to buy a decent sports wristband; including the cost of mistakes, I could have bought the latest Xiaomi wristband. Next time I tinker, I must set a strict budget; otherwise, it’s a waste of money and time.
Popular Science · Innovation · Practice · Sharing
Long press to recognize the QR code and follow the “Radio” magazine