Hi everyone
i don't now if this is the right section of the forum, but i'll try to post here.
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.
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().
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