hello,
I have set up a circuit which gets the analogue read from an LDR. I get the values ok but how would I convert these values to a percentage? I have seen calculations like (5v-LDR reading)/1023 what is this calculating? I know the light depends on the resister you use in the voltage divider but a percentage is easier to display and makes a bit more sense than a number from 0-1023.
here is my code for temp, humidity and light sensor.
#include <dht.h> // including DHT11 libary
dht DHT;
int dht_dpin = A0; // Data pin for DHT11is connected to pin A0
int LDRPin= A2; // LDR pin for reADING IN A2
int x = 0;
int row = 0;
void setup(){
Serial.begin(9600);
delay(300);//Let system settle
Serial.println("Humidity and temperature\n\n"); // Print to serial monitor
delay(1000); //Wait rest of 1000ms recommended delay before
Serial.println("LABEL, Time, H %, T (C), Light"); // Print headers for serial monitor
}
void loop(){
int LDRReading = analogRead(LDRPin); // Reading value from LDR
DHT.read11(dht_dpin);
Serial.print("DATA,TIME,");
Serial.print(DHT.humidity); Serial.print(",");
Serial.print(DHT.temperature); Serial.print(",");
Serial.println(LDRReading);
row++; // for PLX-DAQ
x++; // for PLX-DAQ
delay(800); // Read values every 800 ms
}