Pulse Flash LED with PWM

Description

Pulse Width Modulation is the method of having a digital port, which is only On or Off to have a varying output voltage. Use this approach to flash and LED with a pulsing effect.

Step 1

DC electricity works by having Positive and Negative. An LED is short for a Light Emitting Diode. A diode prevents current from flowing both directions. Diodes only allow current to flow in one direction, and they’re always polarized. A diode has two terminals. The positive side is called the anode, and the negative one is called the cathode.

User-inserted image

Current through a diode can only flow from the anode to the cathode, which would explain why it’s important for a diode to be connected in the correct direction.

Did You Know: Physically, every diode has some sort of indication for either the anode or cathode pin. Usually the diode will have a line near the cathode pin, which matches the vertical line in the diode circuit symbol.

An LED has a physical indication of Anode and Cathode pins as well. LED stands for light-emitting diode, which means that much like diodes, they’re polarized. Find the longer leg, which indicates the positive, anode pin.

Connect an LED to port D0 of the EZ-B. In this example, we will provide power (+) to the LED from a signal pin of the EZ-B. The EZ-B will output +3.3 volts on the signal pin when it is in the ON state. The signal pin will respectively output GND when it is in the OFF state.

  1. Connect the LED's Anode (+) wire to the signal (white) pin D0 of the EZ-B.

  2. Connect the LED's Cathode (-) wire to the ground (black) pin D0 of the EZ-B.

User-inserted image

The Code Use the ServoSpeed() command to apply a ramping speed to the PWM. The PWM command to set the brightness. The PWM essentially turns the state of the digital pin ON and OFF hundreds/thousands of times per second to produce the result of a "varying" voltage. The PWM range is between 0% and 100%, called the Duty Cycle.

The ServoSpeed() command will configure Ramping between two PWM duty cycles.

Add an EZ-Script control to your project, edit and paste this code...


# set the servo speed to 2
ServoSpeed(d0, 2)

:loop

# Set LED On
pwm(d0, 100)

# wait some time for the pwm to do its ramping thing
sleep(3000)

#set LED Off
pwm(d0, 0)

# wait some time for the pwm to do its ramping thing
sleep(3000)

goto(loop)

Tweak the Sleep() command time and the ServoSpeed() command time to see the different pulsing effects.


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

PRO
Belgium
#17  

ptp

so the only problem is a wrong led . if voltage is not a problem when using the ezbv4.

PRO
USA
#18   — Edited

Quote:

so the only problem is a wrong led . if voltage is not a problem when using the ezbv4.
Yes if the LED is an Infrared, you can't see the light.

Regarding the Led current versus voltage, my answer is in context of the above scenario: EZ-Robot controller and generic leds.

bear in mind, not all leds are equal. Some leds have different forward voltages and/or max current values to operate. (high current = brighter)

https://www.hobbytown.com/radioshack-highoutput-infrared-led-rsh2760143/p787932

Quote:

Forward voltage (V): 1.2 (Typ) / 1.5 (Max), rated at 20mA. 1.4 (Typ) / 1.8 (Max), rated at 100mA.
EZ-Robot controller values: PIN Logic voltage: 3.3v PCB Resistor : 330 ohms

Ohms law:   Current = Voltage / Resistor

If your led has (typical) 1.2 forward voltage :

Current = (3.3 - 1.2) / 330 = 0.006 A => 6 milliamperes

If you could change the voltage to 5V and keeping the same resistor:

Current = (5 - 1.2) / 330 = 0.011A => 11 milliamperes

So increasing the voltage increases the current and the led will be more bright, but each led has specific limits if you cross the limit you will burn the led. http://lednique.com/electrical-theory-basics/ohms-law-and-resistor-calculation/

once again I'm discussing the relevant information, leds are diodes and there are other i.e. bored details like saturation current, but let's keep it simple:)

I had only two classes of electronics, and it was long time ago... so i hope I'm not inducing more confusion;)

Jeremie is the expert... Jeremie are you there ?

PRO
Belgium
#19  

i wonder if its an infrared led,chould that be possible to see with phone video recording? just like if you test the led from a tv remote.

PRO
USA
#20  

Quote:

i wonder if its an infrared led,chould that be possible to see with phone video recording?
Elementary my dear watson:)

Infrared LED ON :

User-inserted image

Infrared Led OFF:

User-inserted image

#21  

@Bobsheau

Quote: I bought two 2760143 LEDs from the local Hobby Town, and neither is working.

PTP Beat me to it me to the answer, Is an Infrared LED.  PTP is a great and has helped me many many times PTP know his stuff.

@Bobsheau You night have burn out your leds, I would try using you phone camera to see if it still working.

Then get the correct LED as ptp  has given you a link... Regular leds:

https://www.hobbytown.com/miniatronics-5mm-dia.-blinker-flasher-led-1ea-red-green-yel-mnt1215003/p285117

Don’t give up and  keep learning.  Ps,  in my humble opinion, I would suggest in future questions when someone asks a question please give a direct answer this will help your frustration as people try to help you.

cheers

Great job PTP!

PRO
Canada
#22  

Hello Gentlemen,

Thank you @PTP, I would have never thought that it was an IR LED! Good call looking into the part number.

@PTP is indeed correct. The voltage rating of an LED is usually referring to the diodes minimum forward voltage to overcome the voltage drop of the diode itself (normally forward voltage values are in the 1.2V to 3V range). Voltage is usually not a worry with LEDs as they can handle up to 20-30V (check the datasheet maximum voltage rating). LEDs are damaged by over current in most cases so you would have to increase the resistance as the voltage goes up in order to keep from over-currenting the LED.

In this case 3.3V from the signal pin (plus the inline 330ohm current limiting resistor) is always going to safely light up the LED, but if the light is invisible (like Infrared light) then you would have to use a digital camera to see the light. Please note that most phones and digital cameras now have Infrared light filters built-in these days so you'll need to use the lower quality front facing camera on your phone or an old digital camera.

@Bob if you want some visible colored light to come out of the LED you're going to need some new LEDs.

#23   — Edited

Of course I get the LEDs that don't give off any light...  Whoever maintains these forums, can we get a "robot facepalm" emoji to compliment the:) and:( ?

"I would suggest in future questions when someone asks a question please give a direct answer this will help your frustration as people try to help you." I'd be less frustrated if this platform's suggestion of "ez" wasn't so misleading. Look at how deep we had to dig before we came upon the revelation that I bought the WRONG kind of LED for this project.  Until individual LEDs are available for purchase in EZ-Robot's store, this tutorial needs to mention how if you're trying to get any kind of visible blinking action, you don't want to buy infrared LEDs.

And I'm not being indirect in my answering questions. Someone asks me a question, I tell them the information I THINK they're asking for.

#24  

@Bobsheau

[Quote I'd be less frustrated if this platform's suggestion of "ez" wasn't so misleading. Look at how deep we had to dig before we came upon the revelation that I bought the WRONG kind of LED for this project. Until I'd be less frustrated if this platform's suggestion of "ez" wasn't so misleading. Look at how deep we had to dig before we came upon the revelation that I bought the WRONG kind of LED for this project. Until individual LEDs are available for purchase in EZ-Robot's store, this tutorial needs to mention how if you're trying to get any kind of visible blinking action, you don't want to buy infrared LEDs.EZ-Robot's store, this tutorial needs to mention how if you're trying to get any kind of visible blinking action, you don't want to buy infrared LEDs. Of course I get the LEDs that don't give off any light... ]

IMHO,  The document DJ wrote is not miss-leading, You also can buy a lot of other things that are on ez-robots store but remember ez-rotor is not owned by Synthiam so DJ does not have any control what EZ-Robot’s store sells.

As the old saying goes, if you don’t learn something every day you’re missing out or something like that. ;-)

Now you know the difference between infrared and visible light admitting diode’s.  AFAIK I thought everyone knew the difference.

keep  on building keep on trucking. Be well, cheers