ziming shang
Published

Heartbeat lighting and piezo stethoscope

LED interaction with heartbeat and a digital stethoscope that can plugin into speaker

IntermediateWork in progress50
Heartbeat lighting and piezo stethoscope

Things used in this project

Hardware components

Gravity: Heart Rate Monitor Sensor for Arduino
DFRobot Gravity: Heart Rate Monitor Sensor for Arduino
×1
Piezo Sensor
ControlEverything.com Piezo Sensor
×1
stethoscope
×1
Audio / Video Cable Assembly, 3.5mm 4 Pole Jack Plug
Audio / Video Cable Assembly, 3.5mm 4 Pole Jack Plug
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Heart Pulse LED

Code

Heart Pulse LED

C/C++
To Connect heart pulse sensor to LED strip, which blinks with the heartbeat
#include <FastLED.h>

#define NUM_LEDS 171
#define LED_PIN 12
#define FADE_RATE 20    // How quickly the LEDs fade (higher = faster fade)
#define RISE_RATE 80    // How quickly the LEDs light up (higher = faster rise)
#define MAX_BRIGHTNESS 200  // Maximum brightness for LEDs

CRGB leds[NUM_LEDS];
int const PULSE_SENSOR_PIN = 10;   // 'S' Signal pin connected to A0
int Signal;                // Store incoming ADC data. Value can range from 0-1024
int Threshold = 1990;      // Determine which Signal to "count as a beat" and which to ignore.

// Variables for animation
bool beatDetected = false;
int animationBrightness = 0;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(100);
  pinMode(LED_BUILTIN, OUTPUT);  // Built-in LED will blink to your heartbeat
  Serial.begin(9600);           // Set comm speed for serial plotter window
}

void loop() {
  Signal = analogRead(PULSE_SENSOR_PIN); // Read the sensor value
  Serial.println(Signal);                // Send the signal value to serial plotter
  
  // Beat detection
  if(Signal > Threshold) {
    if (!beatDetected) {
      // New beat detected - trigger animation
      beatDetected = true;
      digitalWrite(LED_BUILTIN, HIGH);
    }
  } else {
    beatDetected = false;
    digitalWrite(LED_BUILTIN, LOW);
  }
  
  // Animation handling
  updateAnimation();
  
  delay(10);
}

void updateAnimation() {
  if (beatDetected && animationBrightness < MAX_BRIGHTNESS) {
    // Gradual increase in brightness when beat is detected
    animationBrightness += RISE_RATE;
    if (animationBrightness > MAX_BRIGHTNESS) {
      animationBrightness = MAX_BRIGHTNESS;
    }
  }
  else if (!beatDetected && animationBrightness > 0) {
    // Gradual decrease in brightness when no beat is detected
    animationBrightness -= FADE_RATE;
    if (animationBrightness < 0) {
      animationBrightness = 0;
    }
  }
  
  // Apply the brightness to all LEDs
  if (animationBrightness > 0) {
    for (int i = 0; i < NUM_LEDS; i++) {
      // Using white light with calculated brightness
      leds[i] = CHSV(10, 100, animationBrightness);
    }
    
    // Add some blur for a smoother look
    blur1d(leds, NUM_LEDS, 64);
  } else {
    // Turn off all LEDs
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CRGB::Black;
    }
  }
  
  FastLED.show();
}

Credits

ziming shang
3 projects • 8 followers

Comments