Esp32 with ldr sensor

Hi all
Can any one trll why my code doesn't work ;
i wont to connect ldr sensor to esp32
image
but it dosent work the outlight pin dosent give me low why

const int ldr =23;
const int outlight = 25;
void ldrlamp();
void setup{
  pinMode(ldr, INPUT);
  pinMode(outlight, OUTPUT);}
void loop() {
  ldrlamp();
}
void ldrlamp(){
  if(digitalRead(ldr)==1){
    digitalWrite(outlight, LOW);

  }else{
    digitalWrite(outlight, HIGH);

  }
}

Correct the above and rerun the sketch.

1 Like

Do the two LEDs light up?

I don't under stand what U mean

Yes the both light up and Do when.i cover it light off

Does your sketch compile?

But as @GolamMostafa has pointed out, your sketch does not compile

Yes it's compile corectly

It is compile with
But i found another way to solve this proplem i connect the Do directly to INT to the relay and it's work fine

If you found a bettor way I won't try to convince you to do something different.
Glad it worked.

1 Like

I thank you for your support thank you very much

It is surprising that your sketch works without correcting ––

void setup{

==> void setup(){

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.