Hi,
I'm quite new to Arduino and I'm making a vital signs monitor for my final project using Arduino Uno. I will only be using a temp sensor LM35 and Heart rate sensor KY039 whose values I am displaying on an lcd display (16x2). The code compiles and uploads once I set my project up. However nothing appears on my LCD screen. It only lights up. I have also connected a push button that lights the LCD on and off.
Here is the code with explanations
/* This is the sketch for a vital signs monitor intended to senses temperature and heart rate*/
#include <LiquidCrystal.h> //Include LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Connections to arduino pins
/*define*/
int HBSensor = 8; //the heart beat sensor is connected to pin 8 of arduino uno
int HBCount = 0;
int HBCheck = 0;
int TimeinSec = 0;
int HBperMin = 0;
int HBStart = 6; //button is connected to pin 6 on arduino
int tempPin = A1;
int TEMPERATURE = 0;
int val;
int LED = 7;// LED connected on this output pin
int run;//for pushbutton
int buttonPin;
float cel;//temperature celsius
/* void setup*/
void setup()
{
/*temp setup*/
Serial.begin(9600);
/*lcd setup*/
lcd.begin(16, 2);// lcd display is type 16x2
run = 0; //starts stopped pushbutton
buttonPin = 6 ; //whatever pin your button is plugged into
pinMode(HBSensor, INPUT); //heartbeat sensor
pinMode(HBStart, INPUT_PULLUP);
pinMode (tempPin,INPUT); //temperature sensor
pinMode (LED,OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);//for pushbutton
lcd.clear();//resets LCD display
lcd.setCursor(0,0);
lcd.print("Current HB : "); //will display the current hb
lcd.setCursor(0,1);
lcd.print("HB per Min : 0.0");
lcd.setCursor(0,2);
lcd.print("Current Temp : "); //will display the current temperature reading
lcd.print (TEMPERATURE);
lcd.print ("C");
delay(3000);
}
void loop()
//multiple loops so i gave them different names
{
pushbutton();
heartrate();
temp();
}
void pushbutton ()
//void loop 1 for pushbutton
{
if(run == 0)
{
run = 255;
}
else
{
run = 0;
}
if(run > 0)
{
//code you only run if button was pressed, stops running when button pressed again, so forth...
}
}
//void loop 2 for heartbeat
void heartrate ()
{
HBCount = HBCount + 1;
HBCheck = 1;
lcd.display ();
lcd.setCursor(14,0);// set cursor to this position on lcd
lcd.print(HBCount);
lcd.print(" ");
if((digitalRead(HBSensor) == LOW) && (HBCheck == 1))
{
HBCheck = 0;
}
if(TimeinSec == 10)
{
HBperMin = HBCount * 6; //10 seconds is multiplied by 6 to make one minute ie 60 secs
lcd.setCursor(14,1);
lcd.print(HBperMin);
lcd.print(" ");
lcd.setCursor(14,2);
lcd.print (TEMPERATURE);
lcd.print ("*C");
lcd.setCursor(0,2);
lcd.print("Press Button again.");
Serial.print("TEMPERATURE = ");
Serial.print ("C");
Serial.println("");
Serial.print("HBperMin = ");
Serial.println();
//
HBCount = 0;
TimeinSec = 0;
}
}
//void loop 3 for temperature sensor
void temp ()
{
val = analogRead(tempPin);//READ THE A1 PIN
float mv = ( val/1024.0)*5000; //MANIPULATE THE VALUE
float cel = mv/10;//DIVIDE BY 10
if(cel >= 39)
{
//blinks at 5ms intervals for 10 seconds when temperature is higher than 39
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
digitalWrite(LED, LOW);
if(cel <= 39)
{
digitalWrite(LED,LOW); //switch LED off
}
}
