Lcd.print not printing

I'm using an Arduino Uno.

It doesn't print to my lcd. I have changed LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
to "LiquidCrystal lcd(9, 8, 7, 6, 5, 4);" which works in my other programs with the 1602 keypad shield I'm using.
Here is the lcd.print code.

Thanks for Looking, Douger

lcd.setCursor(0, 0);
lcd.print("Temperature ");
lcd.print (temperature);

And the whole program, probably needed.

//From https://www.electroschematics.com/arduino-temperature-controlled-relay/
 //Now modified MK
#include <LiquidCrystal.h>
int reading = 0;
#define sensorPin A5
int celsius;
int fahrenheit; //= ((celsius * 9) / 5 + 32);   //I added
//float voltage = reading * (5000 / 1024.0);
int relay =11;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int tempC;

void setup() {
// set up the LCD's number of columns and rows: 
lcd.begin(16, 2);
pinMode(relay,OUTPUT);
// Print a message to the LCD.

}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
int reading = analogRead(sensorPin);
fahrenheit = ((celsius * 9) / 5 + 32)*1.0095; // Convert to fahrenheit  I added
float voltage = reading * (5000 / 1024.0);
float tempC = voltage / 10;
float temperature = ((tempC * 9) / 5 + 32);
lcd.setCursor(0, 0);
lcd.print("Temperature ");
lcd.print (temperature);

if (temperature < 81)  // TURN ON heater
{
digitalWrite (11,HIGH); 

}
else

{digitalWrite(11,LOW);
}
delay(500);
}

Have you tried running the LCD library example sketches?

Where is 'celsius' assigned any value?

Beginner, so I don't know what that means.
However I found the order of the numbers here was wrong,
LiquidCrystal lcd(9, 8, 7, 6, 5, 4); should be LiquidCrystal lcd(8, 9, 4, 5, 6, 7)

So the program now does as expected.
Thanks, Douger

...unless you expected

fahrenheit = ((celsius * 9) / 5 + 32)*1.0095; // Convert to fahrenhei

to do anything at all...

Ya, no, that line was later removed :slight_smile:
I got the heater controller working well, then last night my son got involved and started whipping out code to use the 1602 Keypad Shield buttons, using the select button to select between "Set temperature", "Set watering Schedule", and Watering on Time" and using the up/ down buttons to set those. He did in 4 hrs what would have taken me weeks. Little bit more work on the code and then I'll get into the mechanical design of a Bean Sprout Grower.
Douger

Sounds like your son has some talent.

Very surprising because he only started working with an Arduino about 3 weeks ago.
He has no previous coding experience, but he is good with Excel.
We need to add some hystesis to the heater control, the relay goes on/off, on/off several times right near the set-point. Any ideas?
Thanks, Douger

Why is hysteresis a problem? The logic is brutally simple:

if reading > high set point
{ turn off heat }
if reading < low set point
{ turn on heat }

Your code does not have hysteresis in it. Hysteresis code has been put in and it solved the problem.
Thanks, Douger

I beg to differ. What I posted is canonical hysteresis. I'm entirely mystified why you would say something like that. If you think I made a mistake, please enlighten me so I don't spend the rest of my life in ignorance.

If you found a solution, great, please post it for the benefit of future readers...

OK, I am a beginner, but that code causes my led/relay to click on and off 2 or 3 times every time the temperature was going through the transition up. Down was better behaved.
This was using a LM35, Adding this code for hysteresis made it operate properly.

// Turns heater off if temperature reaches SetPoint, TempM is for the hysteresis.  tempM=1

if ( temperature >= (setPoint +tempM)){
  digitalWrite(12, LOW);
}
if ( temperature <= (setPoint+tempM)){
  digitalWrite(12, HIGH);

I have since changed to a DS18B20 Sensor and found the hysteresis is not needed so I removed the hysteresis code.
Douger

That code is incorrect. You only calculate one end of the hysteresis range, because you added it in both cases. Thus you have a range (dead zone) of zero, and there is no hysteresis. In order to create a range, you have to both add and subtract 1/2 the range, like:

// Turns heater off if temperature reaches SetPoint, TempM is for the hysteresis.  tempM=1

if ( temperature >= setPoint + tempM) {
  digitalWrite(12, LOW);
}
if ( temperature <= setPoint - tempM) {
  digitalWrite(12, HIGH);

The reason you may not need it with the DS18B20 is that it is very slow. Your relay will still "chatter", just so slowly that you would normally not notice.

I am posting this correction for the benefit of other people who might find this thread.

Ya, I no longer had that code, I removed it after testing with the DS18B20. I rewrote it from memory, yup, I got the negative sign wrong when I rewrote it.
Douger