const int led=10;
const int ldr=A0;
int data;
void setup() {
pinMode(led, OUTPUT);
pinMode(ldr, INPUT);
Serial.begin(9600);
}
void loop() {
int ldrvalue = analogRead(ldr);
ldrvalue = map(ldrvalue, 0,1023,255,0);
float voltage = ldrvalue *(5.0/1023.0);
Serial.print("ldr sensor data:");
Serial.println(voltage);
Serial.println("[v]");
analogWrite(led, ldrvalue);
delay(200);
}