Difference between revisions of "LED"

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
 
(17 intermediate revisions by 3 users not shown)
Line 8: Line 8:
 
A LED typically requires a resistor that is in series with the LED to restrict the current that is flowing through the LED.
 
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:
+
For sketching we can just use the following values (see [[#Background]] for more details):
* 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.
 
 
 
[[File:Led04.JPG|500px]]
 
 
 
For sketching a shortcut we can also just use the following values:
 
 
* 100 Ohm for a controller with 3.3V (our ESP32/ESP8266)
 
* 100 Ohm for a controller with 3.3V (our ESP32/ESP8266)
 
* 150 Ohm, 200 Ohm or 330 Ohm for a controller with 5V
 
* 150 Ohm, 200 Ohm or 330 Ohm for a controller with 5V
Line 23: Line 15:
 
This is how to connect an LED to a power supply. It does not matter where the resistor goes. But if the direction of the LED is wrong, it will not light up.
 
This is how to connect an LED to a power supply. It does not matter where the resistor goes. But if the direction of the LED is wrong, it will not light up.
  
[[File:Led00.JPG|300px]]
+
[[File:Led00.PNG|300px]]
  
LED will be on if Pin is 3.3V (or ON or High)
 
  
[[File:Led02.JPG|300px]]
+
LED will be on if Pin26 is 3.3V (or ON or High)
  
 +
[[File:Led02.PNG|300px]]
  
LED will be on if Pin is 0V (or OFF or Low)
 
  
[[File:Led03.JPG|300px]]
+
LED will be on if Pin26 is 0V (or OFF or Low)
 +
 
 +
[[File:Led03.PNG|300px]]
  
 
= How to control it in MicroPython =
 
= How to control it in MicroPython =
Line 61: Line 54:
 
       sleep(0.5)
 
       sleep(0.5)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
The setup to try the program:
 +
 +
[[File:Exampleled.PNG|303px]]  [[File:Exampleled1.JPG|200px]]
  
 
= Related Tutorial Videos =
 
= Related Tutorial Videos =
 
<youtube>0KGgYsEZcZM</youtube>
 
<youtube>0KGgYsEZcZM</youtube>
 +
 +
= Background =
 +
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.
 +
 +
[[File:Led04.JPG|500px]]
 +
 +
 +
[[Category:Actuators]]

Latest revision as of 09:31, 14 June 2024

Description[edit]

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 sketching we can just use the following values (see #Background for more details):

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

How to connect it electrically[edit]

This is how to connect an LED to a power supply. It does not matter where the resistor goes. But if the direction of the LED is wrong, it will not light up.

Led00.PNG


LED will be on if Pin26 is 3.3V (or ON or High)

Led02.PNG


LED will be on if Pin26 is 0V (or OFF or Low)

Led03.PNG

How to control it in MicroPython[edit]

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

A small Program in MicroPython[edit]

 1 from machine import Pin
 2 from time import sleep 
 3 
 4 # assume our LED is connected to Pin 26, we use it as output 
 5 myLED = Pin(26, Pin.OUT)
 6 
 7 while True:
 8       # this switches the LED on for 1 second
 9       myLED.on()
10       sleep(1)
11       # this switches the LED off for 500 ms
12       myLED.off()
13       sleep(0.5)

The setup to try the program:

Exampleled.PNG Exampleled1.JPG

Related Tutorial Videos[edit]

Background[edit]

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.

Led04.JPG