# write a micropython script to control the brightness of a led connected to gpio 4 
# with respect to intensity of the light falling on ldr connected to gpio 34
# (if intensity of sunlight is more brightness of led less)

from machine import Pin, PWM, ADC
from time import sleep

led = PWM(Pin(4),5000)
ldr = ADC(Pin(34))
ldr.width(ADC.WIDTH_10BIT)
ldr.atten(ADC.ATTN_11DB)

while True:
   x = ldr.read()
   print(x)
   led.duty(x)
Loading
esp32-devkit-c-v4
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO
led1:A
led1:C
r1:1
r1:2