ECG Patiënt Simulator - The Hardware.

And now the circuit:

The main goal of this project is to make a circuit that is easy to reproduce without the need for special tools. Therefore, only through hole components are used. For this project I designed a printed circuit board, but even on a prototyping-board this circuit can be perfectly recreated.  No exotic parts are used, all components are very good available from various distributors of electronics parts worldwide. In the development phase I used an Arduino UNO with the Atmega328 microcontroller in a 28-Pin DIL housing. To obtain a finished product that is as compact as possible, only the microcontroller, the crystal of 16MHz, a few capacitors and a resistor from the Arduino UNO were used in the eventual result. The other parts such as the voltage regulator, the USB interface, the connectors and other components of the Arduino board became redundant in this design or were replaced by other parts.

The full schematic of the ECG Patient Simulator (Click on the image to enlarge).

In this circuit, 3 blocks can be distinguished, the power supply, the microcontroller with interfacing, and the conditioning of the output signals.

Hereafter I will treat these blocks one by one.

The power supply:

The circuit is powered by a 9V battery that can be connected to the "+ Batt." pin-connector on the PCB. This connection tolerates however an input voltage of up to 18Vdc.  When using a higher power voltage than 9Vdc the value of the attenuation resistance for the loudspeaker should be reconsidered. We will come back to this later. The 9V voltage from the battery wants to enter the circuit via diode D5 and via MOSFET Q1, but resistor R1 pulls the gate of this MOSFET to the same level as its source pin.  As a result, MOSFET Q1 is blocked.

The power supply part of the circuit with the LE50ABZ as a low drop linear voltage regulator. (Click on the image to enlarge.)

Since this is a “P-Channel Enhancement” type MOSFET, the gate must be negative in relation with its source to make this transistor conduct. This can be achieved by pressing the push button SW1A, which causes the gate of Q1 to go towards the ground potential via diode D1. A second way to bring down the gate of Q1 is by means of MOSFET Q2. The gate of this MOSFET Q2 is pulled to ground by resistor R2. Since this is an N-Channel Enhancement Type MOSFET, it will not be able to make Q1 conduct as long as the gate of Q2 is not being driven higher by the microcontroller.

And this already explained a great deal of the power supply.

The linear voltage regulator U2, which provides the 5V supply for the circuit, receives its input voltage by pressing push button SW1A, this makes Q1 to conduct and the "+ Batt" voltage will be passed to the voltage regulator U2. The microcontroller now receives its 5V power supply via voltage regulator U2. One of the first tasks in the software of the microcontroller is to make the output PD5 high and thus activates the gate of Q2. This causes a conductive Q2 to be in parallel with the still pressed SW1A. The microcontroller then keeps Q2 on, so the microcontroller will get its 5V power and can continue doing its job. We can now release SW1A because Q2 takes over the job of this push button. When the microcontroller decides to turn itself off, it sinks the digital output PD5 and Q2 stops conducting. The source-gate voltage of Q1 will vanish and Q1 will block. At this point the input voltage to the voltage regulator U2 is gone, causing the 5V of the microcontroller to be cut off. This switches off the circuit. C1, C2 and C3 will smoothen the supply voltage and diode D5 provides foolproof protection against reverse input voltage on the "+ Batt" power supply connector.

The Microcontroller:

The integration of a microcontroller in a circuit is always a lot of fun. Not only does it make the whole concept very flexible, it also reduces the size of the overall circuit tremendously. This is because much of the digital logic can be substituted by the software. However, some components are still required to ensure correct interfacing to the microcontroller.

In the Microcontroller part, the Atmega328 is the main component. It is the escape version of an Arduino Uno. (Click on the image to enlarge.)


One of the tasks of the microcontroller is to monitor the battery.  Between MOSFET Q1 and voltage regulator U2 a voltage divider is connected, which is formed by resistor R5 and R6.  With this voltage divider, the "+ Batt" input voltage, reduced by the voltage drop across diode D5 (approximately 0.8V), is brought to I/O pin PC0 of the microcontroller through the conducting MOSFET Q1. The voltage produced by the voltage divider is a representation of the input voltage. With a 9Vdc battery input, the output of the voltage divider is ((9 - 0.8) / (2700 + 5600)) * 2700) = 2.6 .... Vdc.

I/O pin PC0 of the microcontroller is input A0, as we know from the Arduino UNO. It is obvious that, with a piece of program, we can use the measured analog battery voltage to indicate, for example, if the battery needs to be replaced or to prevent us switching on the simulator when the battery is too weak. Capacitor C7 protects this measured value from clutter on the power or from external interferences. Diode D4 prevents analog I/O PC0 from going higher than the supply voltage of the microcontroller because it doesn't like that very much actually.

Duracell MN1604 ZnMn/O2  9V battery.

The software uses the information from the discharge characteristics of a 9V battery to take various actions. At a load of approximatly 50mA,  which is about the laud of our circuit, the voltage of a 9V battery will quickly drop to about 8V and then show a less steep decay to about 6V in function of time and load. The linear voltage regulator LE50ABZ is a low drop type that will still be satisfied with an input voltage of 5.2V. This means that, before the output voltage of the voltage regulator becomes unpredictable, the minimum voltage of the battery may drop to 5.2V plus the voltage drop of 0.8V across D5 which results in a battery voltage of 6V. This is exactly the tipping point at which the battery voltage in our discharge characteristic starts to drop more steeply at the same load. The voltage drop across Q1 is negligible.

Discharge characteristic of a 9V Duracell MN1604 battery.

The software ensures that the ECG Patient Simulator can no longer be switched on when the battery voltage is under approximately 6.3V. Due to the 0.3V difference between this 6.3V and the 6V tipping point of the battery, there is still some margin for an emergency startup.  Because of this, the user is still able  to do a simulation in case of an urgency. How to carry out an emergency startup can be found in the description of the software or in the brief manual of this device.

Push button SW1A has a triple function. On one hand, it switches on and off the ECG Patient Simulator, and on the other hand, SW1A can also increase the rhythm of the ECG signal or it can adjust the amplitude of the signal during calibration. To do so, the microcontroller must be able to read the state of this push button. I/O pin PD3 of the microcontroller takes care of this. This pin is connected to the push button via diode D2. If SW1A is not pressed, PD3 will read a high value because of the internal PULLUP resistance of this pin. Diode D2 ensures that I/O pin PD3 is protected from voltage influences that would reach this pin from the battery via D5, R1 and D1 and also prevent the gate of Q1 from being operated by PD3.

I/O pin PD6 controls the speaker via MOSFET Q3 and the attenuation resistor. The attenuation resistor is not soldered to the printed circuit board, but can be plugged onto the PCB using the female pin connector J4.
This gives you the ability to change the value of this attenuation resistor, when you want to adjust the sound level of the speaker on J3. The pin connector J4 also offers the possibility to connect a potentiometer with sufficient power to obtain a continuous volume control of the speaker. A third line of thought is to connect, for example, a relay or another component on pin connector J3 while bridging J4. This opens new dimensions when reprogramming I/O pin PD6. Diode D3 is a freewheeling diode to tame any inductive loads on J3.

Coming back to my comment in the power section, I would like to point out that the speaker terminal on the positive  side is connected before the voltage regulator. This means that if a higher supply voltage is used than that of a 9V battery, the value of this attenuation resistor must also be revised.  This is important when you are not using a piezo speaker, as I would recommend. When you are using a classic speaker anyway, it should have an impedance of at least 8 Ohms or higher. The typical value for the attenuation resistor when using a speaker of 8 Ohms and with a supply voltage of 9Vdc should be somewhere around 100 Ohms. Always make sure that the current through MOSFET Q3 does never exceed 200mA when selecting this resistor.

With the double DIP switch SW4, connected to I / O pins PD4 and PD5, the beep tone at heart rate can be switched off, with switch 1, while the startup tone can be changed, by switch 2. These DIP-Switches can be assigned another function when changing the software. Both switches are active low and inside the microcontroller, both I / O pins are pulled high by their internal pullup resistor.

There is also an LED that blinks to the rhythm of the selected heart rate, which is controlled to I/O pin PD3. Resistor R3 provides the necessary current limitation for the LED and I/O PD3. The reset pin of our Atmega328 is kept high by resistor R4 and the clock oscillator of the microcontroller is manned by the 16MHz crystal Y1 together with both capacitors C5 and C6 of 22pF each.

The capacitor C4 of 100nF is a decoupling capacitor for the supply voltage of the microcontroller and is therefore placed close to the microcontroller.

This should be about everything that has to be said about the circuit around our microcontroller, the Atmega328.


Oh yes, I almost forgot, of course, one more thing,  the microcontroller also produces the ECG signal!
Indeed, last but not least, I/O pin PB1 or pin 15 provides the ECG waveform. Because the Atmega328 is not equipped with an analog output and because we have to be able to offer the digital sample values ​​of the ECG signal, in one way or another to our ECG monitor as an analog signal, we can use the PWM mode of this output PB1.

The (pulse width modulated) PWM signal passes through two successive low-pass filters (R7, C8 and R8, C9) (integrated twice), resulting the ECG to reappear between R8 and R9 as an analog signal. The advantage is that we save a D/A converter and some space on our PCB, but the disadvantage is that the ECG signal at the output of our low-pass filters is influenced by the frequency or in other words by the different heart rhythms.

This is why we send this analog signal back to the analog input PC1 of the microcontroller (A1 on the Arduino UNO). In the software, an amplitude measurement is done at the highest point of the ECG wave. By using these measures at the different heart rhythms, it is possible to decrease the pulse width (more attenuation) at lower frequencies and so we can obtain an nearly constant peak to peak value of the ECG wave for all heart rhythms.

Above: The PWM signal at PB1 of the microcontroller and the waveform after the low pass filters. The phase shift between the PWM signal and the analog waveform, as a result of the RC circuit, can clearly be seen .

Below: The complete waveform as it is sent to the resistance network (voltage divider) at the output. The signal is set to its maximum here.

(Click on the images to enlarge).

Conditioning the output signals:

The series of resistors at the output of our ECG Patient Simulator R9, R10, R11, R12 and R13 reduce the signal coming from the low-pass filters, which is approximately 2 Vpp - 2.5 Vpp maximum, to a series of signals with the peak-to-peak value and polarity as we can measure on the electrodes of a connected patient.

From the Einthoven's Triangle we can conclude that the right arm electrode is, in terms of potential, lower than the left arm electrode. We also see that the right arm electrode is lower than the left foot electrode and that the left arm electrode is also at a lower potential than the left foot electrode. It is easy to understand that the lowest potential can be found on the right arm and the highest potential on the left foot. Somewhere in between lies the potential of the left arm. The N or right foot electrode is known as the ground potential and mainly serves for the reduction of external disturbances.

I tried to obtain the potential of the V1 electrode from a number of realistic ECG examples that could be found on the internet. The potential of the V1 electrode floats somewhere between the 3 main leads and is slightly lower than the left arm electrode. In reality, the V1 lead is formed by the average of the 3 main leads and the measured value at the V1 electrode on the patient.

The 3 main leads with polarity and electrodes.

The low-pass filters and the voltage divider at the output of the circuit, which take care of the conditioning of the various signals.

The result is that, the right foot electrode is on the ground potential (thus also on the ground potential of our circuit) and that the right arm has the lowest potential of the 3 main electrodes (above R13). The left foot has the highest potential of the 3 main electrodes (just above R10). In between, both electrodes V1 (just above R12) and the left arm electrode (just above R11) are positioned.  Lead II (RA-LL) is,in reality the largest lead (about 1 mVpp to 3 mVpp).  The other leads are somewhere in between.  Now we can, by using the Ohm's law and by comparing examples of existing ECGs, calculate the resistance values ​​ ​​for R9 to R13 in our schematic, knowing that between R8 and R9 (SignalVoltage) the peak value of the ECG will be somewhere between 1.5vpp and 2.5Vpp maximum.

The ratios between the peak values ​​of the different leads are not that important for our project. In practice, the placement of the electrodes and the quality of the connections with the patient can also result in varying ratios in the peak values ​​of the mutual signals. Deviations from the general peak value of the output signal due to tolerances on the resistors and capacitors can be adjusted by doing a calibration of the ECG Patient Simulator.

So far, I think we have discussed everything about the circuit.
From the schematic that I drew in KiCad, I designed a double-sided PCB with solder mask and silkscreen and had it made by Eurocircuits, a Belgian PCB manufacturer. The result is a top class PCB. At Eurocirquits you can order a small prototype edition of your PCB (max 5 pieces). This is delivered within a few days after payment. The price may be higher than the Chinese competition, but my patriotism drives me again to the high service and quality of my own country.


The finished PCB with speaker, battery clip and flat-cable for the different electrode clips.

As we say in Belgium, “the last one turns off the light and closes the door” we should also be able to turn off our circuit when we no longer need it. The simulator is turned off by pressing SW1A for 3 seconds. The software will pull down I/O pin PD5 causing Q2 to give up its task of keeping Q1 conducting. However, Q1 is still being conducted by SW1A at this time because we are still pressing it to switch the device off. The circuit will shut down as soon as SW1A is released.

The software code for this circuit is described under the "The software" tab and can be downloaded in the form of an Arduino IDE sketch which is fully commented in English.


Have great fun building your own EKG Patient Simulator.


Johan Smets

The STEAM Reactor / Makerspace Genk.

A small photo shoot of the circuit and the printed circuit board. Also the connection diagram on which you can see how the different leads are connected (click on an image to enlarge).

image/svg+xmlOpen Source Licenses HardwareSoftwareDocumentationCERN-OHL-S-2.0-or-laterGPL-3.0-or-laterCC-BY-SA-4.0

This ECG Patient Simulator project is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.