Best Microcontroller Projects


[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Forum
Problem?-Solution
Projects Showcase
LCD-KEYS OnePort
PIC Introduction
PIC Programmer
Schematic Tool
PIC Projects
Tips & Techniques
PIC Tutorials
C Course
Digital Downloads
Store
My SECRET
Oscilloscopes
About Me
Search This Site
Freebies
Articles
Books
Resource Links
Site Map
Video du Jour
Rant/Rave
Privacy Policy
Contact
Terms of Use


Custom Search

Sign up for MicroZine:
''The'' Microcontroller Newsletter


:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Enter your first Name and primary email address in the form above:

And receive absolutely FREE a full project for:


"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be Removed
at any time.  

It will NOT be
available indefinitely SO

To avoid
disappointment get it:

Now



Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.


To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates.

Scroll up to the form above and sign up NOW.  Don't forget it's FREE and if you don't like it you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.



Social Bookmarking
Click & Add:
add to BlinkBlink
add to Del.icio.usDel.icio.us
add to DiggDigg
add to FurlFurl
add to GoogleGoogle
add to SimpySimpy
add to SpurlSpurl
Bookmark at TechnoratiTechnorati
add to YahooY! MyWeb
Readers comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."


- Ranish Pottath


"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com

Learn PIC C Now
Wondering how to program your next project using C and need a great start?


"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

Learn Microcontrollers
"Interested in
Microcontrollers?"


Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon





How to drive an rgb led using three microcontroller pins.


You can use a software PWM to
drive an RGB led...

"Download Your Essential
Guide To Logic Level MOSFETs"

"This is completely Free"

CLICK HERE to DOWNLOAD NOW

Sponsored Links...

The RGB LED contains three LEDs encased in one shell: Red, Green and Blue (some contain an extra blue led - as blue LEDs generate less output intensity (candela) per mA). It looks like a single white led except that it has four leads - one for the common ground connection and one for each led.

pwm rgb led using microcontroller.

Basic operation

The average current through each of the LEDs determines it's light output i.e. its contribution to the total output color. So by controlling the average current through each LED you can create almost any other color.  

Specification

RGB LED Output colors Red, Green, Blue

RGB LED driver project details.

RGB LED Project
Compiler Mikroelectronika C compiler V5.0.0.3 Free!
Target 16F877A (retargetable to other PICs that have an 3 output pins!).
Software level Medium.
Software notes Interrupt driven 3 output PWM.
Hardware level Easy.
Hardware notes No special notes
Project version 1.00 Initial Release
Project files Enter your details to get the Download Link
and get the microcontroller newsletter:
:
:
(Note: Your email is safe it will never be sold or rented).
You will get All the C source code and hex file.


Essential
C Programming Course:

You can program the PIC in circuit through the ICSP connector.

Diffuser

By varying the current through each led you can create almost any other color but at close range you only see the individual colors of each LED.

To see the 'merged' color view it from a distance or put a diffuser over it. I used a small piece of baking paper - which is transparent enough to let the light through and opaque enough to diffuse the light from the three LEDs. In a proper design you would use a semi-transparent plastic.

Note: Other projects in the web show the output without a diffuser I think the camera settings merge the light acting as a diffuser (they do - using a digital camera gives the same results i.e. It's not what your eye sees on the bench).

If you make a sign board using these LEDs you won't need a diffuser as your eye will not be able to distinguish the individual LEDs (if it's far enough away - it's exactly the same as a TV pixel).

How it works.

This project uses puls width modulation to drive each of the leds in the RGB led. By changing the duty cycle of each PWM signal you can control the average current flowing through each led creating any color you want. The limit is set by the resoelution of the PWM (set at 256 steps per channel).

The project relies on persistence of vision to make it appear that the led is continuously driven (the PWM signals must be repeated quickly enough so that you do not see any flicker) at a rate greater than 50Hz (approx). Too slow and you begin to see the led flickering.

PWM Software

PIC micros only have one built in PWM module so you need to create three pulse width modulators in software.

This is fairly easy to do using one of the timers in the PIC micro and all that's needed is an 8 bit timer for an output resolution of 1/256.

Note: It's fairly difficult to make it work at 4MHz (it probably can be done in assembler or with more effort in 'C'). So I chose to use a 20MHz crystal just to make it easier.

Heart beat timer

This project uses timer 0 to create a heart beat timer that generates a regular interrupt. The pwm timer tick routine called here controls the PWM operation.

Note: You can use any timer to generate the heartbeat.

Non PWM use

The other way to use a tri-color LED is without using PWM and treat each led line as fully on or off.

Using it in this way you get six color outputs: Red, Green, Blue, Magenta, Cyan and Yellow - without complex PWM control.

Hardware

The hardware is simple with only three wires needed to drive the rgb led.

RGB LED circuit
(Click diagram to open a pdf).

rgb led hardware circuit


Learn about the tool used for creating this diagram

RGB LED Software operation

The source code consists of five files:

RGB LED 'C' Files

  • 16F877A_rgb-led.c
  • pwm.c

RGB LED Header files

  • pwm.h
  • bit.h
  • types.h

RGB LED: pwm.c, pwm.h, types.h

pwm.h defines the prototypes for use in other files.

pwm.c defines a simple pulse width modulator - simplified in that each output uses the same time base. Two user access functions let you initialize the port and set the duty cycle:

  • _pwm_Init( U8 *usePORT, U8 _p1, U8 _p2, U8 _p3 )
  • _pwm_Duty( U8 chan, U8 d )

Note that U8 is defined in types.h as a typedef so and is a short hand for an unsigned short (usually of 8 bits) hence Unsigned 8bit.

Channels are selected in _pwm_Duty from 0 to 2.

RGB LED: PWM interrupt

The main control for the PWM is _pwm_timer_tick(void) which must be called regularly from a timer interrupt. This calls the local file scope function action which then calls chan_action that does the PWM output. Note that a shadow register is used here to ensure the outputs are set correctly.

You would need to integrate the shadow register with other code if other code accesses the same port.

The resolution of the PWM is 256 bits and at each call to _pwm_timer_tick(void) each pwm channel is updated.

RGB LED : 16F877A_rgb-led.c

This function contains main which initializes the PWM on port C and enters an infinite loop.

The random number generator qrn seems more random than the built in one and it uses less memory. It is used in random_start to set a random duty cycle value for each channel and a random sweep direction.

In the infinite loop each channel is swept up and down using the current values from the arrays duty[] and dir[]. This produces a random color pulsating light output.

So that a new random sequence is started after a count of 300 cycles a new random sequence is started so you don't see the same thing over and over.



Jump from RGB led page 
to Best Microcontroller Projects Home Page.


Don't forget to Sign Up for your

Microcontroller Newsletter

With "Essential tips and techniques",

..."New Site Info" and more...

Including a free project :

How to drive an LCD and 12key keypad using "Only One 8 Bit Port" with no interface logic!...

(Works for any microcontroller)

This costs you : Nothing...
Just fill out the form below and you'll get full C source code and project schematic and description.



:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Google
 
  Best Microcontroller projects.