print("Hello, ESP32!") # Display message to serial monitor
#####################################
###### IMPORT LIBRARIES
from machine import Pin # Import Pin module to control GPIO pins
from machine import ADC # Import ADC module to read analog values
from utime import sleep # Import sleep function for delay
#####################################
###### PIN CONFIGURATIONS
# Configure the pin as input
# Replace the x with your GPIO Pin X number here
pot_pin = ADC(Pin(4)) # Set GPIO4 as ADC input for potentiometer
# Configure LED as output
# Replace the y with your GPIO Pin Y number here
led1_pin = Pin(25, Pin.OUT) # Set GPIO25 as output for LED
#####################################
###### MAIN ROUTINE
def main():
while True: # Infinite loop
# Read potentiometer value
pot_value = pot_pin.read() # Read analog value from potentiometer
# Condition for LED
if pot_value < 2100:
led1_pin.value(0) # Turn OFF LED
else:
led1_pin.value(1) # Turn ON LED
# Print potentiometer value to serial monitor
print(pot_value)
# Small delay before next reading
sleep(0.1)
#####################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main() # Run the main function