Wireless sensor networks are regarded as the most essential components of contemporary technologies since they are in charge of sensing and monitoring processes, which are the primary functions of these technologies. Because these nodes rely on an unchangeable battery and are randomly deployed in the environment, node energy management is the most essential issue to consider when designing algorithms to enhance the network's life. Clustering is a wireless sensor network (WSN) routing technique that has been implemented in order to extend network lifetime. Also, it is trendy to increase the energy levels of the node battery by utilizing various energy harvesting techniques in order to extend the network lifetime. In this paper, a new energy-aware clustering algorithm (EHEARA) has been proposed. The proposed algorithm is based on a dynamic clustering function and adopts a solar energy harvesting scheme in order to improve network lifetime. Furthermore, the active-sleep mechanism was used to distribute node activity and balance communication among nodes within clusters and cluster heads with the base station. The proposed algorithm is simulated using matrix laboratory (MATLAB), and the results show that it outperforms the low energy adaptive clustering hierarchy (LEACH), distributed energy efficient clustering (DEEC), and stable election protocol (SEP) algorithms in terms of network lifetime, energy consumption, and network throughput.