LCD Code not working

Im trying to display the temperature,Light and Humidy on a lcd.
Problem is whenever i tr to call the function it says it is already declared or not declared.
Please help me…

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 8; 
int sw_state = 0; 
int no_of_switch_presses =0; 
int val;
int old_val=0;
float temp,hum,light;

void setup() {
  
  lcd.begin(0,2);
  lcd.setCursor(0,0);
  pinMode(switchPin,INPUT); 
}
void loop() {
  
   val = digitalRead(switchPin); 
    if ((val == LOW) && (old_val ==HIGH)) {
    no_of_switch_presses = no_of_switch_presses +1;
   delay(50); 
    }
    old_val = val; 
    switch(no_of_switch_presses){
      
      case 0:
            lcd.setCursor(0,0);
            lcd.print("Welcome ");
            delay(200);
      
      break;
    
      case 1: 
      temp();
            lcd.setCursor(0,0);
            lcd.print("Temp    ");
            delay(200);
      
      break;
      
      case 2:
      hum();
            lcd.setCursor(0,0);
            lcd.print("Humidity");
            delay(200);
      break;
      
      case 3:
      ligh();
             lcd.setCursor(0,0);
            lcd.print("Light   ");
      
      break;
      
      default:
      no_of_switch_presses = 0;
    
    }
    }
void temp();
{
  float R=4700;
  float ADC;
  float BETA=3950;
  float RO=5000;
  float TO=298.15
  ADC = analogRead(A0);
  float T,RT;
  float A,B;

  A=(R*ADC);
  B=(1023-ADC);
  RT=A/B;

  T=1/((1/T0)+(1/BETA)*log(RT/R0));
  TC=T-273.15;

  if(TC>27.0)
  {
    analogWrite(fan,255);
  }
  else
  {
    analogWrite(fan,0);
  }
}

void hum();
{
  float HRmin = 20;
  float RHmin = 1.1;
  float HV;
  float Rhumidity;
  
  HV=HRmin*exp(1.88816351 - (0.18625752*log(Rhumidity/RHmin)));
    
  }
  
 void light()
{
  float V;
  float constant = 1333.0;
  ADC = analogWrite(A2);
  V=ADC*5.0/1023;
  Lux_Val=V*constant;
}
  delay(3000);
}
}

Hi Andre Rieu.

Nice to see you over here, didn't expect you would be interested in this stuff too ;).

Please in future try to create a more descriptive title. You won't believe how many "LCD code not working" threads were created already. While you're trying to do something with a LCD, your problem (hinted by the compiler's messages) has no relation to the LCD.

There seems to be a lot of problems with your code. You are declaring global floats, but those aren't floats at all in the rest of your code. Instead they are functions. Functions shouldn't be declared like that. Next, you seem to be inconsistent with {} and ; Once you have cleaned that up, you'll get even more error messages (because the compiler now knows those are functions and tries to handle them). Those errors also are related to incomplete or incorrect declarations.

 ADC = analogWrite(A2);

This means put the result of the analog write to A0 with nothing into variable ADC. You can't instruct to write nothing to some analog pin, so that will generate an error. But i'm sure that is not what you intended to do. Did you instead mean something like this perhaps :

 analogWrite(A2, ADC);

?

I could go on for a while. But i think you should take baby steps, so first try to solve the typos and the {} and ; mistakes, there are a few of each of those.

Read the error messages. They contain hints to the exact location where a problem was found:

sketch_mar24a.ino:10:16: error: 'float light' redeclared as different kind of symbol

This means the problem was found on line 10 and position 16, followed by a (somewhat cryptic) description of the problem. That's a great help to find out what's wrong.

Try to fix some of the mentioned issues, and post your new code to have it checked out.

It looks like there are some curly brace issues which can create all kinds of phantom errors.

ok so i got it working, but im getting like 300 degrees shown on my LCD, and exaggerated values for light and humidity, what would be the problem ?

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 8; 
int sw_state = 0; 
int no_of_switch_presses =0; 
int val;
int old_val=0;


void setup() {
  
  lcd.begin(0,2);
  lcd.setCursor(0,0);
  pinMode(switchPin,INPUT); 
}
void loop() {
  
   val = digitalRead(switchPin); 
    if ((val == LOW) && (old_val ==HIGH)) {
    no_of_switch_presses = no_of_switch_presses +1;
   delay(50); 
    }
    old_val = val; 
    switch(no_of_switch_presses){
      
      case 0:
            lcd.setCursor(0,0);
            lcd.print("Welcome ");
            delay(200);
      
      break;
    
      case 1: 
      temp();
            lcd.setCursor(0,0);
            lcd.print("Temp=");
            lcd.print((long)temp);
            delay(200);
      
      break;
      
      case 2:
      hum();
            lcd.setCursor(0,0);
            lcd.print("Hum=");
            lcd.print((long)hum);
            delay(200);
      break;
      
      case 3:
      light();
             lcd.setCursor(0,0);
            lcd.print("Light=");
            lcd.print((long)light);
      
      break;
      
      default:
      no_of_switch_presses = 0;
    
    }
    }
    
    
void temp()
{
  float R=4700;
  float ADC;
  float BETA=3950;
  float RO=5000;
  float TO=298.15;
  ADC = analogRead(A0);
  float T,RT,TC;
  float A,B;

  A=(R*ADC);
  B=(1023-ADC);
  RT=A/B;

  T=1/((1/TO)+(1/BETA)*log(RT/RO));
  TC=T-273.15;
  lcd.print((float)TC);

 // if(TC>27.0)
//  {
//    analogWrite(fan,255);
//  }
 // else
//  {
 //   analogWrite(fan,0);
 // }
}

void hum()
{
  float HRmin = 20;
  float RHmin = 1.1;
  float HV;
  float Rhumidity;
  
  HV=HRmin*exp(1.88816351 - (0.18625752*log(Rhumidity/RHmin)));
   lcd.print((float)HV);
    
  }
  
 void light()
{
  float V,Lux_Val;
  float constant = 1333.0;
  analogWrite(A2, ADC);
  V=ADC*5.0/1023;
  Lux_Val=V*constant;
  lcd.print((float)Lux_Val);
}

You seem to be converting floats to longs. A long is an int, a float can't be an int.

You have variables and functions using the same names.

float temp,hum,light;

Is declaring variables by those names and then later you have functions by those very same names.

This will cause problems and not work.

--- bill

Ok so i fixed those problems :smiley:

Getting value 0.00 for Light and Humidity and my temperature hovers around 30 degrees (works)

What would be the problem ?

#include <LiquidCrystal.h>
#include <math.h>

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

const int switchPin = 8; 
int sw_state = 0; 
int no_of_switch_presses =0; 
int val;
int old_val=0;
int LED= 13;
float TC;
float V;
float HV;

void setup() {
  
  lcd.begin(8,2);
  lcd.setCursor(0,0);
  pinMode(LED,INPUT);
  pinMode(6,INPUT);
}
void loop() {
  
   val = digitalRead(switchPin); 
    if ((val == LOW) && (old_val ==HIGH)) {
    no_of_switch_presses = no_of_switch_presses +1;
   delay(50); 
    }
    
    old_val = val; 
    digitalWrite(LED,HIGH);
    switch(no_of_switch_presses){
      
      case 0:
            lcd.setCursor(0,0);
            lcd.print("Welcome    ");
            lcd.setCursor(0,1);
            lcd.print("User    ");
            delay(100);
   
      break;
    
      case 1: 
      temperature();
            lcd.setCursor(0,0);
            lcd.print("Temp=    ");
            lcd.setCursor(0,1);
            lcd.print(TC);
            lcd.setCursor(5,1);
            lcd.print("C");
            delay(200);
      
      break;
      
      case 2:
      humidity();
            lcd.setCursor(0,0);
            lcd.print("Hum=   ");
             lcd.setCursor(0,1);
            lcd.print(HV);
            lcd.setCursor(5,1);
              lcd.print("B");
            delay(200);
      break;
      
      case 3:
      lighting();
             lcd.setCursor(0,0);
            lcd.print("Light=   ");
            lcd.print(V);
             lcd.setCursor(5,1);
             lcd.print("D");
      
      break;
      
      default:
      no_of_switch_presses = 0;
    
    }
    }
    
    
void temperature(void)
{
  float R=10000;
  float ADC;
  float BETA=3950;
  float TO=298.15;
  float T,RT;
  float A,B;

  ADC = analogRead(A0);

  RT= ((R*ADC) / (1023-ADC));
  T = 1/((1/TO)+(1/BETA)*log(RT/R));
  TC = T-273.15;

  if(TC > 1.0)
  {
    digitalWrite(6,HIGH);
  }
  else
 {
    digitalWrite(6,LOW);
 }
}

void humidity(void)
{
  float HRmin = 20;
  float RHmin = 1.1;
  float HV;
  float Rhumidity;
  
  HV=HRmin*exp(1.88816351 - (0.18625752*log(Rhumidity/RHmin)));
   
  }
  
 void lighting(void)
{
  float V;
  float constant = 1333.0;
  float ADC_2;
  ADC_2 = analogRead(A2);
  
  V=((ADC_2*5.0) / (1023*constant));
}

You are creating global declares of variables V and HV. Then you are also declaring new variables with those very same names inside your functions. I´m surprised the IDE doesn´t complain about that, but is doesn´t. But it still can´t work that way. You didn´t do this with TC for temperature, and you say that works, so...