Code does not update LDC display with temperature readings

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi Guys,
I am quite new to Arduino programming and I have written a program that indicates via LED's when a temperature is either above, below on within a set-point temperature range. I am displaying the set-point temperature as "Target" and the real temperature from the sensor as "Actual" on a 16X2 LCD display.
The set-point can vary between 15 and 30 degrees centigrade via a potentiometer.
If the temp is <= set-point + 2 and temp is >= set-point - 2 a green LED will be on
If the temp is < set-point a blue LED will be on
If the temp is > set-point a red LED will be on
Only one LED will be on at any one time.
Now I have constructed this circuit and written the code using Tinkercad and it works with no problems, however I have compiled the program and uploaded it to my Arduino UNO and it does not seem to be working. I am not 100% sure if there are code differences between the two? The display is outputting the written text but the temperatures for "Target" and "Actual" are remaining on 0 (Zero) and not updating.
As I mentioned I am fairly new to programming so I am unsure how to further verify if my program is actually running or if it's stuck.
I have uploaded the Arduino .ino file and a .txt version for a more experienced programmer to have a look at and hopefully point out if I have made an error or advise how I could go about debugging to find the problem.
Regards
Dan
 

Attachments

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi Again,
Not to worry.
I resolved my problem. I just had the display of the temperatures in the wrong section of the program.
All resolved now.

Regards
Dan
 

Wolframore

Joined Jan 21, 2019
2,609
You should have posted in the “self help” section. Sometimes it helps to organize your thoughts by discussing.

Use code tags next time and just post it to the forum. Zip files makes looking a little harder.

It’s good practice to put serial output commands in your codes. By using you COM port you can watch the sketch run and it will give you a clue as to what’s working and what is not.
 

spinnaker

Joined Oct 29, 2009
7,830
You should have posted in the “self help” section. Sometimes it helps to organize your thoughts by discussing.

Use code tags next time and just post it to the forum. Zip files makes looking a little harder.

It’s good practice to put serial output commands in your codes. By using you COM port you can watch the sketch run and it will give you a clue as to what’s working and what is not.

And breaking the problem down into smaller pieces. I.E. If nothing is displaying forget about the temperature and just get something to display.
 

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi Wolframore,
Thanks for the reply. Yes the suggestion with regards to outputting to the serial port is a good one, I will definitely take that on board.
But could you please explain what you mean by using code tags. I'm unsure about that.

Regards
Dan
 

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi Again,
Please forgive me, but am I correct in saying that I would place the code that I was posting within the [ ] ?
Just want to be absolutely sure.

Regards
Dan
 

Wolframore

Joined Jan 21, 2019
2,609
it's called BBS tags... kind of like HTML... there are a number of tags that let you put in different functionality in forums... out of all the forums I've seen all about circuits has one of the best, most of it is automated.

typing his give you below:

code.jpg

Code:
/your code here
 

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi,
So what interface do I use to add my code into these code blocks? I assume I don't just put it in here.

Regards
Dan
 

bertus

Joined Apr 5, 2008
22,270
Hello,

Here is the posted code in the txt file from the zip file:

C:
/*
  LiquidCrystal Library

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>             

float tempSen = A0;            //Data type allocation for variables
int potWiper = A1;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  //Initialize the library with the numbers of the LCD interface pins

void setup() {
   
  lcd.begin(16, 2);            //Set up the LCD's number of columns and rows:
  pinMode(tempSen, INPUT);  //Sets analog A0 as input
  pinMode(potWiper, INPUT);  //Sets analog A1 as input
  pinMode(8, OUTPUT);  //Sets digital pin 8 as an output
  pinMode(9, OUTPUT);  //Sets digital pin 9 as an output
  pinMode(10, OUTPUT);  //Sets digital pin 10 as an output
  lcd.clear();
 
}

void loop() {
 
  int readVal, newSptemp, newTemp;
  float temp, spTemp;
   
  lcd.setCursor(0,0);  // set the cursor to column 0, line 0
  lcd.print("Target:  deg C ");   
  lcd.setCursor(8,0);
  lcd.print(spTemp, 0);  // Print the setpoint temp
   
  lcd.setCursor(0,1);  // set the cursor to column 0, line 1
  lcd.print("Actual:  deg C ");   
  lcd.setCursor(8,1);
  lcd.print(temp, 0);  // Print the temperature sensor temp
 
  readVal = analogRead(tempSen);  //Reads the raw value of temp sensor TMP36
  temp = scalAnalog(readVal,0.5,1.55/165);  //Operation to scale temperature sensor TMP36
 
  readVal = analogRead(potWiper);  //Reads the raw value of potentiometer
  spTemp = scalAnalog(readVal,-5.0,5.0/15);  //Operation to scale 15 to 30 degrees for set point control
 
  newSptemp = Round(spTemp);  //Rounded set-point temperature == See function below
  newTemp = Round(temp);  //Rounded temperature sensor == See function below
 
  delay(5000);  //Measure setpoint and temp sensor every 5 seconds
 
  if (newTemp <= newSptemp + 2 && newTemp >= newSptemp - 2){ //Test to check if temp is +- 2 degrees of set point
  digitalWrite(8, LOW);            //If temp is between this range system is healthy
  digitalWrite(9, HIGH);          //Turn on Green status LED
  digitalWrite(10, LOW);
  }
  else if (newTemp < newSptemp - 2){        //Test to check if temp is 2 degrees below set point
  digitalWrite(8, LOW);            //If temp is below this range the temp is too cold
  digitalWrite(9, LOW);              //Turn on Blue status LED
  digitalWrite(10, HIGH);
  }
  else if (newTemp > newSptemp + 2){        //Test to check if temp is 2 degrees above set point
  digitalWrite(8, HIGH);          //If temp is above this range the temp is too hot
  digitalWrite(9, LOW);            //Turn on Red status LED
  digitalWrite(10, LOW);
  }   
 
}
  //Function written by Daniel Lardner 11/05/2019
  //This function has been written to covert the raw potentiometer value into a scaled voltage
  //This scaled voltage is then used to calculate a scaled temperature
 
  float scalAnalog(int raw, float offset, float gradient)
  {
  float scalVolt, scalTemp;
  scalVolt = float(raw) * 5/1024;        //Operation to obtain scaled input voltage
  scalTemp = (scalVolt - offset) / gradient;  //Operation to obtain scaled temperature
  return (scalTemp);
  }
  //Function written by Daniel Lardner 11/05/2019
  //This function has been written to round the floating point temperatures
  //This is for the LED outputs only being being turned on/off at the correct temperatures   
   
  int Round(float num)
  {
  int Rounded;
  Rounded = num + 0.5;
  return (Rounded);
  }
Bertus
 
Type exactly what you see below to the "-----" mark. You can Preview and see what happens. I killed the effects of the tag in this post.

[code]

/your code here

[/code]

-----

Another example: Instead if using the interface, you can do bold by tags as well:

You type:
[b]this will be in bold[/b]
and this

this will be in bold

appears

it's known as BBcode.
 

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi,
Ok I think I get it. So I would just use my same interface that I am using to write my code such as the Arduino IDE and I would just put
Code:
 at the start and
at the end and copy and paste it into a post? As you said the HTML side of things would take care of the rest.
 

Thread Starter

Danlar81

Joined Apr 19, 2019
87
Hi Guys,
Yes I see now. My last post probably doesn't make sense but I fully understand it now.
Thank you for being patient with me.
I will use code tags when posting in the future.
Thanks for helping me understand.

Regards
DAn
 

bertus

Joined Apr 5, 2008
22,270
Hello,

Remember that bold and italic do not work inside code tags.
You can use the language to enhance the code.
Here is an example with a piece of your code:

[code=c]
void setup() {

lcd.begin(16, 2); //Set up the LCD's number of columns and rows:
pinMode(tempSen, INPUT); //Sets analog A0 as input
pinMode(potWiper, INPUT); //Sets analog A1 as input
pinMode(8, OUTPUT); //Sets digital pin 8 as an output
pinMode(9, OUTPUT); //Sets digital pin 9 as an output
pinMode(10, OUTPUT); //Sets digital pin 10 as an output
lcd.clear();

}[/code]


This will result in:
C:
void setup() {
   
  lcd.begin(16, 2);            //Set up the LCD's number of columns and rows:
  pinMode(tempSen, INPUT);  //Sets analog A0 as input
  pinMode(potWiper, INPUT);  //Sets analog A1 as input
  pinMode(8, OUTPUT);  //Sets digital pin 8 as an output
  pinMode(9, OUTPUT);  //Sets digital pin 9 as an output
  pinMode(10, OUTPUT);  //Sets digital pin 10 as an output
  lcd.clear();

}
Bertus
 
Top