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

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

PRO
USA
#25   — Edited

Hi Bobsheaux ,I read your posts, my friend.  :-)

Sorry you had to get the long version of LEDs, great info, maybe a little over kill from DJ's original post... :-)

Here is the simple version:

here is the LEDs I used - $8.98 for many types https://www.amazon.com/Haitronic-assorted-Prototyping-breadboard-circuitry/dp/B01MYWS9IW/ref=sr_1_2?dchild=1&keywords=led+hobby&qid=1598022758&sr=8-2

You do need some hobby Male to Male Lead Plug Extension Wires - cheap on Amazon

I simply plug is a few light-emitting diode  -  LEDs per DJ’s instructions:

DJ - quote:

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 (+) (long side) wire to the signal (white) pin D0 of the EZ-B.

  1. Connect the LED's Cathode (-) (short side) wire to the ground (black) pin D0 of the EZ-B. 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...

Code: In ARC open a script and put:

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.

In ARC  I opened the PWM control and used the "PWM Slider" to turn the LED on / off

I did it and it worked perfectly

If you need a video, I can make one for you.

EzAng

PRO
USA
#26  

Bobsheaux, did you ever finish this LED project? I never heard.

I always finish and understand a project before I go on to something else. EzAng

#27  

I haven't got it QUITE figured out yet.  And this might seem a bit ambitious for someone who's done as much bitching and head-scratching as me, but... I kinda want to try doing THIS...

https://youtu.be/d6RR5tw8jx0?t=51

PRO
Canada
#28  

In that video they use quite a large speaker and likely a decent amplifier, the voltage coming out of the amp would have to be fairly high to light up that many LEDs (since there is a diode in between each one). So there are a couple ways to do that, use the transistor idea I mentioned a little while ago (with some mods) or use an external amplifier with the circuit they show in the video. The transistor way would likely take some electronic design and tweaking, it would be a bit more advanced.