Friday, January 28, 2011

Project 7 - Pulsating Lamp

I'm still working on the modification to Project 6 that will make the LEDs behave like a bouncing ball (see page 58), but so far I haven't figured out the proper code yet. (Please don't tell me - yet - as I want to try and figure this out on my own.)

In the meantime, I've moved on to Project 7 here which uses a bit of my least-favorite subject in high school - trigonometry. (Sorry math-teachers... I loved Algebra, Geometry, and Calculus, but Trig was my kryptonite...)

Project 7 calls for a single LED, but I thought it'd be fun to throw a few extra in the mix so I wired it up with 3 LEDs - green, red, and yellow. I also modified the code by adding in some additional variables (yes, I could have used an array and a loop for assigning the pins to OUTPUT mode, but with only 3 LEDs it was just as fast to create 3 variables and copy-and-paste some of the original code).

I also got to use my new mini-breadboard and the flexible jumper wires I ordered from makershed.com last week. The MakerShield is very cool but it's a DIY device, so I'll be soldering this weekend to get it operational and ready to use... will post pics when done.

Below is a video of the pulsating LEDs... the text calls for a green LED but I found the green LED gave me the worst results... the red and yellow LEDs have a very nice fade in and out and the green one just looks weak (your results may vary). Could be a cheap LED... who knows?

I think the key concept to take from this project is to understand PWM (and how the sine function is used in the code...). I got lucky in the sense that I wired up my 3 LEDs using pins 9, 10, and 11... I didn't realize that the PWM pins were limited to 3, 5, 6, 9, 10 & 11. If I had used 10, 11, and 12, I doubt I'd have gotten the results I wanted. (As a matter of fact, I'm going to pause here and rerun the project and change the code to use pin 12 for the yellow LED... let's see what happens... 2nd video will show the results.)



5 comments:

  1. Jim,

    Because you are using the same resistor for the Red, Yellow and Green LED's, there is the same amount of current running through each. The brightness of an LED is related to how much current it is seeing. The reason the green looks pretty dodgy is because inthe colour spectrum, it is much easier to excite photons in the red band than it is in the green band. If you think of a rainbow, a blue LED would be even worse. (Someone feel free to correct me on the physics, it's beena few years but I'm pretty sure that was the reason :D )

    ReplyDelete
  2. Damien,

    I put a single resistor in front of each LED. I think it is just hard to see in the video.

    ReplyDelete
  3. Sorry, I meant "the same value resistor" for each LED.

    ReplyDelete
  4. Gotcha. So you think if I lower the resistor value for the green LED, it might brighten a bit? My problem is I don't have any data on that green LED so the voltage max is unknown.

    Still, your explanation sounds right about the color green versus red or yellow.

    ReplyDelete
  5. Yep, lower the resistance which should brighten the LED. We used to put 20mA through our LEDs as default, and up to 50mA when pulsed. Times have probably changed though since then.

    ReplyDelete