Saturday, May 16, 2015


by J.B. Wylzan

Project 21:  RGB LED 

This project  shows how to control a RGB Led colors. 
These colors will be used as ROM indicators as we build our Homotronics robots.

RGB led 
2 resistors
connecting wires
Arduino R3 UNO board

Block Diagram:

Code # 21:

  iHackLab RGB Colors
  powered by Arduino
  sketched by J.B. Wylzan
  modified by Lawsinium

  The RGB LED will display the colors red, green and blue continuously.
  This example code is public domain.

int redPin = 8;
int greenPin = 7;
int bluePin = 4;
void setup()
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

void loop()
  digitalWrite(redPin, HIGH);                                   // red led
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, LOW);

  digitalWrite(redPin, LOW);                                   // green led
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);

  digitalWrite(redPin, LOW);                                  // blue led
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, HIGH);

Sketch a program that will produce other colors aside from red, green and blue by altering or combining HIGH or LOW inside digitalWrite(). Be surprised what colors will be created. Use the programming procedure technique below to create various colors by replacing r, g, and b with any numbers from 0 to 255. Happy painting ;-).

void displayRGB(int r, int g, int b)
  analogWrite(redPin, r);
  analogWrite(greenPin, g);
  analogWrite(bluePin, b);

Actual Layout:

1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code # 21 above
5. Paste Code #21
6. Click File > Save
7. Click Verify
8. Click Upload
9. The RGB led will change colors from Red, Green and Blue.

Project # :  Robotics

Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: A Journal of a Creative Mind, Joey Lawsin, 1988, USA.

"The Last Human on Earth will no longer be Human." ~ Joey Lawsin
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®


No comments:

Post a Comment