#script to control the LED brightness w.r.to intensity of light falling on LDR
from machine import Pin, ADC, PWM
from time import sleep
# Configure ADC for ESP32
led=PWM(Pin(4),5000)
ldr = ADC(Pin(34))
ldr.width(ADC.WIDTH_10BIT) # 10 bit resolution => 0 to 1023
ldr.atten(ADC.ATTN_11DB) # 11 DB => full range voltage: 3.3V
while True:
# Read the value from the LDR
x = ldr.read()
print(x)
led.duty(1023 - x)
sleep(0.1)
# from machine import Pin, ADC, PWM
# from time import sleep
# #Configure ADC for ESP32
# led=PWM(Pin(4),5000)
# ldr = ADC(Pin(34))
# ldr.width(ADC.WIDTH_10BIT) # 10 bit resolution => 0 to 1023
# ldr.atten(ADC.ATTN_11DB) # 11 DB => full range voltage: 3.3V
# frequency = 5000
# led_pwm = PWM(Pin(4), frequency)
# while True:
# ldr.read()
# print(“ldr_value=”, ldr_value)
# voltage = ldr_value*(3.3/1023)
# print(“ldr_voltage=”, voltage)
# led_pwm.duty(1023-ldr_value)
# sleep(0.1)
# # write a micropython script to control the brightness of the led gpio4 with respect to intensity of the light fall on the ldr connected of gpoo34 (if the intensity of the sunlight is more than brightness of the will be low)
# from machine import Pin,ADC,PWM
# from time import sleep
# led=PWM(Pin(4),5000) #f=1hz to 40M hz
# ldr=ADC(Pin(34))
# ldr.width(ADC.WIDTH_10BIT)
# ldr.atten(ADC.ATTN_11DB)
# while True:
# x=ldr.read()
# print(x)
# led.duty(x)