End result
Wiring
Code:
/* Pulse Sensor Amped 1.4 by Joel Murphy and Yury Gitman http://www.pulsesensor.com
———————- Notes ———————- ———————-
This code:
1) Blinks an LED to User’s Live Heartbeat PIN 13
2) Fades an LED to User’s Live HeartBeat
3) Determines BPM
4) Prints All of the Above to Serial
Read Me:
https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/README.md
———————- ———————- ———————-
*/
#include <Adafruit_NeoPixel.h>; // Library containing
// Variables
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 9; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
int fadeControl = 240;//will hold the current brightness level
int fadeDirection = -1;//change lights to fade up or down
int tempPin = A1; // sets the arduino pin for the temp sensor to analog pin 0
int value; //variable that stores the value of the temp sensorb
int g = 0; // Green is set to zero (for non-red colors, change this)
int b = 0; // Blue is set to zero (for non-red colors, change this)
int r = 0;
int TempMap = 75;
int i;
int int_temperatureF;
//int temperatureF;
// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // “True” when User’s live heartbeat is detected. “False” when not a “live beat”.
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
// Regards Serial OutPut — Set This Up to your needs
static boolean serialVisual = false; // Set to ‘false’ by Default. Re-set to ‘true’ to see Arduino Serial Monitor ASCII Visual Pulse
// Set up use of NeoPixels
const int NUMPIXELS = 60; // Put the number of NeoPixels you are using here
const int BRIGHTNESS = 200; // Set brightness of NeoPixels here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, fadePin, NEO_GRB + NEO_KHZ800);
void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
Serial.begin(9600);
strip.begin();
strip.setBrightness(BRIGHTNESS);
for (int x=0; x < NUMPIXELS; x++) { // Initialize all pixels to ‘off’
strip.setPixelColor(x, strip.Color(0, 0, 00));
}
strip.show(); // Ensure the pixels are off
delay(500); // Wait a second
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
}
// Where the Magic Happens
void loop(){
// getTemp();
//serialOutput() ;
if (QS == true){ // A Heartbeat Was Found
// BPM and IBI have been Determined
// Quantified Self “QS” true when arduino finds a heartbeat
// digitalWrite(blinkPin,HIGH); // Blink LED, we got a beat.
Serial.println(“Beat”);
Serial.println();
rainbowpulse(15);
fadeControl = 240; // Makes the LED Fade Effect Happen
// Set ‘fadeRate’ Variable to 255 to fade LED with pulse
// strip.setBrightness(fadeControl);//set the strip brightness
// serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
}
delay(20); // take a break
}
void rainbowpulse(uint8_t fadeStep) {
uint16_t i, j;
getTemp();
//
// for(i=0; i<60; i++) {
// for(int i=0;i <= TempMap;i++) {
// strip.setPixelColor(i, strip.Color(255,0,0));
// }
// for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
// {
// strip.setPixelColor(i, strip.Color(100,100,0));
// }
// }
for (fadeControl = 240; fadeControl >= 60; fadeControl–) {
strip.setBrightness(fadeControl);//set the strip brightness
strip.show();
}
//delay(10);
// strip.setBrightness(240);//set the strip brightness
//strip.show();
delay(fadeStep); //delay(10)
}
void getTemp () {
//Serial.println(“getting temp and stopping”);
//delay(3000);
//getting the voltage reading from the temperature sensor
int value = analogRead(tempPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = value * 5.0 / 1024;
// print out the voltage
//Serial.print(voltage); Serial.println(” volts”);
// now print out the temperature
float temperatureC = (voltage – 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge – 500mV) times 100)
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.println(temperatureF);
//Serial.println(” degrees F”);
int_temperatureF = (int) temperatureF – 5;
TempMap = map(int_temperatureF, 10, 100, 1, 60);
//Serial.print(“TempMap: “);
// Serial.println(TempMap);
TempMap = TempMap – 5;
setColor (temperatureF);
}
void setColor (int temperatureF) {
if (temperatureF >= 90.05)//if above 90 degrees, strip is red and entire strip is lit
{
strip.clear();
for(int i=0;i <= TempMap;i++)
{
strip.setPixelColor(i, strip.Color(20,150,200));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i, strip.Color(0,255,0));
}
}
else if (temperatureF < 90.2 && temperatureF >= 80.05) //if 90 > temperatureF >= 80 orange and strip is partially lit up to 29th pixel
{
strip.clear();
for(int i=0;i <= TempMap;i++)
{
strip.setPixelColor(i, strip.Color(255,63,4));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i, strip.Color(128,255,0));
}
}
else if (temperatureF < 80.02 && temperatureF >= 70.5)// if 80 > temperatureF >= 70 yellow-green and strip is lit up to 25th pixel
{
// strip.clear();
for(int i = 0; i <= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(220,220,100));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i,strip.Color(255,204,0));
}
}
else if (temperatureF < 70 && temperatureF >= 60.5)// if 70 > temperatureF >= 60 green and strip is lit up to 21st pixel
{
// strip.clear();
for(int i = 0; i<= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(255,97,4));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i,strip.Color(255,0,0));
}
}
else if (temperatureF < 60.02 && temperatureF >= 50.5) //if 60 > temperatureF >= 50 blue and strip is lit up to 17th pixel
{
// strip.clear();
for(int i = 0; i <= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(255,172,4));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i,strip.Color(0,0,255));
}
}
else if (temperatureF < 50.02 && temperatureF >= 40.5) //if 50 > temperatureF >= 40 aqua and strip is lit to 13th pixel
{
strip.clear();
for(int i = 0; i <= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(198,22,150));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i, strip.Color(255,0,255));
}
}
else if (temperatureF < 40.02 && temperatureF >= 32.5) //if 40 > temperatureF >= 32 fuschia and strip is lit to 9th pixel
{
strip.clear();
for(int i = 0; i <= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(220,220,100));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i, strip.Color(168, 22,198));
}
}
else if (temperatureF < 32.5) //temp < freezing white and strip is lit to 5th pixel
{
strip.clear();
for(i = 0;i <= TempMap; i++)
{
strip.setPixelColor(i, strip.Color(22,22,198));
}
for(int i=(TempMap+1);i <= 60;i++) // yellow for the rest
{
strip.setPixelColor(i, strip.Color(255,255,255));
}//end for
}
strip.show();
}
//void setStrip(int g) { // Set the strip to one color intensity (red)
// int r = 0; // Green is set to zero (for non-red colors, change this)
// int b = 0; // Blue is set to zero (for non-red colors, change this)
// for (int x=0; x < NUMPIXELS; x++) {
// strip.setPixelColor(x, strip.Color(r, g, b));
// }
// strip.show();
//}