A pump (70), including a compression compartment (77, 79) configured to receive, between first and second sides (76A, 76B, 80A, 80B) of the compartment, a flexible container (72, 74) holding a fluid and having an outlet; The pump also has a pump mechanism (70) that is coupled to drive the first and second sides (76A, 76B, 80A, 80B) of the compartment together so as to force the fluid out of the container through the outlet. There are first and second electrodes (24, 102) that are fixed respectively to the first and second sides (76A, 76B, 80A, 80B) . The pump also includes a processor (46) that is coupled to measure a capacitance between the first and second electrodes (24, 102) and to estimate, responsively to the capacitance, a volume of the fluid remaining in the container.