NODEMCU -photoresistence problem?

Hi everyone
i don't now if this is the right section of the forum, but i'll try to post here.:smiley:

i'm having some issues with a project where i need to turn on some leds with my nodemcu. The problem is when i try to cover the photoresistor...No leds turn on, in serial monitor the value of photoresistor is 0 everytime. My project has others instructions to do, like servomotors and Pir sensor, so i decided to try the photoresistor alone with a new code. I used a code from internet, and i connected components like the image below the code, but nothing. If i try to connect the photoresistor just to the "Vin" of Nodemcu and a Led, it works, but when i try to connect with a pin of NodeMcu it stops to work...

i don't know if this is the right section of the forum, but i'll try to post here.

that's the base code that i use for test:

#define f_res D0 //Fotoresistenza collegata al pin A0
#define LED D7 //Led collegato al pin 13
 
void setup() {
pinMode(D0, INPUT); //Impostazione del pin D0 come input
pinMode(D7, OUTPUT); //Impostazione del pin D7 come output
Serial.begin(9600); //Inizializzazione della comunicazione seriale
}
 
void loop() {
int val = analogRead(f_res); //Lettura del valore della fotoresistenza
Serial.println(val, DEC); //Scrittura del valore della fotoresistenza 
 
//Del valore 500 parleremo piรน avanti
if(val < 500) digitalWrite(LED, HIGH); //Accensione del led
else digitalWrite(LED, LOW); //Spegnimento del led
}

and that's the image below the code:

it's with arduino but i used the right pin on Nodemcu.

Thanks for help!!!!

it's with arduino but i used the right pin on Nodemcu.

Prove that. Show me a pin diagram that shows what pins can be used for what, and which pins have special meaning.

Do u mean this?

You should measure the voltage at the LDR when it is uncovered and when it is covered to see if the electrical circuit is working properly. And tell us what the voltages are.

And it will be much easier to help if you post a diagram of the actual connections. Just make a pencil drawing and post a photo of it.

If you just want to use the LDR as a switch it should work fine if you read it with digitalRead().

...R

Scottino:
Do u mean this?

Yes. The only thing that is not clear from that picture is which pins are digital only, and which are analog or digital.

Personally, I would expect that referring to a pin as D0 would imply that it was a digital pin, not an analog pin.

Robin2:
You should measure the voltage at the LDR when it is uncovered and when it is covered to see if the electrical circuit is working properly. And tell us what the voltages are.

And it will be much easier to help if you post a diagram of the actual connections. Just make a pencil drawing and post a photo of it.

If you just want to use the LDR as a switch it should work fine if you read it with digitalRead().

...R

I tried using the code with digital and not analog:
Uncovered 3.8V
Covered: 4.5V

:confused:

Scottino:
Uncovered 3.8V
Covered: 4.5V

I think you need to change the resistor that makes the voltage divider so you get a greater range. What value do you have now?

I have found that 68k works nicely with my LDRs.

...R