Temperature with leds, code not working

Hi, I am having a whole lot of trouble trying to make my school-project work. I found this tinkercad online and I thought I might use it as a form of "base" however I have trouble adding the LED RGB code to the LCD code, I don't know how to combine them, can somebody please help?

Tinkercad links aren't acceptable here. Please post your code inline in a post, as explained in the sticky threads at the top of the forum.

Why make it such a pain to help you? I will not create a Tinkercad account just to see your project.

Post your code here. Post a schematic here. Describe the problems that you are having.

We want to help you.

It appears as if you didn’t fully read the forum instructions. Please edit your post to add code tags around your code. Before you do, please also remove useless blank lines and format the code in the IDE using .

Also, you never explained what your “trouble” with the program is. What is the problem?

You cannot have 2 setup() functions and 2 loop() functions.

Combining codes tutorial.

Another combine codes tutorial.

aarg:
It appears as if you didn’t fully read the forum instructions. Please edit your post to add code tags around your code. Before you do, please also remove useless blank lines and format the code in the IDE using .

Also, you never explained what your “trouble” with the program is. What is the problem?

I am so sorry, my english is not the best, but I’ve read through it again. Hopefully I get it right this time :slight_smile:

</>

#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//This is the Arduino Pin that will read the sensor output.

int sensePin = A0;

//The variable we will use to store the sensor input.

int sensorInput;

//The variable we will use to store temperature in degrees.

double temp;

void setup()

{

//Initialize the LCD’s number of columns and rows.

lcd.begin(16, 2);

//Start the Serial Port at 9600 baud (default).

Serial.begin(9600);

}

void loop()

{

//Set the cursor to column 0, line 0

lcd.setCursor(0, 0);

//Read the analog sensor and store it.

sensorInput = analogRead(A0);

//Find percentage of input reading.

temp = (double)sensorInput / 1024;

//Multiply by 5V to get voltage.

temp = temp * 5;

//Subtract the offset.

temp = temp - 0.5;

//Convert to degrees.

temp = temp * 100;

}

int Temp = 0;

void setup()

{

pinMode(11, OUTPUT);

pinMode(10, OUTPUT);

pinMode(9, OUTPUT);

pinMode(A0, INPUT);

}

void loop()

{

analogWrite(11, 51);

analogWrite(10, 255);

analogWrite(9, 51);

Temp = -40 + 0.488155 * (analogRead(A0) - 20);

if (Temp >= 50) {

analogWrite(11, 255);

analogWrite(10, 0);

analogWrite(9, 0);

}

if (Temp >= 30) {

analogWrite(11, 255);

analogWrite(10, 204);

analogWrite(9, 0);

}

if (Temp <= 10) {

analogWrite(11, 102);

analogWrite(10, 255);

analogWrite(9, 255);

}

delay(10); // Delay a little bit to improve simulation performance

lcd.print("Temperature: ");

//Set the cursor to column 0, line 1

lcd.setCursor(0, 1);

lcd.print(temp);

lcd.print(" Celsius");

}

WTF? How in the world do you interpret the forum guidelines to say to post code like that. Have you looked at even one other thread?

Posting using code tags (assuming that you are actually reading the links provided).

Hopefully I get it right this time

What exactly did you do ?
Did you not notice when you previewed your reply that it looked odd ?

//Include the library code.
#include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//This is the Arduino Pin that will read the sensor output.
int sensePin = A0;
//The variable we will use to store the sensor input.
int sensorInput;
//The variable we will use to store temperature in degrees.
double temp;

void setup()
{
  //Pin of the led.
  pinMode(13, OUTPUT);
  
  //Initialize the LCD's number of columns and rows.
  lcd.begin(16, 2);
  
  //Start the Serial Port at 9600 baud (default).
  Serial.begin(9600);
}

void loop()
{  
  //Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  
  //Read the analog sensor and store it.
  sensorInput = analogRead(A0);
  //Find percentage of input reading.
  temp = (double)sensorInput / 1024;
  //Multiply by 5V to get voltage.
  temp = temp * 5;
  //Subtract the offset.
  temp = temp - 0.5;
  //Convert to degrees.
  temp = temp * 100;
  }  

  lcd.print("Temperature: ");
  
  //Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print(temp);
  
  lcd.print(" Celsius");

}

Dammit I got it wrong again: this must be right

All right! That is much better.

See the comment.

  //Subtract the offset.
  temp = temp - 0.5;
  //Convert to degrees.
  temp = temp * 100;
}  ****** curly bracket in the wrong place closes loop() early

  lcd.print("Temperature: ");
  
  //Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);

If you use the IDE autoformat tool (ctrl-t or Tools, Auto Format) the error would stand out.

Wait! I didn’t get the full code:

  #include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//This is the Arduino Pin that will read the sensor output.
int sensePin = A0;
//The variable we will use to store the sensor input.
int sensorInput;
//The variable we will use to store temperature in degrees.
double temp;

int Temp = 0;

void setup()
{
  //Initialize the LCD's number of columns and rows.
  lcd.begin(16, 2);
  
  //Start the Serial Port at 9600 baud (default).
  Serial.begin(9600);
  
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(A0, INPUT);
}

void loop()
{  
  //Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  
  //Read the analog sensor and store it.
  sensorInput = analogRead(A0);
  //Find percentage of input reading.
  temp = (double)sensorInput / 1024;
  //Multiply by 5V to get voltage.
  temp = temp * 5;
  //Subtract the offset.
  temp = temp - 0.5;
  //Convert to degrees.
  temp = temp * 100;
  
  {
  analogWrite(11, 51);
  analogWrite(10, 255);
  analogWrite(9, 51);
  Temp = -40 + 0.488155 * (analogRead(A0) - 20);
  if (Temp >= 50) {
    analogWrite(11, 255);
    analogWrite(10, 0);
    analogWrite(9, 0);
  }
  if (Temp >= 30) {
    analogWrite(11, 255);
    analogWrite(10, 204);
    analogWrite(9, 0);
  }
  if (Temp <= 10) {
    analogWrite(11, 102);
    analogWrite(10, 255);
    analogWrite(9, 255);

  lcd.print("Temperatur: ");
    
  //Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print(temp);
  
  lcd.print(" Celsius");
    }

Looks good except 2 missing closing curly brackets (}) at the end. It compiles, does it do what you want?

You are updating the display every time through loop(). That can lead to display flicker. Consider updating less often or updating only when the data changes.

Use the millis() function for timing, not delay().
Non-blocking timing tutorials:
Several things at a time.
Beginner's guide to millis().
Blink without delay().