We propose a model to generate electrocardiogram signals based on a discretized reaction-diffusion system to produce a set of three nonlinear oscillators that simulate the main pacemakers in the heart. The model reproduces electrocardiograms from healthy hearts and from patients suffering various well-known rhythm disorders. In particular, it is shown that under ventricular fibrillation, the electrocardiogram signal is chaotic and the transition from sinus rhythm to chaos is consistent with the Ruelle-Takens-Newhouse route to chaos, as experimental studies indicate. The proposed model constitutes a useful tool for research, medical education, and clinical testing purposes. An electronic device based on the model was built for these purposes.