Build Your Own Portable ECG
Heart Monitor Robot!
Turn an Arduino into a real heart-watching machine — see your heartbeat on a screen in real time. Perfect for curious kids aged 12 and up! 🚀
// WHAT WE'RE BUILDING
🫀 What Is an ECG?
ECG stands for Electrocardiogram (say: ee-lek-tro-KAR-dee-oh-gram). Doctors use ECGs every day to look at how your heart is beating. Every time your heart pumps blood, it sends a tiny electrical signal through your body. Our robot project catches those signals and draws them on a screen — just like a real hospital machine!
We're going to build a portable version using an Arduino microcontroller and a special sensor called the AD8232. When you're done, you'll be able to see your own heartbeat waveform — the spiky zigzag line you've seen in movies! 📺
Your heart muscle creates tiny electrical pulses every beat
Sticky pads on your skin capture those tiny signals
The AD8232 chip makes the tiny signal much louder
The Arduino measures the signal thousands of times per second
The Serial Plotter draws the iconic ECG waveform live!
// SHOPPING LIST
🛒 Parts You'll Need
Ask a grown-up to help you buy these parts. You can find them at electronics stores or online. Total cost is usually around $20–$35.
// BUILD GUIDE
🛠️ Step-by-Step Build Instructions
Follow these steps in order. Take your time — there's no rush! Ask a grown-up if you get stuck.
⬇️ Install Arduino IDE
Go to arduino.cc/en/software and download the free Arduino IDE for your computer (Windows, Mac, or Linux all work).
Install it like any normal program. When it opens, you'll see a white code editor — that's where we'll write our program!
🔌 Connect Arduino to Your Computer
Plug the USB cable into your Arduino Uno and the other end into your computer. A green power LED on the Arduino should light up.
In Arduino IDE: go to Tools → Board → Arduino Uno, then Tools → Port and select the COM port that appeared (on Mac it starts with /dev/cu.usbmodem...).
🧱 Set Up the Breadboard
Place your breadboard on a flat surface. Push the AD8232 module into the breadboard so its pins sit firmly in the holes.
Breadboards have rows of connected holes. The long rows on the sides (+/–) are for power, and the middle rows connect side-to-side.
🔗 Wire Up the Circuit
Using the connection table above, connect jumper wires from the AD8232 module to the Arduino:
🟡 3.3V → 3.3V | ⚫ GND → GND | 🟢 OUTPUT → A0 | 🔵 LO– → D2 | 🟣 LO+ → D3
If adding the optional LED: connect LED long leg (+) to D13 through a 220Ω resistor, and short leg (–) to GND.
📝 Upload the Code
Copy the Arduino code from the section below into the Arduino IDE editor. Replace any existing code (the setup() and loop() functions).
Click the → Upload button (right-pointing arrow at the top). Wait for "Done uploading" to appear at the bottom of the screen.
🩹 Attach the Electrode Pads
Stick the three electrode pads to your body. Ask a grown-up to help! Standard placement:
🔴 RA (Right Arm) — right wrist or upper right chest | 🟡 LA (Left Arm) — left wrist or upper left chest | ⚫ RL (Right Leg) — right lower chest or hip area
Connect the coloured lead wires from the AD8232 to the electrode pads using the snap connectors.
📊 Open Serial Plotter
In Arduino IDE: go to Tools → Serial Plotter. Make sure the baud rate in the bottom-right is set to 9600.
Sit still, breathe normally, and watch your heartbeat draw itself on the screen! You'll see the classic spiky ECG waveform — those are called P, QRS, and T waves. 🎉
// ARDUINO CODE
💻 The Full Arduino Code
Copy this code and paste it into Arduino IDE. Every line has a comment (after //) explaining what it does — great for learning!
/* ================================================ PORTABLE ECG HEART MONITOR Kids Robotics Project 🤖❤️ Components: Arduino Uno + AD8232 ECG Sensor ================================================ */ // ── PIN DEFINITIONS ─────────────────────────── const int LO_MINUS_PIN = 2; // Lead-off detect negative const int LO_PLUS_PIN = 3; // Lead-off detect positive const int ECG_PIN = A0; // Analog ECG signal input const int LED_PIN = 13; // Optional heartbeat LED // ── HEARTBEAT DETECTION VARIABLES ───────────── int sensorValue = 0; // Raw ECG reading (0–1023) int threshold = 600; // Value above = peak detected bool peakFound = false; // Are we currently in a peak? unsigned long lastBeat = 0; // Time of last heartbeat (ms) unsigned long beatInterval = 0;// Time between beats (ms) int bpm = 0; // Beats Per Minute // ── SETUP: RUNS ONCE AT START ───────────────── void setup() { Serial.begin(9600); // Start talking to computer // Set lead-off pins as inputs pinMode(LO_MINUS_PIN, INPUT); pinMode(LO_PLUS_PIN, INPUT); // LED pin as output pinMode(LED_PIN, OUTPUT); Serial.println("ECG Monitor Ready! Attach electrodes."); } // ── LOOP: RUNS OVER AND OVER ────────────────── void loop() { // CHECK: Are the electrode leads attached properly? if (digitalRead(LO_MINUS_PIN) == HIGH || digitalRead(LO_PLUS_PIN) == HIGH) { // Electrodes not connected — print warning Serial.println(0); digitalWrite(LED_PIN, LOW); delay(10); return; // Skip rest of loop } // READ the ECG signal from analog pin A0 sensorValue = analogRead(ECG_PIN); // SEND the value to Serial Plotter (draws the wave!) Serial.println(sensorValue); // ── HEARTBEAT DETECTION ───────────────────── if (sensorValue > threshold && !peakFound) { // NEW PEAK DETECTED! 🎉 peakFound = true; digitalWrite(LED_PIN, HIGH); // Flash LED // Calculate time between this beat and last beat beatInterval = millis() - lastBeat; lastBeat = millis(); // Prevent divide-by-zero and crazy readings if (beatInterval > 300 && beatInterval < 2000) { // BPM = 60 seconds ÷ beat interval in seconds bpm = (int)(60000.0 / beatInterval); // Print BPM to Serial Monitor Serial.print("Heart Rate: "); Serial.print(bpm); Serial.println(" BPM"); } } else if (sensorValue < threshold - 50) { // Signal came back down — reset for next peak peakFound = false; digitalWrite(LED_PIN, LOW); // Turn off LED } // Wait 5ms between readings (200 samples per second) delay(5); }
// DID YOU KNOW?
🤩 Cool Heart Science Facts!
Times your heart beats every single day — without stopping! ❤️
Average resting heart beats per minute for kids aged 10–12
Year that scientists first discovered the heart produces electricity
Kilometres of blood vessels in the human body — enough to wrap Earth 80 times!
// HELP CENTER
🔧 Troubleshooting Problems
Something not working? Don't worry — troubleshooting is a real engineering skill! Check these common problems:
Make sure you selected the right COM port in Tools → Port. Unplug and replug the USB, then try again. Check all wires are firmly connected.
The electrodes might not be attached properly. Press them firmly on your skin. Make sure the lead wires are snapped onto the electrode pads securely.
Try to sit very still — muscle movement creates electrical noise! Make sure your skin is clean and dry where the electrodes attach. Try moving the electrode positions slightly.
This means the lead-off detection fired. Your electrodes lost contact — re-press them onto your skin and check the wire connections to D2 and D3.
Check that LED is in the right way — the longer leg (+) should go to D13 side. Verify your 220Ω resistor is connected. Also check the threshold value in code (try changing 600 to 550 or 650).
// STAY SAFE
⚠️ Important Safety Rules
This project is safe when built correctly, but always follow these rules:
🛡️ Safety First — Always!
- Always have an adult supervise this project, especially when attaching electrodes.
- Use ONLY the 3.3V output from Arduino — NEVER connect body electrodes to any higher voltage or mains electricity.
- Do NOT use this device if you have a pacemaker or any heart condition. Consult a doctor first.
- This is a learning/hobby project, NOT a medical device. Never use it to diagnose health problems.
- Disconnect electrodes before modifying any wiring or code.
- If you feel any discomfort or tingling, remove the electrodes immediately.
- Keep all electronics away from water and liquids.
// LEVEL UP
🚀 What Can You Do Next?
Connect an OLED screen to show BPM without a computer!
Save heart rate readings to an SD card over time
Upgrade to ESP32 to send data to your phone via Bluetooth
Use Python and machine learning to detect irregular beats!

Comments
Post a Comment