Parry21
Published

Temperature and Light on an LCD

Display the ambient light and temperature of a place.

IntermediateFull instructions provided3,924
Temperature and Light on an LCD

Things used in this project

Story

Read more

Schematics

Light and temperature sensor

Code

Light and Temperature Sensor

C/C++
/*For more details and information on the code used to get the temperature sensor to work properly, visit my previous project*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0;
float fntemp;
float sum;
float voltage;
int sensorVal;
int count;
float lux=0.00,ADC_value=0.0048828125,LDR_value;//Conversion of the
float lux2=0.00,LDR_value2;//photoresistor value to the SI Unit of lux
float lux3=0.00,LDR_value3;
float lux4=0.00,LDR_value4;
void setup() {
  Serial.begin(250000);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  sum = 0.0;
  voltage = 0.0;
  fntemp = 0.0;
  sensorVal = 0;
  count = 0; 
  pinMode(A1,INPUT); 
  pinMode(A2,INPUT);
  pinMode(A3,INPUT);
  pinMode(A4,INPUT);  
}

void loop() {  
  if (count < 30) {
    sensorVal = analogRead(sensorPin);
    voltage = (sensorVal/1024.0)*5.0;
    sum += ((voltage-0.5) * 100);
    count ++;
    delay(1);
  }
  else {
    fntemp = sum / count;
    count = 0;
    sum = 0.0;
  }
  Serial.println(fntemp);
  lcd.print(fntemp);
  lcd.print(" C");
  lcd.setCursor(0, 1);
  delay(100);
  LDR_value=analogRead(A1);
  lux=(250.000000/(ADC_value*LDR_value))-50.000000;
  LDR_value2=analogRead(A2);
  lux2=(250.000000/(ADC_value*LDR_value2))-50.000000;
  LDR_value3=analogRead(A3);
  lux3=(250.000000/(ADC_value*LDR_value3))-50.000000;
  LDR_value4=analogRead(A4);
  lux4=(250.000000/(ADC_value*LDR_value4))-50.000000;
  float luxa = (lux + lux2 + lux3 + lux4) / 4;
  delay(100);//All delay values can be tweaked to your desires. I found
  Serial.println(luxa);//the values that are currently set as the
  lcd.print(luxa);//optimum.
  lcd.print(" lx");
  lcd.setCursor(0, 0);
}

Credits

Parry21
1 project • 2 followers

Comments