// HEARTBEAT SENSOR (displays heart rate on LCD screen)
int sensorPin = A0; // This is the analog sensor pin the backwards S pin is connected to // you can use any of the analog pins, but would need to change this to match double alpha = 0.75; // This code uses a rather cool way of averaging the values, using 75% of the // average of the previous values and 25% of the current value. int period = 20; // This is how long the code delays in milliseconds between readings (20 mSec) int in = 8; int Reset=6; int start=7; int count=0,i=0,k=0,rate=0;
// LCD SCREEN #include<LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// BIG SOUND SENSOR int soundDetectedPin = 10; int soundDetectedVal = HIGH; boolean bAlarm = false;
unsigned long lastSoundDetectTime;
int soundAlarmTime = 500;
// PUSH BUTTON AND BUZZER int buzzer = 3; int ledPin = 13; int inPin = 7; int val = 0;
#define sing
#define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
#define melodyPin 3 //Hotline Bling Melody int hotlineb_melody[] = { 0, NOTE_D5, NOTE_D5, NOTE_D5, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_C5, 0, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5,
NOTE_C5, NOTE_A4, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_C5, 0, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_C5, NOTE_A4,
NOTE_F5, NOTE_C6, NOTE_C6, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_C6, NOTE_D6, 0, NOTE_F5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, 0, NOTE_C6, NOTE_C6, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_C6, NOTE_D6, 0, NOTE_F5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_D6, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_F5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6,
NOTE_A5, NOTE_D6, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5,
NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_G5 };
//HotlineBLING tempo int hotlineb_tempo[] = { 12, 12, 12, 12, 12, 12, 12, 12, 6, 2, 3, 12, 12, 12, 12, 3,
3, 3, 12, 12, 12, 12, 6, 2, 3, 12, 12, 12, 12, 3, 3, 4,
12, 12, 12, 12, 12, 12, 12, 2, 3, 12, 12, 12, 12, 12, 12,
2, 3, 12, 12, 12, 12, 12, 12, 3, 3, 12, 12, 12, 12, 12, 12,
2, 12, 12, 12, 12, 12, 12, 12, 12, 1.5, 12, 12, 12, 12, 12, 12,
12, 12, 6, 2, 12, 12, 12, 12, 12, 12, 12, 12, 6, 2, 12, 12,
12, 12, 12, 12, 12, 12, 6, 2.4, 12, 12, 12, 12, 12, 12, 12, 12,
12, 1.5, 12, 12, 12, 12, 12, 12, 12, 12, 6, 2, 12, 12, 12, 12,
12, 12, 12, 12, 6, 2, 12, 12, 12, 12, 12, 12, 12, 12, 8, 24, 2 };
void setup() {
{ //lcd.createChar(1, heart); lcd.begin(16,2);
lcd.print("Heart Beat"); lcd.write(1); lcd.setCursor(0,1); lcd.print("Monitering"); pinMode(in, INPUT); pinMode(Reset, INPUT); pinMode(start, INPUT); digitalWrite(Reset, HIGH); digitalWrite(start, HIGH); delay(1000);
lcd.begin(16,2); lcd.print("need to talk?"); delay(1000);
lcd.begin(16,2); lcd.print("not yet satisfied with care?"); delay(1000); } // This code runs on startup, it sets ledPin to output so it can blink the LED that is built into the // Arduino (but then never does), and sets the serial port up for fast 115,200 baud communication // of the values (make sure you change your serial monitor to match).
Serial.begin (115200); // the baud rate of the serial data { Serial.begin(115200); pinMode (soundDetectedPin, INPUT); } //PUSH BUTTON AND BUZZER { pinMode(buzzer, OUTPUT); pinMode(13, OUTPUT); pinMode(inPin, INPUT); } }
void loop() { // HEARTBEAT SENSOR static double oldValue = 0; // used for averaging. static double oldChange = 0; // not currently used int rawValue = analogRead (sensorPin); // This reads in the value from the analog pin. // this is a 10 bit number, and will be between 0 and 1023 // If this value doesn't change, you've connected up // something wrong
unsigned long time2,time1; unsigned long time;
doubleint valuesensorPin = alphaA0; *// oldValueThis +is (1the -analog alpha)sensor *pin rawValue;the //backwards CalculateS anpin averageis usingconnected 75%to
of the
// you can use any of the analog pins, but would need to change this to match
double alpha = 0.75; // This code uses a rather cool way of averaging the values, using 75% of the
// average of the previous valuevalues and 25% of the newcurrent value.
int period = 20; // This is how long the code delays in milliseconds between readings (20 mSec)
int in = 8;
int Reset=6;
int start=7;
int count=0,i=0,k=0,rate=0;
Serial// LCD SCREEN
#include<LiquidCrystal.printh>
LiquidCrystal lcd(rawValue12, 11, 5, 4, 3, 2);
// Send outBIG seriallySOUND theSENSOR
int valuesoundDetectedPin read= in10;
Serial.printint (",");soundDetectedVal = HIGH;
boolean bAlarm = false;
unsigned long lastSoundDetectTime;
int soundAlarmTime = 500;
// SendPUSH aBUTTON commaAND BUZZER
Serial.printlnint (value);buzzer = 3;
int //ledPin Send= out13;
int theinPin average= value7;
int andval a= new0;
#define linesing
oldValue
#define =NOTE_B0 value; 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define melodyPin 3
//Hotline SaveBling theMelody
int averagehotlineb_melody[] for= next{
iteration 0, NOTE_D5, NOTE_D5, NOTE_D5,
delay (period); NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5,
NOTE_E5, NOTE_C5, 0, NOTE_F5,
NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5,
NOTE_C5, NOTE_A4, NOTE_F5, NOTE_E5,
NOTE_D5, NOTE_C5, NOTE_E5, NOTE_C5,
0, NOTE_F5, NOTE_E5, NOTE_D5,
NOTE_C5, NOTE_E5, NOTE_C5, NOTE_A4,
NOTE_F5, NOTE_C6, NOTE_C6,
NOTE_C6, NOTE_A5, NOTE_C6, NOTE_C6,
NOTE_D6, 0, NOTE_F5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, 0, NOTE_C6, NOTE_C6,
NOTE_C6, NOTE_A5, NOTE_C6, NOTE_C6,
NOTE_D6, 0, NOTE_F5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6,
NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6,
NOTE_A5, NOTE_D6, NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5,
NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5,
NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_F5, NOTE_C6, NOTE_A5, NOTE_C6,
NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6,
NOTE_A5, NOTE_D6, NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_G5,
NOTE_A5, NOTE_A5, NOTE_A5, NOTE_A5,
NOTE_AS5, NOTE_A5, NOTE_G5, NOTE_F5,
NOTE_G5, NOTE_G5, NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_A5, NOTE_AS5, NOTE_A5,
NOTE_G5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_G5
};
//HotlineBLING Waittempo
20 mSecint hotlineb_tempo[] = {
if((digitalRead(start)))
{
k=0;
lcd.clear();
lcd.print("Please wait.......");
while(k<5)
{
if(digitalRead(in))
{
if(k==0)
time1=millis();
k++;
while(digitalRead(in));
}
}
time2=millis();
rate=time2-time1;
rate=rate/5;
rate=60000/rate;
lcd.clear();
lcd.print("Heart Beat Rate:");
lcd.setCursor(0,1);
lcd.print(rate);
lcd.print(" ");
lcd.write(1);
k=0;
rate=0;
}
if(!digitalRead(Reset)) {
rate=0;12, 12, 12, 12,
lcd.clear();12, 12, 12, 12,
lcd.print("Heart6, Beat2, Rate:");3, 12,
lcd.setCursor(012, 12, 12, 3,
3, 3, 12, 12,
12, 12, 6, 2,
3, 12, 12, 12,
12, 3, 3, 4,
12, 12, 12,
12, 12, 12, 12,
2, 3, 12, 12,
12, 12, 12, 12,
2, 3, 12, 12,
12, 12, 12, 12,
3, 3, 12, 12,
12, 12, 12, 12,
2, 12, 12, 12,
12, 12, 12, 12,
12, 1);.5, 12, 12,
lcd12, 12, 12, 12,
12, 12, 6, 2,
12, 12, 12, 12,
12, 12, 12, 12,
6, 2, 12, 12,
12, 12, 12, 12,
12, 12, 6, 2.write(1);4,
lcd12, 12, 12, 12,
12, 12, 12, 12,
12, 1.print(rate);5, 12, 12,
k=0;12, 12, 12, 12,
} // LCD SCREEN (helpful hotlines message) { lcd.setCursor(0,1); lcd.clear(); lcd.begin(16,2); lcd.print("1-800-273-8255"); delay(1000); lcd.clear(); lcd.begin(16,2); lcd.print("1-877-726-4727"); delay(1000); } // BIG SOUND SENSOR { soundDetectedVal = digitalRead(soundDetectedPin);
if (soundDetectedVal ==12, LOW12, 6, 2,
12, 12, 12, 12,
12, 12, 12, 12,
6, 2, 12, 12,
12, 12, 12, 12,
12, 12, 8, 24, 2
};
void setup() {
{
lastSoundDetectTime//lcd.createChar(1, =heart);
millis lcd.begin(16,2);
if
lcd.print(!bAlarm"Heart Beat"){;
lcd.write(1);
Seriallcd.printlnsetCursor("you're0,1);
doing greatlcd.print("Monitering");
: pinMode(in, INPUT);
pinMode(Reset, INPUT);
pinMode(start, INPUT);
digitalWrite(Reset, HIGH);
digitalWrite(start, HIGH);
delay(1000);
lcd.begin(16,2);
lcd.print("need to talk?");
delay(1000);
bAlarmlcd.begin(16,2);
= true;lcd.print("not yet satisfied with care?");
}delay(1000);
}
else
{// This code runs on startup, it sets ledPin to output so it can blink the LED that is built into the
// Arduino if(but (millis(then never does)-lastSoundDetectTime, and sets the serial port up for fast 115,200 baud communication
// of the values (make sure you change your serial monitor to match).
> soundAlarmTime
&& bAlarmSerial.begin (115200); // the baud rate of the serial data
{
Serial.printlnbegin("keep breathing"115200);
bAlarmpinMode =(soundDetectedPin, false;INPUT);
}
//PUSH BUTTON AND BUZZER
{
pinMode(buzzer, OUTPUT);
pinMode(13, OUTPUT);
pinMode(inPin, INPUT);
}
}
} // LCD SCREEN (are feeling better/listen to these sick tunes buddy message) { lcd.setCursor(0,1); lcd.clear(); lcd.begin(16,2); lcd.print("if still need comfort"); delay(500); lcd.clear(); lcd.begin(16,2); lcd.print("hold button"); delay(1000); } //PUSH BUTTON AND BUZZER { val = digitalRead(inPin); if (val == HIGH) { digitalWrite(buzzer, LOW); } else { digitalWrite(buzzer, HIGH); } } // BUZZER {{ sing(1); sing(1); sing(2); } int song = 0; void sing(int s) { song = s; if (song == 1) { Serial.println("recognize this?"); int size = sizeof(hotlineb_melody) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { int noteDuration = 1000 / hotlineb_tempo[thisNote];
buzz(melodyPin, hotlineb_melody[thisNote], noteDuration);
void loop() {
int// pauseBetweenNotesHEARTBEAT SENSOR
static double oldValue = noteDuration0; *// 1used for averaging.30;
delaystatic double oldChange = 0; // not currently used
int rawValue = analogRead (pauseBetweenNotessensorPin); // This reads in the value from the analog pin.
// this is a 10 bit number, and will be between 0 and 1023
// If this value doesn't change, you've connected up
// something wrong
unsigned long buzztime2,time1;
unsigned long time;
double value = alpha * oldValue + (melodyPin1 - alpha) * rawValue; // Calculate an average using 75% of the
// previous value and 25% of the new
Serial.print (rawValue); // Send out serially the value read in
Serial.print (","); // Send a comma
Serial.println (value); // Send out the average value and a new line
oldValue = value; // Save the average for next iteration
delay (period); // Wait 20 mSec
if((digitalRead(start)))
{
k=0;
lcd.clear();
lcd.print("Please wait.......");
while(k<5)
{
if(digitalRead(in))
{
if(k==0)
time1=millis();
k++;
while(digitalRead(in));
}
}
time2=millis();
rate=time2-time1;
rate=rate/5;
rate=60000/rate;
lcd.clear();
lcd.print("Heart Beat Rate:");
lcd.setCursor(0,1);
noteDuration lcd.print(rate);
lcd.print(" ");
lcd.write(1);
k=0;
rate=0;
}
if(!digitalRead(Reset))
{
rate=0;
lcd.clear();
lcd.print("Heart Beat Rate:");
lcd.setCursor(0,1);
lcd.write(1);
lcd.print(rate);
k=0;
}
} // LCD SCREEN (helpful hotlines message)
} { void buzz(int targetPin, long frequency, long length) { digitalWrite(13, HIGH); long delayValue = 1000000 / frequency / 2; long numCycles = frequency * length / 1000; for (long i - 0; i < numCycles; i++) { digitalWrite(targetPin, HIGH); delayMicroseconds(delayValue); digitalWrite(targetPin, LOW); delayMicroseconds(delayValue); } digitalWrite(13, LOW);
} {
lcd.setCursor(0,1);
lcd.clear();
lcd.begin(16,2);
lcd.print("1-800-273-8255");
delay(1000);
lcd.clear();
lcd.begin(16,2);
lcd.print("1-877-726-4727");
delay(1000);
}
// BIG SOUND SENSOR
{
soundDetectedVal = digitalRead(soundDetectedPin);
if (soundDetectedVal == LOW)
{
lastSoundDetectTime = millis();
if (!bAlarm){
Serial.println("you're doing great :)");
bAlarm = true;
}
}
else
{
if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm) {
Serial.println("keep breathing");
bAlarm = false;
}
}
}
// LCD SCREEN (are feeling better/listen to these sick tunes buddy message)
{
lcd.setCursor(0,1);
lcd.clear();
lcd.begin(16,2);
lcd.print("if still need comfort");
delay(500);
lcd.clear();
lcd.begin(16,2);
lcd.print("hold button");
delay(1000);
}
//PUSH BUTTON AND BUZZER
{
val = digitalRead(inPin);
if (val == HIGH) {
digitalWrite(buzzer, LOW);
} else {
digitalWrite(buzzer, HIGH);
}
}
// BUZZER
{{
sing(1);
sing(1);
sing(2);
}
int song = 0;
void sing(int s) {
song = s;
if (song == 1) {
Serial.println("recognize this?");
int size = sizeof(hotlineb_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
int noteDuration = 1000 / hotlineb_tempo[thisNote];
buzz(melodyPin, hotlineb_melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
buzz(melodyPin, 0, noteDuration);
}
}
}
{
void buzz(int targetPin, long frequency, long length) {
digitalWrite(13, HIGH);
long delayValue = 1000000 / frequency / 2;
long numCycles = frequency * length / 1000;
for (long i - 0; i < numCycles; i++) {
digitalWrite(targetPin, HIGH);
delayMicroseconds(delayValue);
digitalWrite(targetPin, LOW);
delayMicroseconds(delayValue);
}
digitalWrite(13, LOW);
}
}
}
}
}
}
} } } }