Arduino Dead or Alive
Trick for treat .. the illusion of proving you are alive .. and alive enough to even enjoy a treat.

This particular project is a carry over from a request to simply 3D print a heart for a 4th grade class demonstration -- and after negotiations negated instead reanimating a heart in a lightning storm .. uh, with an Arduino obviously .. we (me) pitched a pulse driven beating heart .. that in turn rewards your having proved to subsist, with a treat.


Ingredients
Arduino Uno
Servo
(2) 10K Potentiometer
LCD Display
Pulse Sensor
(2) 330 ohm Resistor
1000 uf Capacitor
Piezo Buzzer
2N2222 Transistor
4007 Diode
Neopixels
(2) Toggle Switch
MDF

Code
// Arduino Dead or Alive
// Vije Miller

#include "FastLED.h"
#include "LiquidCrystal.h"
#include "Servo.h"

#define NUM_LEDS 5
CRGB leds[NUM_LEDS];
#define PIN 6

// Beat Var LED
int bpm_led_delay = 500;

// Buzzer Pin
const int ekg = 9;

// LCD
const int rs = 12, en = 11, d4 = 5,
d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Switch
int aux = 7;
int aux_state = 0;

// Servo
Servo srv;
int st = 110;
int ps = 45;

// Pulse
int pulse = A0
int val;
int tot;
int nxt;
int high;

void setup()
{
Serial.begin(9600);

FastLED.addLeds
(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

pinMode(ekg, OUTPUT);
digitalWrite(ekg, LOW);

pinMode(aux, INPUT);

srv.attach(10);
srv.write(st);

lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Dead or Alive?");

}

void loop() {
// Motor and Buzzer Switch On/Off
aux_state = digitalRead(aux);

// Reset Value
tot = 0;
nxt = 0;
set_bpm = 0;

// Smoothing Pulse
for (int n = 0; n <= 5; n++) {
for (int i = 0; i <= 25; i++) {
val = analogRead(pulse);
tot = val + tot;
// Display Per Peak
if (val > 580) { // Adjust
// If Motor and Buzzer
if (aux_state == HIGH) {
beat_led(0xff, 0x00, 0x00);
delay(bpm_led_delay);
// If No Motor and Buzzer
} else if (aux_state == LOW) {
beat_led_non(0xff, 0x00, 0x00);
delay(bpm_led_delay);
}
}
delay(2);
}
nxt = tot / 25;
set_bpm = set_bpm + nxt;
}
// BPM Maths
bpm = set_bpm * 12;
// Not Very Accurate .. Meh!

if (bpm > 30) {
lcd.setCursor(0, 0);
lcd.print("Alive!");
lcd.setCursor(0, 1);
lcd.print(bpm);
lcd.print(" BPM");
} else if (bpm <= 30) {
lcd.setCursor(0, 0);
lcd.print("Undead!");
}

}


// Neopixel FastLED Fade Red
// via http://tweaking4all.com
void beat_led(byte red, byte green, byte blue) {
float r, g, b;
for (int k = 0; k < 256; k = k + 8) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
showStrip();
digitalWrite(ekg, HIGH);
srv.write(ps);
}
digitalWrite(ekg, LOW);
srv.write(st);
for (int k = 255; k >= 0; k = k - 10) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
showStrip();
}
}

void beat_led_non(byte red, byte green, byte blue) {
float r, g, b;
for (int k = 0; k < 256; k = k + 8) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
showStrip();
}
for (int k = 255; k >= 0; k = k - 10) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
showStrip();
}
}

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}

Notations
1. 'Clear watermelon' filament .. (>_ლ)
2. Censored #$@*!$#% about people, places and things.
3. Extensive modification of https://3dwarehouse.sketchup.com/mod... by Profesor D.
4. Did not earn a TVShow episode bcz .. it had been done.
5. Original concept included a candy dispenser that required evidence of life.

Archive
https://hackaday.io/project/161614-arduino-dead-or-alive
https://3dwarehouse.sketchup.com/model/ufce9d3ab-1e98-442f-afb3-7ed2d09802dd/heart

11:9:13 234-018