Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

DIY – How to generate different colours from RED-GREEN-BLUE LEDs using AVR microcontroller

By Ashutosh Bhatt

The circuit presented here generates different colours from 3 LEDs – RED, GREEN and BLUE only using AVR micro controller ATMega32.

As we all know there are three primary colours – red, green and blue. All other colours can be made by mixing these three colours in different amount. The picture tube of any television set also uses this principle. Today’s modern LCD and LED TVs are also based on the same principle. They generate millions of different colours by setting different levels of red, green and blue colour and generates realistic like picture.

From these three primary colours, secondary colours yellow, cyan and magenta are generated by adding two these three colours as given below

RED + GREEN = YELLOW

GREEN + BLUE = CYAN

RED + BLUE = MAGENTA

The following figure shows the colour chart for primary and secondary colours

Image showing Primary Colors

Fig. 1: Image showing Primary Colors

The given circuit demonstrates how to generates these three primary and three secondary colours from three RED, GREEN, BLUE colour LEDs with the help of AVR micro controller

Circuit description:

(Check the circuit diagram tab for complete circuit for how to generate different colours from RED-GREEN-BLUE LEDs using AVR micro controller)

As shown in figure, the circuit is made up of 3 LEDs of red, green and blue colour, AVR micro controller ATmega32 and 8 MHz crystal

Three LEDs BLUE, RED and GREEN are connected with PORTB pins PB2, PB1 and PB0 respectively with 330Ω current limiting resistors as shown. All three LEDs are connected in sinking current configuration. One 8 MHz crystal along with two 22 pf capacitors is connected to crystal input pins XTAL1 and XTAL2. It gives basic clock internal operation and program execution.

Circuit operation:

The anodes of LEDs are connected to Vcc and cathodes are connected to PORTB pins. So to turn LED ON, low logic (0) has to be given to respective pin. 

To generate three primary colours RED, GREEN and BLUE, the respective LED is turned ON by making particular port pin low. To generate secondary colours, at a time any two LEDs are turned ON by making two pins low simultaneously. Please refer the table given below

Table showing bit values at output port for color generation on RGB LED

Fig. 2: Table showing bit values at output port for color generation on RGB LED

So to generate different colours, LEDs are turned ON by sending data to PORTB as per given in table. The data bytes are given to PORTB one by one with 2 second delay in between. The program is loaded into internal FLASH of ATmega32 to perform above functionality. Click on the tab to see the C program written and compiled in AVR studio software.

Project Source Code

###

#include <avr/io.h>

#include <util/delay.h>

 

int main()

 {

 

      DDRB = 0x07;            // declare PORTB pins as output

      PORTB= 0x07;            // set all pins to high to turn off all LEDs

      while(1)                // continue loop

        {

            PORTB = 0xFE;     // GREEN LED ON

            _delay_ms(2000);  // 2 second delay

            PORTB = 0xFD;     // RED LED ON

            _delay_ms(2000);

            PORTB = 0xFB;     // BLUE LED ON

            _delay_ms(2000);

PORTB = 0xFC;     // RED n GREEN ON => YELLOW

            _delay_ms(2000);

            PORTB = 0xF9;     // RED n BLUE ON  => MAGENTA

            _delay_ms(2000);

            PORTB = 0xFA;     // BLUE n GREEN ON => CYAN

            _delay_ms(2000);

 

     }

  } 

###

 


Circuit Diagrams

Circuit-Diagram-8051-Microcontroller-RGB-LED-Controller


Filed Under: Electronic Projects

 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Electrical Lenght of Microstrip Transmission Lines
  • Op amp non inverting amplifier not working
  • Making a ducted soldering fan?
  • Characterization values of a MOSFET in PDK
  • USBASP Programmer Mod

RSS Electro-Tech-Online.com Discussions

  • Need a ducted soldering fan for solder smoke extraction
  • How to search component to replace my burn RF inductor?
  • Question about ultrasonic mist maker
  • Someone please explain how this BMS board is supposed to work?
  • bluetooth jammer
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering