An ECG sensor, or electrocardiogram sensor, is a device that measures the electrical activity of the heart. It does this by placing electrodes on the skin and measuring the voltage changes that occur when the heart contracts.
Working of ECG sensor
The heart is a muscle that contracts and relaxes rhythmically. When the heart contracts, it generates an electrical impulse. This impulse travels through the heart muscle and causes it to contract. The ECG sensor measures the voltage changes that occur when the heart muscle contracts.
Applications of ECG sensors
ECG sensors have a wide variety of applications, including:
- Medical diagnosis
- Fitness tracking
- Research
- Virtual reality
- Gaming
- Robotics
How to use an ECG sensor
To use an ECG sensor, you will need to connect it to a device that can read the sensor’s output. This device could be a smartphone, a computer, or an Arduino board.
Once the sensor is connected, you can write code to read the sensor’s output and print it to the Serial Monitor. You can also use the sensor’s output to control other devices, such as LEDs or motors.
Interfacing Arduino with ECG sensor
To interface an Arduino board with an ECG sensor, you will need to connect the sensor’s output pins to the Arduino board’s analog input pins. You will also need to connect the sensor’s power and ground pins to the Arduino board’s power and ground pins.
Once the connections are made, you can write code to read the sensor’s output and print it to the Serial Monitor. You can also use the sensor’s output to control other devices, such as LEDs or motors.

Here is an example of ECG sensor code:
Code
// This code reads the output of an ECG sensor and prints it to the Serial Monitor.
// Import the necessary libraries
import processing.serial.*;
// Define the serial port
Serial myPort;
// Define the ECG sensor pins
int sensorPin1 = A0;
int sensorPin2 = A1;
int sensorPin3 = A2;
void setup() {
// Initialize the serial port
myPort = new Serial(this, "COM3", 9600);
// Set the ECG sensor pins as inputs
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
}
void loop() {
// Read the value from the ECG sensor
int sensorValue1 = analogRead(sensorPin1);
int sensorValue2 = analogRead(sensorPin2);
int sensorValue3 = analogRead(sensorPin3);
// Print the sensor values to the Serial Monitor
myPort.println(sensorValue1);
myPort.println(sensorValue2);
myPort.println(sensorValue3);
// Wait for 10 milliseconds
delay(10);
}
Use code with caution.
This code will first import the necessary libraries. It will then define the serial port and the ECG sensor pins.
In the setup function, the code will initialize the serial port and set the ECG sensor pins as inputs.
In the loop function, the code will read the value from the ECG sensor and print it to the Serial Monitor. It will then wait for 10 milliseconds before repeating the process.
To run this code, you will need to connect the ECG sensor to the Arduino board and the Arduino board to your computer. You will also need to install the Processing software.
Once you have installed the Processing software, you can open the code in Processing and click the “Run” button. The Serial Monitor will start displaying the value from the ECG sensor.