Blink LED using ESP32 python program in IoT
Blink LED using ESP32 python programe in IoT
In this programe, we will see about LED turn on & off procedure using ESP32 microcontroller and Python Program.
Requirements,
- ESP32 Microcontroller
- LED
- 10 Ohm Resistor
Circuit connections as,
- ESP32 pin2 to one end of Resistor
- Resistor another end to LED positive
- LED negative to ESP32 GND(ground)
Python script:
Turn "ON" LED:
print('Turning on the LED')
from machine import Pin
# Define the pin where the LED is connected
led_pin = 2
# Create a Pin object for the LED
led = Pin(led_pin, Pin.OUT)
# Turn on the LED
led.on()
Turn "OFF" LED:
print('Turning off the LED')
# Turn off the LED
led.off()
Turn "ON & OFF" in Loop:
import time
from time import sleep
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
*simulate in wokwi before the physical working
Full programe for turn ON & OFF
print('kavi-Turn on&off the LED')
from machine import Pin
import time
from time import sleep
#Define the pin where the LED is connected
led_pin = 2
#Create a Pin object for the LED
led = Pin(led_pin, Pin.OUT)
#Turn on the LED
led.on()
#Wait for 1 second
time.sleep(1)
#Turn off the LED
led.off()
#loop on&off
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
Comments
Post a Comment