Many Internet of Things applications require a regular periodic sampling of physical quantities, such as light, CO2, or position. However, for energy harvesting devices, this can be in sharp contrast with the unreliable and time-varying amount of energy gathered opportunistically from the environment, and the severe energy storage limitations in constrained devices further exacerbate such issue. This article proposes an approach devised to jointly optimize frequency and stability of the sampling rate in energy harvesting sensors. Unlike heuristic approaches, StableSENS builds upon a solid theoretical foundation, namely, Lyapunov optimization, which - to the best of our knowledge - is applied here for the first time to the sensing scenario. One of StableSENS’ main assets is its very broad applicability: we remark that neither assumptions nor predictions on future energy availability patterns are required. Numerical results obtained in realistic scenarios show that StableSENS yields superior performance with respect to previous heuristic approaches as well as reinforcement-learning-based approaches. © 2014 IEEE.