LED Experiments

09/09/18

Categories: Electronics

~/contents

Simple LED Circuits explains calculating resistance for single LEDs as well as in series and parallel.

Powering LEDs on Breadboard

Most of the information I saw about testing LEDs with a breadboard using 220Ohm or 330Ohm resistors. I had some 2.2k resistors, so that is what I tried, and it works. Any generic LED can be used, you can use a resistance calculator to confirm what you need.

LED Wiring

#!/usr/bin/python
from pyA20.gpio import gpio
from pyA20.gpio import port
import time

LED = port.PA6
gpio.init()
gpio.setcfg(LED, gpio.OUTPUT)

print("LED on.")
gpio.output(LED,gpio.HIGH)
time.sleep(1)
print("LED off.")
gpio.output(LED,gpio.LOW)

For multiple LEDs, try this and this.

Alternating LEDs with transistor

Switching between a green and red LED by turning the GPIO high or low. [Source]

Pulsing LEDs

Experimenting with having an LED fade in and out using pulse width modulation. [Source]

from pyA20.gpio import gpio
from pyA20.gpio import port
from orangepwm import *
from time import sleep

LED = port.PA6
gpio.init()
pwm = OrangePwm(100, LED)
val = 100
pwm.start(val)
while True:

    for i in range(0,100):
        val-=5
        pwm.changeDutyCycle(val)
        print(val)
        sleep(0.1)
        if not val:
            break

    for i in range(0,100):
        val +=5
        pwm.changeDutyCycle(val)
        print(val)
        sleep(0.1)
        if val == 100:
            break

pwm.stop()

RGB LEDs

I got some more blinkies, including a pair of RGB cathode LEDs. These LEDs have 4 pins. I actually had to test these to figure out the pin order, which is Red, GND, Green, Blue. You can blend colors. It looks like a microcontroller is the way to go for anything more complex than a basic circuit.