Heart cell rhythm depends on the opening and closing of a complex series of valves on the cell membrane, called ion channels. Some valves let certain ions like potassium (K+) flow out, others let different ions like sodium (Na+) flow in. There are also pumps that actively move ions one direction or another.
The number of K+ ions is greater inside a resting cell than outside. But the number of Na+ ions is greater outside. When a heart cell beats, sodium channels open allowing a rapid, transient in-rush of Na+ ions, then close within about two one-thousandth's (2/1000) of a second. This depolarizes the membrane with the positive ions moving in. Then there is a slower, but prolonged (1/2 second), release of potassium to the outside of the cell which repolarizes the cell membrane.
The beat is actually much more complex and involves other ions. But the end result of this depolarization-repolarization is that the contractile filaments in the cell engage, and the cell contracts.