Using PWM outputs with an Arduino and a LED

Hi everyone, been a while since my last post, but I have been a busy new daddy. ๐Ÿ™‚ I wanted to demonstrate what PWM output was and how to use it nicely in a sketch. I’m really big on ramping lights on and off (my entire house is set up that way) and would like to share how do accomplish that. I also wanted to use a video to show PWM outputs on a scope to help me explain the process.


Slide from video above

Pulse Width Modulation (PWM, but also sometimes referred to as Pulse-Duration Modulation -PDM) is the manipulating (modulating) of the width of a fixed pulse. The pulses are sent at the same voltage and frequency, so just the width of the pulse is changed. In the screen shot above the fixed voltage is 3.2V and the Frequency is 490Hz.

You can grab the serial controlled Arduino code here, or the shorter fading sketch here.

Controlling high power (or high number of) LED’s with an Arduino

A while ago I posted about my bench lights, and have gotten a number of request for schematics and code. I’ll gladly put the code up, but I also wanted to explain what I did so that others can create their own, or at least change my design up as they wish. The transistors I’m using are TIP122’s. You can find the data sheet here. They will switch a lot of power, but keep in mind, they need to have adequate cooling if you are going to push them hard. Always remember, fire = bad.

I covered the basic schematic for a few LED’s in the video above, but if you have any questions, feel free to post them in the comments and I will answer as quickly as I can.

You can download the original (controller with LCD and hard buttons) code here.

You can also download the newer (serial controlled – adjustable level) code here.

Just a note, I will be using Vimeo from now on, but I will still put all my videos on YouTube as well.

Multiplexing for a 7 year old

I have been wanting to make a LED clock for sometime and can’t really believe I never have. So I rummaged through some parts and found some nice 4 segment LED displays. I found some code for a simple clock at nootropicdesign, and it did something pretty neat. It slowed down multiplexing so you could see it, then it would get faster until it appeared “on”. It was a good sketch, but I thought, it needs set buttons, a blinking colon, and a way to trigger the multiplex slow down trick with out restarting. (and resetting the clock!) So I made this little clock and it worked great.

This was a great way to show my 7 year old (who wrote his first Arduino sketch the other night) about multiplexing. A picture is worth 1,000 words right? Well, a hands on demo is worth even more than that. After explaining how it works, he totally understood.

Then I noticed I had, sitting on my bench, some Lexan laser cut, for those little Nokia LCD’s I love so much, that had a 4 segment LED display size hole in them. I made the clock and moved some pins around to free up 3 PWM pins for an RGB LED. Because it’s always good to have a full PWM controlled RGB LED, ya know, just in case. Thinking of programming the LED different colors/brightness according to sun position. I also remembered I have a few Dallas 1307’s.. Maybe tomorrow, it’s late right now, and besides I’m busy porting software for a Touch Shield I got. ๐Ÿ™‚

If your new to multiplexing, it basically combines pins of LED’s and then through switching on only certain pins at a time, you can light only certain LED’s. If you were to apply power to more than 1 cathode and anode, you would get unwanted LED’s lighting. So how can this work? I have to light 14 LED’s just to display 1:00! What makes this work is you light one segment at a time. With a microcontroller, you can do this in an order and at a rate that’s fast enough that the human eye thinks that they are on solid. Most LED 4 digit displays found in microwaves, stoves, appliances, and VCR/DVD players are multiplexed. Its a great way to light a lot of LED’s with less pins than connecting each directly to the microcontroller. Below is a circuit diagram of the LED display I used. The link for the code is below as well, as always, hack away. ๐Ÿ™‚ Detailed pinout for Arduino are in the code comments.

Multiplexing!

Get the code here. (Arduino 22 .pde file)

Schematic (Eagle file)

Schematic (png file)

Dual Boot LED Control, RGB to HEX Converter

OK, so a while ago I fell in live with these Nokia 5110/3310 LCD displays. They use a library from adafruit.com that you can find here. They are small, fast, and don’t gobble up a lot of current. So I needed a project to make so I could use one. The result? A massive overkill of an LED controler with all kinds of options and features.

So I was thinking about a RGB to HEX Color converter that I had made for the 2.8″ TFTLCD, and the fact that I might want to figure out values without erasing my sketch I’m working on. Although it’s nice to see the color displayed on the screen it will end up on, sometimes you just need a quick answer. Thanks to brookware2000 (in the Adafruit forums), there is a nice small program here that will do the trick. But it runs on Windows, and I’m kind of a Mac guy. The answer? Build one into my nifty little box that already has 8 buttons, an RGB LED, and a nice LCD screen! So here it is.

Download the code here. (Arduino 22 .pde file)ย This is a version of the code that just has the color converter, I’ll do a video sometime of how to do the dual boot/setup thing.

**Notice the line “PCD8544 nokia = PCD8544(13, 12, 8, 7, 5);” This is not the default pin assignments for the Nokia LCD Tutorial. (default pins are 7, 6, 5, 4, 3) You will need to adjust the wiring for this sketch to work. Pay attention to what pins are used for buttons and LED’s. ๐Ÿ™‚

“Breathing” Sleep LED

I always have loved Apple and their non-jerky, fluid like GUI in all of their OS’s. Then I noticed it even with their hardware when I got my MacBook Pro over 3 years ago. My older PC’s always had a flashing sleep LED. That was fine until I saw the “breathing” LED pattern that Apple did on the Mac products. Much nicer. ๐Ÿ™‚ I saw these awesome cufflinks with the same “breathing” pattern, and got inspired to write a little Arduino sketch to replicate it. So I did.

LED to pin 11, that all.

This is a really simple sketch, only one thing I did was vary the timing in the fade to smooth out the take off and landing. You will see that in all of the if statements inside the dimming function.

You can download the sketch here.