LED: Difference between revisions

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
No edit summary
Line 20: Line 20:
= How to connect it electrically =
= How to connect it electrically =
images goes here... todo
images goes here... todo
[File:Led01.JPG]
[[File:Led01.JPG]]
[File:Led02.JPG]
[File:Led02.JPG]
[File:Led03.JPG]
[File:Led03.JPG]

Revision as of 13:30, 12 August 2020

Description

LEDs are most common as simple visual output. LED stands for light-emitting diode (https://en.wikipedia.org/wiki/Light-emitting_diode).

LEDs have 2 connectors: anode (+, long leg) and cathode (-, short leg)

The direction in which the LED is put into the circuit is important. For the forward direction and this is what we want, as this is when the LED is lighting up, the cathode (-, short leg) has to go towards 0V/GND and the anode (+, long leg) towards 3.3V/+/VSS.

A LED typically requires a resistor that is in series with the LED to restrict the current that is flowing through the LED.

For an LED we are interested in the following parameters:

  • the forward voltage (typically about 2V)
  • the forward current (typically about 20mA = 0,02A)

We use the equations R=U/I and U=U1+U2 to calculate the resistor required.

For sketching a shortcut we can also just use the following values:

  • 100 Ohm for a controller with 3.3V (our ESP32/ESP8266)
  • 330 Ohm for a controller with 5V

How to connect it electrically

images goes here... todo [File:Led02.JPG] [File:Led03.JPG]

How to control it in MicroPython

from machine import Pin
# assume our LED is connected to Pin 26, we use it as output 
myLED = Pin(26, Pin.OUT)
# this switches the LED on
myLED.on()
# this switches the LED off
myLED.off()

A small Program in MicroPython

from machine import Pin
from time import sleep 

# assume our LED is connected to Pin 26, we use it as output 
myLED = Pin(26, Pin.OUT)

while True:
      # this switches the LED on for 1 second
      myLED.on()
      sleep(1)
      # this switches the LED off for 500 ms
      myLED.off()
      sleep(0.5)