16X2 LCD DISPLAY INTERFACED WITH ARDUINO UNO NOT DISPLAYING VALUES

Hi,
I'm quite new to Arduino and I'm making a vital signs monitor for my final project. I will only be using a temp sensor and Heart rate sensor whose values I am displaying on an lcd display. The code compiles and uploads once I set my project up. However nothing appears on my LCD screen. It only lights up.

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
}

}

Does the LCD work with any of the examples that come with the library? I mean, does the LCD work in a sketch by itself.

Please read the "how to use the forum-please read" stickies to see how to properly post code. See #7 (and 11).

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
  }


 
}

First thing - have you tried a simple test program to write something to the LCD? That would prove that it's wired up correctly, properly powered and the contrast is set correctly. If not, get that working first.

And then your code:
Why is pin6 named both buttonPin and HBStart?

Why do you keep printing TEMPERATURE to the LCD when you never set that variable to any value other than the default 0?

What is pushbutton() supposed to do? If run is 0 set it to 255 and then if run > 0 do nothing. What your code doesn't ever do is read a pushbutton.

Your 10 times blinking LED is one thing that should use a loop. Have a look at the "for" loop, it's very useful for doing the same thing several times.

Steve

 lcd.begin(16, 2);// lcd display is type 16x2
  lcd.setCursor(0,2);

One of these is wrong, for starters.

This appears to be the classic problem of not having a contrast potentiometer connected.
Usually 10K with the wiper to pin 3 (marked VO) and the other 2 pins between 0v and Vcc.
But find an example on line which matches your display markings.

He appears to have cross posted:

http://forum.arduino.cc/index.php?topic=544630.0

slipstick:
First thing - have you tried a simple test program to write something to the LCD? That would prove that it's wired up correctly, properly powered and the contrast is set correctly. If not, get that working first.

And then your code:
Why is pin6 named both buttonPin and HBStart?

Why do you keep printing TEMPERATURE to the LCD when you never set that variable to any value other than the default 0?

What is pushbutton() supposed to do? If run is 0 set it to 255 and then if run > 0 do nothing. What your code doesn't ever do is read a pushbutton.

Your 10 times blinking LED is one thing that should use a loop. Have a look at the "for" loop, it's very useful for doing the same thing several times.

Steve

Hi,
I hadn't realised that I had given the pin two names. The push button was intended to start the heart rate sensor. And I don't understand the temperature question (I'm still figuring things out so maybe you could tell me how to correct that part)

6v6gt:
He appears to have cross posted:

[MERGED] 16X2 LCD DISPLAY INTERFACED WITH ARDUINO UNO NOT DISPLAYING VALUES - Project Guidance - Arduino Forum

Because I hadn't followed the guidelines in this post.

CRYSTALBALL:
Because I hadn't followed the guidelines in this post.

The solution is for you to report one of the posts to a moderator (using the report button) and ask for the threads to be merged to avoid different people giving similar answers on the same subject in different threads.

wvmarle:

 lcd.begin(16, 2);// lcd display is type 16x2

lcd.setCursor(0,2);




One of these is wrong, for starters.

What's wrong with the statement? The position of the cursor?

CRYSTALBALL:
What's wrong with the statement? The position of the cursor?

Remember that indices start at 0.

You say you have a 16x2 display, then try to print on the third line (you also have statements that print on lines 0 and 1).

wvmarle:
You say you have a 16x2 display, then try to print on the third line (you also have statements that print on lines 0 and 1).

I got that from an LCD code on the internet. My understanding of it was that

lcd.setCursor(0,0); //not sure

lcd.setCursor(0,1); //will display at the beginning of the 1st row

lcd.setCursor(0,2);//will display at the beginning of line 2/row 2

Is this wrong? I'm confused.

You have to lines on a 1602 display: line 0 and line 1. And 16 columns: 0 to 15.

The fact that there are three lines should have set off alarm bells. NEVER blindly trust code you get "on the Internet" (libraries tend to be quite OK, especially if referenced to from different sources), always check it carefully and make sure you understand every single line. Look up commands that you don't know.

wvmarle:
You have to lines on a 1602 display: line 0 and line 1. And 16 columns: 0 to 15.

The fact that there are three lines should have set off alarm bells. NEVER blindly trust code you get "on the Internet" (libraries tend to be quite OK, especially if referenced to from different sources), always check it carefully and make sure you understand every single line. Look up commands that you don't know.

Thanks I added the 10K potentiometer and have at least got somewhere.