const int ldrpin = A2;
int ldrstat = analogRead(ldrpin);
void setup(){
pinMode(ldrpin, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(ldrstat);
}
so this code is spouse to give me the light value form the ldr but all I get is just 0 no matter if there is flashlight in front of it or my hand completly blocking everything.. I think it's the resistor fault because in tinckercad everything runs smoothly but not IRL.
You have two problems. 1. is that you need a pull down resistor for the LDR to pass any current and develop a voltage drop. 2. Using A2 as an int causes the compiler to assign A2 as a variable not a pin. When the LDR is connected between +5 and A2, it is a pull up resistor and the ADC should show 1023 but, it shows 0, so you are not reading the input on pin A2.