Temperature and Light on an LCD
Display the ambient light and temperature of a place.
Components and supplies
1
Temperature Sensor
1
Photo resistor
1
Arduino UNO
1
RGB Backlight LCD - 16x2
Project description
Code
Light and Temperature Sensor
c_cpp
1/*For more details and information on the code used to get the temperature sensor to work properly, visit my previous project*/ 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 4const int sensorPin = A0; 5float fntemp; 6float sum; 7float voltage; 8int sensorVal; 9int count; 10float lux=0.00,ADC_value=0.0048828125,LDR_value;//Conversion of the 11float lux2=0.00,LDR_value2;//photoresistor value to the SI Unit of lux 12float lux3=0.00,LDR_value3; 13float lux4=0.00,LDR_value4; 14void setup() { 15 Serial.begin(250000); 16 lcd.begin(16, 2); 17 lcd.setCursor(0, 0); 18 sum = 0.0; 19 voltage = 0.0; 20 fntemp = 0.0; 21 sensorVal = 0; 22 count = 0; 23 pinMode(A1,INPUT); 24 pinMode(A2,INPUT); 25 pinMode(A3,INPUT); 26 pinMode(A4,INPUT); 27} 28 29void loop() { 30 if (count < 30) { 31 sensorVal = analogRead(sensorPin); 32 voltage = (sensorVal/1024.0)*5.0; 33 sum += ((voltage-0.5) * 100); 34 count ++; 35 delay(1); 36 } 37 else { 38 fntemp = sum / count; 39 count = 0; 40 sum = 0.0; 41 } 42 Serial.println(fntemp); 43 lcd.print(fntemp); 44 lcd.print(" C"); 45 lcd.setCursor(0, 1); 46 delay(100); 47 LDR_value=analogRead(A1); 48 lux=(250.000000/(ADC_value*LDR_value))-50.000000; 49 LDR_value2=analogRead(A2); 50 lux2=(250.000000/(ADC_value*LDR_value2))-50.000000; 51 LDR_value3=analogRead(A3); 52 lux3=(250.000000/(ADC_value*LDR_value3))-50.000000; 53 LDR_value4=analogRead(A4); 54 lux4=(250.000000/(ADC_value*LDR_value4))-50.000000; 55 float luxa = (lux + lux2 + lux3 + lux4) / 4; 56 delay(100);//All delay values can be tweaked to your desires. I found 57 Serial.println(luxa);//the values that are currently set as the 58 lcd.print(luxa);//optimum. 59 lcd.print(" lx"); 60 lcd.setCursor(0, 0); 61} 62
Light and Temperature Sensor
c_cpp
1/*For more details and information on the code used to get the temperature sensor to work properly, visit my previous project*/ 2#include <LiquidCrystal.h> 3LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 4const int sensorPin = A0; 5float fntemp; 6float sum; 7float voltage; 8int sensorVal; 9int count; 10float lux=0.00,ADC_value=0.0048828125,LDR_value;//Conversion of the 11float lux2=0.00,LDR_value2;//photoresistor value to the SI Unit of lux 12float lux3=0.00,LDR_value3; 13float lux4=0.00,LDR_value4; 14void setup() { 15 Serial.begin(250000); 16 lcd.begin(16, 2); 17 lcd.setCursor(0, 0); 18 sum = 0.0; 19 voltage = 0.0; 20 fntemp = 0.0; 21 sensorVal = 0; 22 count = 0; 23 pinMode(A1,INPUT); 24 pinMode(A2,INPUT); 25 pinMode(A3,INPUT); 26 pinMode(A4,INPUT); 27} 28 29void loop() { 30 if (count < 30) { 31 sensorVal = analogRead(sensorPin); 32 voltage = (sensorVal/1024.0)*5.0; 33 sum += ((voltage-0.5) * 100); 34 count ++; 35 delay(1); 36 } 37 else { 38 fntemp = sum / count; 39 count = 0; 40 sum = 0.0; 41 } 42 Serial.println(fntemp); 43 lcd.print(fntemp); 44 lcd.print(" C"); 45 lcd.setCursor(0, 1); 46 delay(100); 47 LDR_value=analogRead(A1); 48 lux=(250.000000/(ADC_value*LDR_value))-50.000000; 49 LDR_value2=analogRead(A2); 50 lux2=(250.000000/(ADC_value*LDR_value2))-50.000000; 51 LDR_value3=analogRead(A3); 52 lux3=(250.000000/(ADC_value*LDR_value3))-50.000000; 53 LDR_value4=analogRead(A4); 54 lux4=(250.000000/(ADC_value*LDR_value4))-50.000000; 55 float luxa = (lux + lux2 + lux3 + lux4) / 4; 56 delay(100);//All delay values can be tweaked to your desires. I found 57 Serial.println(luxa);//the values that are currently set as the 58 lcd.print(luxa);//optimum. 59 lcd.print(" lx"); 60 lcd.setCursor(0, 0); 61} 62
Downloadable files
Light and temperature sensor
Light and temperature sensor
Comments
Only logged in users can leave comments