What happens when the humidifier for your CPAP runs dry in the night? It isn't pleasant. Let's fix this.
High level flow chart
Portable Network Graphics (PNG) - 82.11 kB - 08/06/2017 at 20:16
JPEG Image - 1.68 MB - 08/06/2017 at 19:19
JPEG Image - 1.64 MB - 08/06/2017 at 19:19
JPEG Image - 1.62 MB - 08/06/2017 at 19:18
With the code mostly complete, I can try actually running this at night and seeing how much water is remaining when the alarm goes off. The water usually doesn't run out during a 6-7 hour of sleep, so I'll need to fill it up half-way or so to ensure the water will run dry.
The hanger is the main input for this device. While on the hanger, the device sits waiting for an input, but once removed from the hanger, the measurements begin. Calibration and alarm test can only be done with the mask on the hanger.
The hanger is very hacked together. I will eventually find a better, more elegant way to implement this. The push button was chosen through Digikey's search system with priority on the amount of force required to depress the button. The mask is quite light, so the button needed to be very sensitive.
Unfortunately, the button was too short for the rounded edge of the hanger, so I had to improvise in the meanwhile. That is in fact paper super glue onto the button head to add some height.
It's not pretty, but it works. Which is a good tagline for the first iteration of the design.
Five measurements are taken per weight measurement and averaged. No effort is made to put these resulting value in units of weight since I am working off percent remaining. These calibration values will be placed in EEPROM so calibration doesn't need to be done every time the device loses power.
As seen above, a new measurement value takes the place of the first value, and the oldest value is pushed out of the calculation. Every cycle the result is compared to the alarm weight to determine whether or not to sound the alarm.
Every measurement of weight is done by taking 5 measurements in 50ms increments, and taking the average of them. At any instance the weight is not exactly the same, so this helps dampen out outlier measurements.
The alarm weight is calculated by:
((full_weight - empty_weight) * alarm_percent) + empty_weight;
This allows the device to monitor the weight as a function of percent remaining, rather than pre-defined weight.
The weight to be compared to the alarm weight is the result of a 10 measurement moving average to get a stable value that will dampen out any outlying measurements. At any given time, this weight is the result of 50 separate measurements. When a new measurement is made, it adds it to the calculation, and pushes out the oldest measurement.
As long as the hanger is not in use, and the weight doesn't reach the alarm value, the device will keep making measurements. Weight calibrations can only be made while the mask is on the hanger. The user will be notified by a success or error sound based on whether or not calibration values properly set upon taking the mask off of the hanger. If the full weight is less than the empty weight in calibration, an error sound will play.
Now that the general enclosure/scale was complete, the next step is building the inputs/outputs into the design, and soldering it all up.
The two buttons are for calibrating the empty and full water reservoir weights. I chose to semi-hide these to limit the chance of accidentally resetting calibration. The screw terminal is for connecting and disconnecting the mask hanger signal (the jumper was to simulate button press).
The rails on the top were an afterthought to ensure that the CPAP machine would not move around and would be level.
Power jack and switch.
The board consists of an Arduino Nano and the load cell amplifier.
Revised block diagram showing connections to microcontroller.
Not the prettiest standoffs but it works.
There were some slight changes to the design from the original drawings. Mainly just bringing the speaker to the top rather than the side, and bringing the scale surface off-center to make the acknowledge button and speaker more prominent. As well as hiding the calibration buttons more as they won't need to be used as much.
I did another test of the scale as shown above. More to come on the enclosure later.
I ordered a 5kg load sensor and HX711 amplifier board that came with it. This amplifier takes in the wheatstone bridge input and outputs the scaled value through a serial pin. I used the Q2HX711 Arduino library to do the work of interfacing with this amplifier.
I won't be doing any scaling to proper weights with this as I am basing the calculations off of percentage of water remaining rather than comparing to any preset weight values. This way I won't need to worry about zeroing the scale or drifting results.
I will be making this out of wood as it needs to be fairly rigid to hold the weight of the CPAP machine. Below are rough sketches of what I am planning for the scale.
The load bar is set up as shown above so that a moment of force will be exerted on one side of the bar to create strain which can be related to weight.
There was some experimenting and trail and error before looking at the datasheet for the load sensor and realizing that the screw holes were for metric screws rather than imperial screws. It seems obvious now, but prior to this I had not considered imperial and metric screws incompatible.
The calibration for this will be pretty easy. Simply placing the empty humidifier reservoir on the base and hitting the calibrate button will measure the lowest weight of the design. This will be stored in non-volatile memory. The same will be done with the reservoir full.
When the mask is off the hanger, data recording will begin. A measurement will be taken approximately every 30 seconds. Once the first 10 measurements have been taking. A moving average calculation will be make with every new measurement. If this moving average value represents only 10-20% of the water left, the alarm will trigger.
Hitting the alarm acknowledge button will cause the device to wait 5 minutes and being taking measurements again. Hanging up the mask on the hanger will put the device back into inactive mode. Either way, 10 measurements will always be taken before moving average calculation begins.
And here is a block diagram just for fun.
As a CPAP machine is a totally enclosed and airtight device, the best way to monitor the water level (I believe) is to monitor the weight of the entire machine over time. By knowing the weight of the machine with no water and with full water, I can have an alarm go off when the water level is say 10% of the difference between the max and min.
Components of the idea:
- a flat box housing all components including the load sensor
2. Calibration Buttons
- two small buttons would be on the back of the base. One is to be pressed to get a measurement of the CPAP machine with no water. The other would be pressed to get a measurement of the CPAP with full water. These values would be stored in non-volatile EEPROM.
- used for waking the user up when water is low
4. Alarm Acknowledge Button
- a larger button the user can press to reset the measurement routine and stop the alarm
5. Hanger (with Tactile Button)
- this is a custom made hanger with a tactile button that will be activated when the mask strap is hanging on it. This will tell the micro to not bother with any measurements. This ensures that while the mask is not being used, no measurements will be made (and therefore no false positives on the alarm).
Next project log will cover the logic behind how it will work.