2 sensors over-ride eachother

so im trying to make an lcd display both temperature and light level (to just generally learn how to use an arduino) and everything has been going smoothly till now.
I've been able to get the photocell to output onto the LCD accurately, and same with the temperature sensor, however when i try to combine the two it does not work. if i shine light on the photocell it will say the temperature is 40c when the temperature in the room is only about 20c, and when i cover the photocell the temp drops down to around 18. When i cover the photocell and put my fingers over the temp sensor it slowly goes up (as it should), so clearly both of them are working correctly but will not work in unison.

#include <LiquidCrystal.h>


int lcdRSPin = 12;
int lcdEPin = 11;
int lcdD4Pin = 5;
int lcdD5Pin = 4;
int lcdD6Pin = 3;
int lcdD7Pin = 2;
const int sensorMin = 0;
const int sensorMax = 800;
int photocellPin = A2;
int lm35Pin = A0;
LiquidCrystal lcd(lcdRSPin, lcdEPin,
                  lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin);
void setup()
{
 
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
  float temperature;
  int tempValue;
  tempValue = analogRead(lm35Pin);
  temperature = float(tempValue) / 1023;
  temperature = temperature * 500;
  Serial.print("Temp: ");
  Serial.print(temperature);
  Serial.println("C");
  lcd.begin(16, 2);
  lcd.print("Live Temp ");
  lcd.print(temperature);
  lcd.print("c");



  int lightvalue;
  int range;
  lightvalue = analogRead(photocellPin);
  range = map(lightvalue, sensorMin, sensorMax, 0, 3);
  switch (range)
  {
    case 0:
      Serial.println("dark");
      break;
    case 1:
      Serial.println("dim");
      break;
    case 2:
      Serial.println("medium");
      break;
    case 3:
      Serial.println("bright");
      break;
  }
  delay(250);
  lcd.setCursor(0, 1);
  lcd.print("Light ");
  switch (range)
  {
    case 0:
      lcd.print("dark     ");
      break;
    case 1:
      lcd.print("dim     ");
      break;
    case 2:
      lcd.print("medium");
      break;
    case 3:
      lcd.print("bright   ");
      break;
  }
}

ive been trying to split up the code by using the #include command but i cant really figure out how to make that work.
Im still pretty new so give me anything.

Welcome to the group.

Show us a good schematic of your proposed circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.

Try using

and

In other words read the analogue input twice.
If it works I will tell you why.
If not then pleases supply a proper schematic, hand drawn is fine, Fritzing drawn is not.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.